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 258D47EE34 for ; Fri, 18 Mar 2016 22:29:10 +0100 (CET) IronPort-PHdr: 9a23:lP+r/RFOVTRafYWwSrvSHJ1GYnF86YWxBRYc798ds5kLTJ75oMqwAkXT6L1XgUPTWs2DsrQf27qQ6/6rBzVIyK3CmU5BWaQEbwUCh8QSkl5oK+++Imq/EsTXaTcnFt9JTl5v8iLzG0FUHMHjew+a+SXqvnYsExnyfTB4Ov7yUtaLyZ/nh6bqpdaNOk1hv3mUX/BbFF2OtwLft80b08NJC50a7V/3mEZOYPlc3mhyJFiezF7W78a0+4N/oWwL46pyv+YJa6jxfrw5QLpEF3xmdjltvIy4/SXEGEGq/D1UcmgMiFAAVw3E9w33RJf8qDHSuPBw1S+XIYv6QOZndy6l6vJRQQfogaQDAAYj93zMloQklqtDoBaooxti64HRaYCRcvF5e/WOLpshWWNdU5MJBGR6CYSmYt5KVrJZMA== Authentication-Results: mail2-smtp-roc.national.inria.fr; spf=None smtp.pra=raphlalou@gmail.com; spf=Pass smtp.mailfrom=raphlalou@gmail.com; spf=None smtp.helo=postmaster@mail-vk0-f46.google.com Received-SPF: None (mail2-smtp-roc.national.inria.fr: no sender authenticity information available from domain of raphlalou@gmail.com) identity=pra; client-ip=209.85.213.46; receiver=mail2-smtp-roc.national.inria.fr; envelope-from="raphlalou@gmail.com"; x-sender="raphlalou@gmail.com"; x-conformance=sidf_compatible Received-SPF: Pass (mail2-smtp-roc.national.inria.fr: domain of raphlalou@gmail.com designates 209.85.213.46 as permitted sender) identity=mailfrom; client-ip=209.85.213.46; receiver=mail2-smtp-roc.national.inria.fr; envelope-from="raphlalou@gmail.com"; x-sender="raphlalou@gmail.com"; x-conformance=sidf_compatible; x-record-type="v=spf1" Received-SPF: None (mail2-smtp-roc.national.inria.fr: no sender authenticity information available from domain of postmaster@mail-vk0-f46.google.com) identity=helo; client-ip=209.85.213.46; receiver=mail2-smtp-roc.national.inria.fr; envelope-from="raphlalou@gmail.com"; x-sender="postmaster@mail-vk0-f46.google.com"; x-conformance=sidf_compatible X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: A0B7AAD/cexWiy7VVdFehQkGryWKcwENgW+GDQKBKgc4FAEBAQEBAQEBEAEBAQgLCwkfMYItghQBAQEDARIRBBkBGx0BAwELBgULDQICJgICIgERAQUBHAYTIodvAQMKCKNlgTE+MYs2gWqCV4VGChknDAFRhAUBAQEHAQEBARYBBQoFbYlmhBYkgwKCVgWXV44EjweNSBEegQ8eAQGCOB6BUTwuiSiBOwEBAQ X-IPAS-Result: A0B7AAD/cexWiy7VVdFehQkGryWKcwENgW+GDQKBKgc4FAEBAQEBAQEBEAEBAQgLCwkfMYItghQBAQEDARIRBBkBGx0BAwELBgULDQICJgICIgERAQUBHAYTIodvAQMKCKNlgTE+MYs2gWqCV4VGChknDAFRhAUBAQEHAQEBARYBBQoFbYlmhBYkgwKCVgWXV44EjweNSBEegQ8eAQGCOB6BUTwuiSiBOwEBAQ X-IronPort-AV: E=Sophos;i="5.24,357,1454972400"; d="scan'208";a="208712420" Received: from mail-vk0-f46.google.com ([209.85.213.46]) by mail2-smtp-roc.national.inria.fr with ESMTP/TLS/AES128-GCM-SHA256; 18 Mar 2016 22:29:09 +0100 Received: by mail-vk0-f46.google.com with SMTP id e185so157063905vkb.1 for ; Fri, 18 Mar 2016 14:29:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-transfer-encoding; bh=F+iWLgXMGsqbAlIsHjHmnWPrkBc6z32BPEnGwcI6AN8=; b=UxZ2rBRHk6RrXWK2pU7SvlAFiN0tNuOJhvGyTVZzlHtVtRAjuKhHXPTXZrzToGAsDx e9CheqqVGEkqaMuRpOYjMDqovfJMej0d9UonyaUSB0CV3z8j3OTqw4VP7mjPSLQ5aJz6 jN58YLKYa/EKbP0L1cr48usqG1Gi6nzX0ZFWoXGnIMPxgee9HjZ4vwr6Gr4tT37Xlnpx ek5R8sEHtHNcMDvLVF40fxuIJzCg5UBZ6P/4LJXNnOx8C5ZIilQp0WBx7vjPnDdFlCX9 r4q0hdTuDTfixYdjgXgY997a1+iuzSB1tUMMXhJ44ahwIbWhQZWC9hRIgWmT3NvPkyU4 LNcA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:in-reply-to:references:date :message-id:subject:from:to:cc:content-transfer-encoding; bh=F+iWLgXMGsqbAlIsHjHmnWPrkBc6z32BPEnGwcI6AN8=; b=bYzBLANVpxHkhHuW+u0PFh+4RDIOC3DFVfet+rTJvpP4QfvxwWpiq52PieMfSn/0Wc LQ4Oq/5VCZBCZLwyLJ3e4+PfG6QrxuO+GL2jJ8OulVnMpGczm1K2LVS74NphKSU8Yj3u HlZveL3rE4fiFr+Ecm+d4b2fbUKHfWkxDI0NPzvl+yzw9hIYdHhhzog9aQtFTLjr7+4J Nq7OSRNZfM7U64xE78/S9B3srha0v3yhe20d/VZtqg6iykYVypXCTUQOUex9tlDLSL2Z J0em8P6l84PTDQ9Vb1E7mX9KKW/+9zL5j662zehamtYcgm5imGc0i/aR9VPXonRMp/yT MG2g== X-Gm-Message-State: AD7BkJJb5xzY5pDuirGkuzdsRiU2xpNXuCb3W2miOJ4XXoynjM82VZTTEQXt85cdxt6eTlmqx+5LdSltGxBPdg== MIME-Version: 1.0 X-Received: by 10.31.190.195 with SMTP id o186mr20234658vkf.100.1458336548231; Fri, 18 Mar 2016 14:29:08 -0700 (PDT) Received: by 10.31.86.194 with HTTP; Fri, 18 Mar 2016 14:29:08 -0700 (PDT) In-Reply-To: <56EC4318.2020701@freenet.de> References: <56EC4318.2020701@freenet.de> Date: Fri, 18 Mar 2016 21:29:08 +0000 Message-ID: From: =?UTF-8?Q?Rapha=C3=ABl_Proust?= To: "Mr. Herr" Cc: Caml List Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Subject: Re: [Caml-list] what does let () = ... define? 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 () =3D () ;; > # () ;; > - : unit =3D () > # let _ =3D () ;; > - : unit =3D () The specific case of `let () =3D =E2=80=A6` I would consider to be equivale= nt to `let (_ : unit) =3D =E2=80=A6`. I.e., it doesn't bind anything in the environment; it runs something (the right hand-side of the `=3D`); it constrains the result to be of type `unit`. > # let None =3D 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 w= hat > does it define? In this case, nothing. Nothing is =E2=80=9Cdefined=E2=80=9D by your pattern= matching. There is just a check that the expression on the right-hand-side of `=3D` 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 =3D 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 =3D in ` into `match with -> `. The former form is limited to one pattern (which is not useful in some situations). 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) =3D in`) or records (`let {foo; bar} =3D in`) - for enforcing typing constraints (`let (_ : baz) =3D in`) - for extracting an element that is present in every part of a sum (`let (A (pos, _, _) | B (pos, _) | C pos) =3D in`) - probably some other things I can't think of right now. -- r