From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail3-relais-sop.national.inria.fr (mail3-relais-sop.national.inria.fr [192.134.164.104]) by sympa.inria.fr (Postfix) with ESMTPS id 3C6C17EE34 for ; Fri, 18 Mar 2016 22:58:32 +0100 (CET) IronPort-PHdr: 9a23:hjxxJhI64bAFT2o22NmcpTZWNBhigK39O0sv0rFitYgULfzxwZ3uMQTl6Ol3ixeRBMOAu6IC07Sd7fyocFdDyKjCmUhKSIZLWR4BhJdetC0bK+nBN3fGKuX3ZTcxBsVIWQwt1Xi6NU9IBJS2PAWK8TWM5DIfUi/yKRBybrysXNWC34Lviavsp9X6WEZhunmUWftKNhK4rAHc5IE9oLBJDeIP8CbPuWZCYO9MxGlldhq5lhf44dqsrtY4q3wD89pozcNLUL37cqIkVvQYSW1+ayFmrPHs4DLKSA/HwnoHTi1CmRNNB03B7Qrmdpb3qCrz8ORnjnq0J8rzGPoRQ3Lqz6pxUlWg3CIGLCI06mHakNZYgrhWrRSsu1pzztiHM8muKPNic/aFLpshTm1bU5MUDnQZDw== Authentication-Results: mail3-smtp-sop.national.inria.fr; spf=None smtp.pra=misterherr@freenet.de; spf=None smtp.mailfrom=misterherr@freenet.de; spf=None smtp.helo=postmaster@mout1.freenet.de Received-SPF: None (mail3-smtp-sop.national.inria.fr: no sender authenticity information available from domain of misterherr@freenet.de) identity=pra; client-ip=195.4.92.91; receiver=mail3-smtp-sop.national.inria.fr; envelope-from="misterherr@freenet.de"; x-sender="misterherr@freenet.de"; x-conformance=sidf_compatible Received-SPF: None (mail3-smtp-sop.national.inria.fr: no sender authenticity information available from domain of misterherr@freenet.de) identity=mailfrom; client-ip=195.4.92.91; receiver=mail3-smtp-sop.national.inria.fr; envelope-from="misterherr@freenet.de"; x-sender="misterherr@freenet.de"; x-conformance=sidf_compatible Received-SPF: None (mail3-smtp-sop.national.inria.fr: no sender authenticity information available from domain of postmaster@mout1.freenet.de) identity=helo; client-ip=195.4.92.91; receiver=mail3-smtp-sop.national.inria.fr; envelope-from="misterherr@freenet.de"; x-sender="postmaster@mout1.freenet.de"; x-conformance=sidf_compatible X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: A0AyAQBseexWk1tcBMNegxmBcLwbhg0CgTE7EQEBAQEBAQEBEAEBAQEHDQkJIS+CLYIUAQEBAwEjBAsBRQYLCxgCAgUWCwICCQMCAQIBRQYNBgIBAYgNAQMKCQMBsSyKCwlBDF4BhAQBCx58iWaEFoMmglYFl1cBlzIEhVSPBjaCQIFSaYkogTsBAQE X-IPAS-Result: A0AyAQBseexWk1tcBMNegxmBcLwbhg0CgTE7EQEBAQEBAQEBEAEBAQEHDQkJIS+CLYIUAQEBAwEjBAsBRQYLCxgCAgUWCwICCQMCAQIBRQYNBgIBAYgNAQMKCQMBsSyKCwlBDF4BhAQBCx58iWaEFoMmglYFl1cBlzIEhVSPBjaCQIFSaYkogTsBAQE X-IronPort-AV: E=Sophos;i="5.24,357,1454972400"; d="scan'208";a="169487085" Received: from mout1.freenet.de ([195.4.92.91]) by mail3-smtp-sop.national.inria.fr with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 18 Mar 2016 22:58:31 +0100 Received: from [195.4.92.142] (helo=mjail2.freenet.de) by mout1.freenet.de with esmtpa (ID misterherr@freenet.de) (port 25) (Exim 4.85 #1) id 1ah2Pe-000239-6S for caml-list@inria.fr; Fri, 18 Mar 2016 22:58:30 +0100 Received: from localhost ([::1]:36616 helo=mjail2.freenet.de) by mjail2.freenet.de with esmtpa (ID misterherr@freenet.de) (Exim 4.85 #1) id 1ah2Pe-0003L1-3v for caml-list@inria.fr; Fri, 18 Mar 2016 22:58:30 +0100 Received: from mx13.freenet.de ([195.4.92.23]:55180) by mjail2.freenet.de with esmtpa (ID misterherr@freenet.de) (Exim 4.85 #1) id 1ah2ME-00072y-2T for caml-list@inria.fr; Fri, 18 Mar 2016 22:54:58 +0100 Received: from cl-252.ham-02.de.sixxs.net ([2001:6f8:1c00:fb::2]:56444 helo=suse132-intel.home.loc) by mx13.freenet.de with esmtpsa (ID misterherr@freenet.de) (TLSv1.2:DHE-RSA-AES128-SHA:128) (port 465) (Exim 4.85 #1) id 1ah2MD-0002n3-PI for caml-list@inria.fr; Fri, 18 Mar 2016 22:54:57 +0100 To: Caml List References: <56EC4318.2020701@freenet.de> From: "Mr. Herr" X-Enigmail-Draft-Status: N1110 Message-ID: <56EC7930.2010308@freenet.de> Date: Fri, 18 Mar 2016 22:54:56 +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: Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Originated-At: 2001:6f8:1c00:fb::2!56444 Subject: Re: [Caml-list] what does let () = ... define? see below /Str. On 18.03.2016 22:29, Raphaël Proust wrote: > On 18 March 2016 at 18:04, Mr. Herr wrote: >> 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 = () > The specific case of `let () = …` I would consider to be equivalent to > `let (_ : unit) = …`. I.e., it doesn't bind anything in the > environment; it runs something (the right hand-side of the `=`); it > constrains the result to be of type `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? > In this case, nothing. Nothing is “defined” by your pattern matching. > There is just a check that the expression on the right-hand-side of > `=` matches the form on the left-hand-side. In the case of `()` that > check is trivial and is guaranteed to succeed by the type checker. In > the case of `None`, the type checker can't make any guarantees about > `None` being exhaustive; hence the warning. > > >> It defines unit and None in the environment, and then that value is just >> sitting there? > To be clear, it does NOT define unit nor None in the environment. Both > `()` and `None` are constructors (in this case, destructors). They are > not variables that can be introduced in the environment. > > The form `let None = in ` is equivalent to > `match with None -> ` which gives a warning > because `None` is not the only case for the option type. (The > exhaustiveness check relies on typing.) > > Generally, you can transform most (all?) `let` into `match` using the > correspondence above: `let = in > ` into `match with -> > `. The former form is limited to one pattern (which is not > useful in some situations). Looks like we are getting near to what I was trying to ask about. So the question seems to be: what is the result of successful pattern matching? OCaml is the language for Coq, to prove properties of programs, and I am asking, what is the result of let None = None ;; and where does this result go? None evaluates to None, is pattern matched to None, and then QED? > Note that using a pattern more complex than a simple variable on the > left-hand-side of a let-binding is often useful. > - for destructing tuples (`let (x,y) = in`) or records > (`let {foo; bar} = in`) > - for enforcing typing constraints (`let (_ : baz) = in`) > - for extracting an element that is present in every part of a sum > (`let (A (pos, _, _) | B (pos, _) | C pos) = in`) > - probably some other things I can't think of right now. I knew I would get hints about this ;-)