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 91C58BC57 for ; Tue, 16 Nov 2010 16:27:02 +0100 (CET) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: Ap4gAJIx4kzRVaA0k2dsb2JhbACUYIV1AYNdDINNSwgVAQEBAQkJCgkRAx+lM4lighiFFi6IWQEBAwWFRgSBXIh8hXuDLw X-IronPort-AV: E=Sophos;i="4.59,206,1288566000"; d="scan'208";a="78399604" Received: from mail-pw0-f52.google.com ([209.85.160.52]) by mail4-smtp-sop.national.inria.fr with ESMTP; 16 Nov 2010 16:27:01 +0100 Received: by pwi5 with SMTP id 5so111077pwi.39 for ; Tue, 16 Nov 2010 07:26:59 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:mime-version:sender:received :in-reply-to:references:from:date:x-google-sender-auth:message-id :subject:to:cc:content-type; bh=zmZZuKSIQsQkzg5OqeMdyLIAzSphwzbyKuiiUucwWZY=; b=x+Top0SxSIk6xaRVBLd20izlKqEp89IO6Yu8nd82CZVbQxWcP/OBEEHJNbC8351CGR Q0/TLg3I5kRO4rnwDsDL3AlZh9BmVLS5ZmWtu6h45aqjFILYx4LFy/ZRZgicHho4Rrsf Vj4wM+sdDYkf2zKp8dmd16a50UkfrTEZWBGew= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:sender:in-reply-to:references:from:date :x-google-sender-auth:message-id:subject:to:cc:content-type; b=ef8YL5pu8oX/RaDaasHSz3A5QEG4wtQx/r8rrKtB0/G39SS8VsieSx3kyzshl9qQ6p prkS2A1i11XKUz+ItBhSZs/1IFyNCsYCONvVfDC4AUXb0wrKrwkoeJEHMjz5ZqRkJcWh sZjQMTJXMuXbbbottb/O/embOVLx/aa3PG/vM= Received: by 10.229.232.205 with SMTP id jv13mr6343379qcb.68.1289921217789; Tue, 16 Nov 2010 07:26:57 -0800 (PST) MIME-Version: 1.0 Sender: gabriel.scherer@gmail.com Received: by 10.229.253.135 with HTTP; Tue, 16 Nov 2010 07:26:37 -0800 (PST) In-Reply-To: References: From: bluestorm Date: Tue, 16 Nov 2010 16:26:37 +0100 X-Google-Sender-Auth: T8yelZMV5Y8cOYGz2YQawVKhi9w Message-ID: Subject: Re: [Caml-list] Option functions (or lack thereof) + operator for composition To: Serge Le Huitouze Cc: caml-list@yquem.inria.fr Content-Type: multipart/alternative; boundary=0016363b8d84f980dc04952d2f1b X-Spam: no; 0.00; syntax:01 camlp:01 camlp:01 ocaml:01 ocaml:01 expr:01 kwd:01 expr:01 kwd:01 syntax:01 hearth:98 hearth:98 sourceforge:01 sourceforge:01 wrote:01 --0016363b8d84f980dc04952d2f1b Content-Type: text/plain; charset=ISO-8859-1 On Tue, Nov 16, 2010 at 12:27 PM, Serge Le Huitouze < serge.lehuitouze@gmail.com> wrote: > It seems that there is no predefined function to test an "'a option" for > being > specifically "None" or "Some _". This seems to be confirmed by the very > existence of: > http://ocaml-lib.sourceforge.net/doc/Option.html > which defines such functions ("is_none" and "is_some"). > I found it weird to be forced to use "match" expressions in my code for > doing that, e.g.: > * let curSelectedRow = ref None in > * let updateButtonsStatus () = > * button_remove#misc#set_sensitive > * (match !curSelectedRow with None -> false | _ -> true) > * in > * ... > Though useless in this case (just use ((<>) None)), there is a very nice syntax extension proposal by Richard Jones to transform any pattern into a boolean predicate : (matches p) would be equivalent to a function that returns true if the input matches the pattern. I have implemented it in camlp4 (the code may be slightly bitrotten) in case you're interested: http://bluestorm.info/camlp4/pa_matches.ml.html > I'm not familiar with operators and their precedence, but I wonder: is it > possible to do something similar with OCaml? > In OCaml, the associativity/precedence of an operator is defined by its first symbols. For example (++$*) has exactly the precedence of (+). You can find all precedence classes and their prefixes in the OCaml Manual: http://caml.inria.fr/pub/docs/manual-ocaml/expr.html#@manual.kwd33 Though this is less flexible that other languages that let you choose precedence and associativity on a case per case basis, it gives a nice homogeneity to binary operators: you don't need to look at the operator definition site to have a (vague, unless you know the table by hearth) idea of its syntactic properties. --0016363b8d84f980dc04952d2f1b Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable
On Tue, Nov 16, 2010 at 12:27 PM, Serge Le Huito= uze <ser= ge.lehuitouze@gmail.com> wrote:
It seems that there is no predefined function to test an "'a optio= n" for being
specifically "None" or "Some _". This seems to be confi= rmed by the very
existence of:
http://ocaml-lib.sourceforge.net/doc/Option.html
which defines such functions ("is_none" and "is_some").=
I found it weird to be forced to use "match" expressions in my co= de for
doing that, e.g.:
* =A0let curSelectedRow =3D ref None in
* =A0let updateButtonsStatus () =3D
* =A0 =A0 =A0button_remove#misc#set_sensitive
* =A0 =A0 =A0 =A0 =A0 =A0 =A0(match !curSelectedRow with None -> false |= _ -> true)
* =A0in
* =A0...

Though useless in this case (j= ust use ((<>) None)), there is a very nice syntax extension proposal = by Richard Jones to transform any pattern into a boolean predicate : (match= es p) would be equivalent to a function that returns true if the input matc= hes the pattern. I have implemented it in camlp4 (the code may be slightly = bitrotten) in case you're interested:

= =A0
I'm not familiar with operators and their precedence, but I wonder: is = it
possible to do something similar with OCaml?

In OCaml, the associativity/precedence of an operator is defined by i= ts first symbols. For example (++$*) has exactly the precedence of (+). You= can find all precedence classes and their prefixes in the OCaml Manual:
Though this is less flexible that other langua= ges that let you choose precedence and associativity on a case per case bas= is, it gives a nice homogeneity to binary operators: you don't need to = look at the operator definition site to have a (vague, unless you know the = table by hearth) idea of its syntactic properties.
--0016363b8d84f980dc04952d2f1b--