caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* from if...else to pattern matching
@ 2010-10-02 14:04 ben kuin
  2010-10-02 14:22 ` [Caml-list] " Philip
  2010-10-02 17:54 ` Jon Harrop
  0 siblings, 2 replies; 5+ messages in thread
From: ben kuin @ 2010-10-02 14:04 UTC (permalink / raw)
  To: caml-list

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


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2010-10-02 17:55 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-10-02 14:04 from if...else to pattern matching ben kuin
2010-10-02 14:22 ` [Caml-list] " Philip
2010-10-02 14:47   ` ben kuin
2010-10-02 16:09     ` Hezekiah M. Carty
2010-10-02 17:54 ` Jon Harrop

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).