From: bluestorm <bluestorm.dylc@gmail.com>
To: Serge Le Huitouze <serge.lehuitouze@gmail.com>
Cc: caml-list@yquem.inria.fr
Subject: Re: [Caml-list] Option functions (or lack thereof) + operator for composition
Date: Tue, 16 Nov 2010 16:26:37 +0100 [thread overview]
Message-ID: <AANLkTinipkd1erqzwg37zY3F_3Re_Jp+GS4cJ6CD04Ft@mail.gmail.com> (raw)
In-Reply-To: <AANLkTimX1JOva2Ebc3FuTGiZ5W3zXAvHtoE9RrkO8v6=@mail.gmail.com>
[-- Attachment #1: Type: text/plain, Size: 1885 bytes --]
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
<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.
[-- Attachment #2: Type: text/html, Size: 2708 bytes --]
next prev parent reply other threads:[~2010-11-16 15:27 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-11-16 11:27 Serge Le Huitouze
2010-11-16 11:49 ` [Caml-list] " David Allsopp
2010-11-16 14:23 ` Michael Ekstrand
2010-11-16 13:30 ` Jacques Garrigue
2010-11-16 13:52 ` Serge Le Huitouze
2010-11-16 14:19 ` dmitry grebeniuk
2010-11-16 14:26 ` Michael Ekstrand
2010-11-16 15:18 ` bluestorm
2010-11-16 15:26 ` bluestorm [this message]
[not found] <1853021343.44703.1289906871683.JavaMail.root@zmbs4.inria.fr>
2010-11-16 11:43 ` Thomas Gazagnaire
2010-11-16 11:51 ` Gabriel Kerneis
2010-11-16 17:45 ` Martin Jambon
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=AANLkTinipkd1erqzwg37zY3F_3Re_Jp+GS4cJ6CD04Ft@mail.gmail.com \
--to=bluestorm.dylc@gmail.com \
--cc=caml-list@yquem.inria.fr \
--cc=serge.lehuitouze@gmail.com \
/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