From: Nicolas Barnier <barnier@recherche.enac.fr>
To: caml-list@inria.fr
Subject: Re: [Caml-list] what does let () = ... define?
Date: Fri, 18 Mar 2016 23:06:51 +0100 [thread overview]
Message-ID: <56EC7BFB.4070200@recherche.enac.fr> (raw)
In-Reply-To: <56EC4E7F.8060602@tu-berlin.de>
Le 18/03/2016 19:52, Christoph Höger a écrit :
> It defines a match-expression with a single case, that is why you get
> the warning on None. [...]
> The same holds
> for records, tuples etc. think of it as a shallow and cheap type annotation.
Indeed. And it is quite a common idiom to write the equivalent of a "main"
function at the end of a source file as the last called function of your
program shouldn't return any useful value, for example :
let () =
let x = int_of_string Sys.argv.(1) in
solve x
It's better practice than to write :
let _ =
...
because it can catch some type error that would silently pass with
the latter: suppose you finally decide to add a parameter to the
solve function (let solve = fun x y -> ...), if you forget to add
the argument to the call to solve in the main function, in the first
case you get a type error, but your program compiles and just does
nothing in the second case (_ matches with a partial application of
solve).
Regards,
-- Nicolas
next prev parent reply other threads:[~2016-03-18 22:06 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-03-18 18:04 Mr. Herr
2016-03-18 18:26 ` Nick Lucaroni
2016-03-18 18:52 ` Christoph Höger
2016-03-18 22:06 ` Nicolas Barnier [this message]
2016-03-18 19:00 ` octachron
2016-03-18 19:42 ` Stefan Monnier
2016-03-18 21:29 ` Raphaël Proust
2016-03-18 21:54 ` Mr. Herr
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=56EC7BFB.4070200@recherche.enac.fr \
--to=barnier@recherche.enac.fr \
--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