From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Original-To: caml-list@sympa.inria.fr Delivered-To: caml-list@sympa.inria.fr Received: from mail2-relais-roc.national.inria.fr (mail2-relais-roc.national.inria.fr [192.134.164.83]) by sympa.inria.fr (Postfix) with ESMTPS id 2DA8C7EE34 for ; Fri, 18 Mar 2016 20:00:54 +0100 (CET) IronPort-PHdr: 9a23:QKnHpBGO7UptF8CKoIvBTp1GYnF86YWxBRYc798ds5kLTJ75pM6wAkXT6L1XgUPTWs2DsrQf27qQ6/6rAD1IyK3CmU5BWaQEbwUCh8QSkl5oK+++Imq/EsTXaTcnFt9JTl5v8iLzG0FUHMHjew+a+SXqvnYsExnyfTB4Ov7yUtaLyZ/nh6bqpdaKMk1hv3mUX/BbFF2OtwLft80b08NJC50a7V/3mEZOYPlc3mhyJFiezF7W78a0+4N/oWwL46pyv50IbaKvdK09SflcDS86G2Ez/szi8xfZHiWV4X5JVW4KmxFIGQ/DpEX9VYv4mjP9svt22C6AOsuwQ6piCmfq1LtiVBK90HRPDDU+6myC0sE= Authentication-Results: mail2-smtp-roc.national.inria.fr; spf=None smtp.pra=octa@polychoron.fr; spf=None smtp.mailfrom=octa@polychoron.fr; spf=None smtp.helo=postmaster@relay4-d.mail.gandi.net Received-SPF: None (mail2-smtp-roc.national.inria.fr: no sender authenticity information available from domain of octa@polychoron.fr) identity=pra; client-ip=217.70.183.196; receiver=mail2-smtp-roc.national.inria.fr; envelope-from="octa@polychoron.fr"; x-sender="octa@polychoron.fr"; x-conformance=sidf_compatible Received-SPF: None (mail2-smtp-roc.national.inria.fr: no sender authenticity information available from domain of octa@polychoron.fr) identity=mailfrom; client-ip=217.70.183.196; receiver=mail2-smtp-roc.national.inria.fr; envelope-from="octa@polychoron.fr"; x-sender="octa@polychoron.fr"; x-conformance=sidf_compatible Received-SPF: None (mail2-smtp-roc.national.inria.fr: no sender authenticity information available from domain of postmaster@relay4-d.mail.gandi.net) identity=helo; client-ip=217.70.183.196; receiver=mail2-smtp-roc.national.inria.fr; envelope-from="octa@polychoron.fr"; x-sender="postmaster@relay4-d.mail.gandi.net"; x-conformance=sidf_compatible X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: A0AmAQAHUOxWk8S3RtlehQ+8E4YNAoEwOxEBAQEBAQEBARABAQEBBw0JCSEvgi2CFQEBBCNVEQsEHRYLAgIJAwIBAgFFEwgBAYgnsUGPboYdhEWFCIF8Cy0TgkMFl1eCE4ZQjlSFVI8EAjaCQIFSik4BfQEBAQ X-IPAS-Result: A0AmAQAHUOxWk8S3RtlehQ+8E4YNAoEwOxEBAQEBAQEBARABAQEBBw0JCSEvgi2CFQEBBCNVEQsEHRYLAgIJAwIBAgFFEwgBAYgnsUGPboYdhEWFCIF8Cy0TgkMFl1eCE4ZQjlSFVI8EAjaCQIFSik4BfQEBAQ X-IronPort-AV: E=Sophos;i="5.24,356,1454972400"; d="scan'208,217";a="208691189" Received: from relay4-d.mail.gandi.net ([217.70.183.196]) by mail2-smtp-roc.national.inria.fr with ESMTP/TLS/ADH-AES256-GCM-SHA384; 18 Mar 2016 20:00:53 +0100 Received: from mfilter30-d.gandi.net (mfilter30-d.gandi.net [217.70.178.161]) by relay4-d.mail.gandi.net (Postfix) with ESMTP id 83FCD1720D2 for ; Fri, 18 Mar 2016 20:00:53 +0100 (CET) X-Virus-Scanned: Debian amavisd-new at mfilter30-d.gandi.net Received: from relay4-d.mail.gandi.net ([IPv6:::ffff:217.70.183.196]) by mfilter30-d.gandi.net (mfilter30-d.gandi.net [::ffff:10.0.15.180]) (amavisd-new, port 10024) with ESMTP id l1_ckGDsJOKb for ; Fri, 18 Mar 2016 20:00:51 +0100 (CET) X-Originating-IP: 83.156.16.70 Received: from [192.168.0.14] (alf94-22-83-156-16-70.fbx.proxad.net [83.156.16.70]) (Authenticated sender: octa@polychoron.fr) by relay4-d.mail.gandi.net (Postfix) with ESMTPSA id C99EF1720C3 for ; Fri, 18 Mar 2016 20:00:51 +0100 (CET) To: caml-list@inria.fr References: <56EC4318.2020701@freenet.de> From: octachron Message-ID: <56EC5062.5070408@polychoron.fr> Date: Fri, 18 Mar 2016 20:00:50 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Thunderbird/38.6.0 MIME-Version: 1.0 In-Reply-To: <56EC4318.2020701@freenet.de> Content-Type: multipart/alternative; boundary="------------050200050703030605020201" Subject: Re: [Caml-list] what does let () = ... define? This is a multi-part message in MIME format. --------------050200050703030605020201 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit Hi, Maybe defining is not the right word here. An alternative explanation would be that "let" binds variables in the pattern on the left in order to match the expression on the right. For instance, the following exotic expression: # type alt = Left of int | Right of int # let (Left a|Right a) = Left 0;; - : val a: int is valid and binds the variable "a" to the value 0. Since there is no variable to be bound in "()" or any constructor without argument, #let () = ();; just computes the expression on the right and does not bind anything on the left. Note that in some way, the toplevel is already telling you that, since # let () = ();; has no output compared to # ();; - : unit = () which prints the value of the constructor (). − octachron Le 03/18/16 19:04, Mr. Herr a écrit : > 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. --------------050200050703030605020201 Content-Type: text/html; charset=utf-8 Content-Transfer-Encoding: 8bit
Hi,

Maybe defining is not the right word here. An alternative explanation would be that "let" binds variables in the pattern on the left in order to match the expression on the right. For instance, the following exotic expression:

# type alt = Left of int | Right of int
# let (Left a|Right a) = Left 0;;
- : val a: int

is valid and binds the variable "a" to the value 0.

Since there is no variable to be bound in "()" or any constructor without argument,

#let () = ();;

just computes the expression on the right and does not bind anything on the left.

Note that in some way, the toplevel is already telling you that, since

# let () = ();;

has no output compared to

# ();;
 - : unit = ()

which prints the value of the constructor ().

− octachron


Le 03/18/16 19:04, Mr. Herr a écrit :
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.

--------------050200050703030605020201--