From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Original-To: caml-list@yquem.inria.fr Delivered-To: caml-list@yquem.inria.fr Received: from mail3-relais-sop.national.inria.fr (mail3-relais-sop.national.inria.fr [192.134.164.104]) by yquem.inria.fr (Postfix) with ESMTP id 61626BBAF for ; Sat, 2 Oct 2010 16:04:32 +0200 (CEST) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: ArQCAK7YpkzRVda2kGdsb2JhbACUN41/CBUBAQEBCQkMBxEDH6ZbiUSCF4YELohVAQEDBYU/BIo8 X-IronPort-AV: E=Sophos;i="4.57,271,1283724000"; d="scan'208";a="59864123" Received: from mail-iw0-f182.google.com ([209.85.214.182]) by mail3-smtp-sop.national.inria.fr with ESMTP; 02 Oct 2010 16:04:31 +0200 Received: by iwn10 with SMTP id 10so17693iwn.27 for ; Sat, 02 Oct 2010 07:04:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:received:received:date:message-id :subject:from:to:content-type; bh=uSMrI44mtI6EsOAEIdYIjV0Ko1ZMgZx8I241JgxSbvE=; b=UFrGvAVT2qxpwHL1zccRqwEvxiSY4NsrNGCj4lQCm1MxM3ZR19yGM6OY/RhZwaEsUf p/cPDUi27tVTPIQ2YYZ2GwME27rpDIX0aoaCjiWJ2f2zpL8TJmU4JpGmEIszCnlfWhgg fW5WQI/15yhrU7Ul+1C3h3TubB/OwLUbSI/kY= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:date:message-id:subject:from:to:content-type; b=DBTfma84/v1DCfztuTYrqIxeSrq8Rrmr8CSM44+GyBK+QXnjk/r3B2jPhd56wpr4uv C7gUxnz+hOLPxb43zfEseKpYPcQIlyxlLRq5wRwX+xEa/7WbHPLqf0BEfk3B7Wy5j+T7 fVrr2I7QyGcr9oZSZocXChd8STbRk16dKWsuE= MIME-Version: 1.0 Received: by 10.231.38.9 with SMTP id z9mr7284311ibd.24.1286028271134; Sat, 02 Oct 2010 07:04:31 -0700 (PDT) Received: by 10.231.174.130 with HTTP; Sat, 2 Oct 2010 07:04:31 -0700 (PDT) Date: Sat, 2 Oct 2010 16:04:31 +0200 Message-ID: Subject: from if...else to pattern matching From: ben kuin To: caml-list@inria.fr Content-Type: text/plain; charset=ISO-8859-1 X-Spam: no; 0.00; pseudocode:01 define:02 match:02 match:02 defining:02 clause:03 let:03 let:03 pattern:04 pattern:04 transform:05 matching:05 matching:05 i'm:09 approaches:09 hi I try to transform an if-else clause into pattern matching, I think I've tried a lot of approaches, but apperently I'm doing something fundemently wrong. ~~~~~~~~~ (** Define behaviors against a constang 'x =< c' with if...else and pattern matching. I want to see how to match a value against funtion **) (* defining a '=<' operator *) let (=<) a b = if a < b then true else if a == b then true else false;; let if_test c = if ( 4 =< c )then true else false ;; (* and now use the operator in pattern matching * ) let match_test c = match ( _ =< c ) (* pseudocode *) | 4 -> true | _ -> false ;; ~~~~~~~~~~~~~~~~~~~~~~~~~~~ thanks in advance ben