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 mail4-relais-sop.national.inria.fr (mail4-relais-sop.national.inria.fr [192.134.164.105]) by yquem.inria.fr (Postfix) with ESMTP id 7A68DBBAF for ; Sat, 2 Oct 2010 19:55:04 +0200 (CEST) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AjsCAFsOp0xKfVI0kGdsb2JhbACUCIFUjFwIFQEBAQEJCQwHEQMfp2WLWwEFjnUBBIVE X-IronPort-AV: E=Sophos;i="4.57,271,1283724000"; d="scan'208";a="72125665" Received: from mail-ww0-f52.google.com ([74.125.82.52]) by mail4-smtp-sop.national.inria.fr with ESMTP; 02 Oct 2010 19:55:04 +0200 Received: by wwd20 with SMTP id 20so1138395wwd.9 for ; Sat, 02 Oct 2010 10:55:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlemail.com; s=gamma; h=domainkey-signature:received:received:from:to:references :in-reply-to:subject:date:organization:message-id:mime-version :content-type:content-transfer-encoding:x-mailer:thread-index :content-language; bh=pTxDG1f6P46QAxLD15X/r6g3cnck2qWRRmjm0h4RKFw=; b=EneTlu6WOMsz6fWN2eGQU1B9MeAxSC9JXQ+jbra5EWOZgPgtKRv/lvyKtpodXdtmv2 +i5SrkWisGcaHgDOGAesueA8aiOVASOI4MwuTJbQEL+HLNhqedAJJXqIDfV/g5w8EleG fOtjfc8hAlED/t5Xyfry70XHYvixPtWAugTdM= DomainKey-Signature: a=rsa-sha1; c=nofws; d=googlemail.com; s=gamma; h=from:to:references:in-reply-to:subject:date:organization:message-id :mime-version:content-type:content-transfer-encoding:x-mailer :thread-index:content-language; b=ohDdmXbpFxLtZY6BG9cOMxrYNejJpYvl4Ky+AYlCqcChbpTNdfiTvHlm+4+p24sxJ6 R4yX6My15Qoa4mPHbUSGT6GqlNbe3r/V8noEKybrFxBUEzKSibjL/RYfZnNTbw7xzj0j BdNyvkLxzc2l7LBkDk5oQv5Lkftx8IXeT5cA8= Received: by 10.216.71.132 with SMTP id r4mr3471009wed.102.1286042103986; Sat, 02 Oct 2010 10:55:03 -0700 (PDT) Received: from WinEight (87.114.152.182.plusnet.thn-ag1.dyn.plus.net [87.114.152.182]) by mx.google.com with ESMTPS id k83sm1714722weq.38.2010.10.02.10.55.02 (version=SSLv3 cipher=RC4-MD5); Sat, 02 Oct 2010 10:55:03 -0700 (PDT) From: Jon Harrop To: "'ben kuin'" , References: In-Reply-To: Subject: RE: [Caml-list] from if...else to pattern matching Date: Sat, 2 Oct 2010 18:54:57 +0100 Organization: Flying Frog Consultancy Message-ID: <002501cb625a$ee2c4b10$ca84e130$@com> MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit X-Mailer: Microsoft Office Outlook 12.0 Thread-Index: ActiOtAmhDNOqwkTQAG4+Cesw2c9zgAH/sbw Content-Language: en-gb X-Spam: no; 0.00; pred:01 pred:01 pseudocode:01 beginner's:01 ocaml:01 bug:01 bounces:98 equality:01 equality:01 beginners:01 rewrite:01 caml-list:01 caml-list:01 bin:01 define:02 Note that you are using physical equality (==) and not structural equality (=). Also, you can always rewrite: if then true else false more simply as: > -----Original Message----- > From: caml-list-bounces@yquem.inria.fr [mailto:caml-list- > bounces@yquem.inria.fr] On Behalf Of ben kuin > Sent: 02 October 2010 15:05 > To: caml-list@inria.fr > Subject: [Caml-list] from if...else to pattern matching > > 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 > > _______________________________________________ > Caml-list mailing list. Subscription management: > http://yquem.inria.fr/cgi-bin/mailman/listinfo/caml-list > Archives: http://caml.inria.fr > Beginner's list: http://groups.yahoo.com/group/ocaml_beginners > Bug reports: http://caml.inria.fr/bin/caml-bugs