caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Nick Lucaroni <nicholas.r.lucaroni@gmail.com>
To: "Mr. Herr" <misterherr@freenet.de>
Cc: Caml List <caml-list@inria.fr>
Subject: Re: [Caml-list] what does let () = ... define?
Date: Fri, 18 Mar 2016 14:26:56 -0400	[thread overview]
Message-ID: <CAADdkeJNuUYvY=PCEmm9v94UoBpr4DuORjTsEek4UB1eoixumQ@mail.gmail.com> (raw)
In-Reply-To: <56EC4318.2020701@freenet.de>

[-- Attachment #1: Type: text/plain, Size: 1248 bytes --]

Pattern matching left of the = sign is helpful for tuple, records and
destructuring variant types with a single constructors.

# let (x,y) = (1,2);;
> val x : int = 1
> val y : int = 2
> # type r = { x : int; y : int; };;
> type r = { x : int; y : int; }
> # let {x=a;y=b} = {x=1;y=2};;
> val a : int = 1
>
>> val b : int = 2
>
> # let {x=a} = {x=1;y=2};;
>
> val a : int = 1
>
# type point = Point of int * int;;
> type point = Point of int * int
> # let Point (x,_) = Point(1,2);;
> val x : int = 1
>

--
nL

On Fri, Mar 18, 2016 at 2:04 PM, Mr. Herr <misterherr@freenet.de> wrote:

> Hi,
>
> in a small presentation of OCaml (Linux User Group Bremen) I got some
> interesting questions, and
> trying to answer I noticed I took something for granted that was not fully
> understood.
>
> Looking at this in the toplevel:
>
> # let () = () ;;
> # () ;;
> - : unit = ()
> # let _ = () ;;
> - : unit = ()
> # let None = None;;
> Warning 8: this pattern-matching is not exhaustive.
> Here is an example of a value that is not matched:
> Some _
> #
>
> ... the question is: okay, pattern matching left of the equal sign, but
> what does it define?
> It defines unit and None in the environment, and then that value is just
> sitting there?
>
> /Str.
>

[-- Attachment #2: Type: text/html, Size: 3307 bytes --]

  reply	other threads:[~2016-03-18 18:27 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 [this message]
2016-03-18 18:52 ` Christoph Höger
2016-03-18 22:06   ` Nicolas Barnier
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='CAADdkeJNuUYvY=PCEmm9v94UoBpr4DuORjTsEek4UB1eoixumQ@mail.gmail.com' \
    --to=nicholas.r.lucaroni@gmail.com \
    --cc=caml-list@inria.fr \
    --cc=misterherr@freenet.de \
    /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).