caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Jon Harrop <jonathandeanharrop@googlemail.com>
To: "'ben kuin'" <benkuin@gmail.com>, <caml-list@inria.fr>
Subject: RE: [Caml-list] from if...else to pattern matching
Date: Sat, 2 Oct 2010 18:54:57 +0100	[thread overview]
Message-ID: <002501cb625a$ee2c4b10$ca84e130$@com> (raw)
In-Reply-To: <AANLkTinpu++qk2A3UYJ-t+==bbmb-CWikmPMTATjasKi@mail.gmail.com>

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


      parent reply	other threads:[~2010-10-02 17:55 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-10-02 14:04 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 message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='002501cb625a$ee2c4b10$ca84e130$@com' \
    --to=jonathandeanharrop@googlemail.com \
    --cc=benkuin@gmail.com \
    --cc=caml-list@inria.fr \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).