[
Home
]
[ Index:
by date
|
by threads
]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
| Date: | -- (:) |
| From: | Jon Harrop <jonathandeanharrop@g...> |
| Subject: | RE: [Caml-list] from if...else to pattern matching |
Note that you are using physical equality (==) and not structural equality (=). Also, you can always rewrite: if <pred> then true else false more simply as: <pred> > -----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