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 39492BBAF for ; Sat, 2 Oct 2010 16:22:47 +0200 (CEST) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: ArcBAJrdpkyNGkAPhWdsb2JhbACDHpBoMY4HFQEBAQoLChgFHa9ukV6BIoMudASNPg X-IronPort-AV: E=Sophos;i="4.57,271,1283724000"; d="scan'208";a="59865322" Received: from deliver.uni-koblenz.de ([141.26.64.15]) by mail3-smtp-sop.national.inria.fr with ESMTP; 02 Oct 2010 16:22:44 +0200 Received: from localhost (localhost [127.0.0.1]) by deliver.uni-koblenz.de (Postfix) with ESMTP id 45B377800E03 for ; Sat, 2 Oct 2010 16:22:44 +0200 (CEST) Received: from deliver.uni-koblenz.de ([127.0.0.1]) by localhost (deliver.uni-koblenz.de [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 24315-02 for ; Sat, 2 Oct 2010 16:22:42 +0200 (CEST) X-CHKRCPT: Envelopesender vrfy feucht@uni-koblenz.de Received: from [192.168.1.34] (dslb-094-221-125-144.pools.arcor-ip.net [94.221.125.144]) (using SSLv3 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by deliver.uni-koblenz.de (Postfix) with ESMTP id E54B07800DDC for ; Sat, 2 Oct 2010 16:22:41 +0200 (CEST) Subject: Re: [Caml-list] from if...else to pattern matching From: Philip To: caml-list@inria.fr In-Reply-To: References: Content-Type: text/plain; charset="UTF-8" Date: Sat, 02 Oct 2010 16:22:41 +0200 Message-ID: <1286029361.2168.47.camel@io> Mime-Version: 1.0 X-Mailer: Evolution 2.28.3 Content-Transfer-Encoding: 7bit X-Virus-Scanned: amavisd-new at uni-koblenz.de X-Spam: no; 0.00; 0200,:01 pseudocode:01 beginner's:01 ocaml:01 bug:01 beginners:01 wrote:01 caml-list:01 caml-list:01 bin:01 define:02 caml:02 caml:02 match:02 match:02 On Sat, 2010-10-02 at 16:04 +0200, ben kuin wrote: > 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 > whoa, thats hard, try: # let t x = match x with a when x<=4 -> true | _ -> false;; btw, there is a beginner-list and irc-channel, Philip > _______________________________________________ > 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