From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail1-relais-roc.national.inria.fr (mail1-relais-roc.national.inria.fr [192.134.164.82]) by walapai.inria.fr (8.13.6/8.13.6) with ESMTP id p9GJP7su016705 for ; Sun, 16 Oct 2011 21:25:07 +0200 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AtcBAHcum05KfVK2kGdsb2JhbABChHWUW48KCCIBAQEBCQkNBxQEIYFuAQEBBBICDwQZARsSCwEDDAYDAgsNAgIJHQICIgERAQUBChIGExIQh2WYWQqLDEWCYIN6PYhuAgUKgSaBe4NJgRQEk3qNKj2DcQ X-IronPort-AV: E=Sophos;i="4.69,354,1315173600"; d="scan'208";a="124334479" Received: from mail-wy0-f182.google.com ([74.125.82.182]) by mail1-smtp-roc.national.inria.fr with ESMTP/TLS/RC4-SHA; 16 Oct 2011 21:25:05 +0200 Received: by wyi40 with SMTP id 40so1909519wyi.27 for ; Sun, 16 Oct 2011 12:25:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc:content-type:content-transfer-encoding; bh=7hkWmtBOezEh8PYtjEIwVOo1YVLHH4kyJ9MUJkTn6w0=; b=r+Go+u24vwiFQNv1TinSYJZ+5HR3SMmo+ShP6YgOGyhujzwldI1xNwsP4h+IylDNx0 O3N/c+63IsOCYbla1F02Ie2PaYfbJxRdJVemDUvlzMsw74DssWUB5UvO3cap0oT/ZdGr sH/SEerozfriTVE28C+Mdcipb5aF7veSUBfQM= Received: by 10.227.195.13 with SMTP id ea13mr5604081wbb.36.1318793104222; Sun, 16 Oct 2011 12:25:04 -0700 (PDT) MIME-Version: 1.0 Received: by 10.227.155.67 with HTTP; Sun, 16 Oct 2011 12:24:44 -0700 (PDT) In-Reply-To: <4E9B27A1.5070309@fiit.stuba.sk> References: <4E9B27A1.5070309@fiit.stuba.sk> From: Gabriel Scherer Date: Sun, 16 Oct 2011 21:24:44 +0200 Message-ID: To: Matej Kosik Cc: Caml List Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-MIME-Autoconverted: from quoted-printable to 8bit by walapai.inria.fr id p9GJP7su016705 Subject: Re: [Caml-list] Ocaml: typing by name vs. typing by structure If record were structurally typed, there would be an ambiguity as to, for example, what this function mean: let access_foo t = t.foo What would the type of `access_foo` be ? { foo : 'a } -> 'a ? { foo : 'a; bar : 'b } -> 'a ? Should `access_foo { foo = 1 }` be typable? And `access_foo { foo = 1; bar = true }` ? In this situation, you want record subtyping. This get more complicated than the relatively simple OCaml records. In fact, OCaml has structurally typed structures with named fields : objects # let access_foo t = t#foo;; val access_foo : < foo : 'a; .. > -> 'a = # access_foo (object method foo = 1 method bar = true end);; - : int = 1 Tuples don't have this issue as they don't have an universal accessor function : there is no way to get the first element of a tuple whatever its width is. Therefore, all tuples manipulation make the structure concrete, and structural subtyping comes at no complexity cost ... if you accept the absence of universal accessors. SML has them (#1 #2 etc.) and I'm not sure how they handle this. On Sun, Oct 16, 2011 at 8:51 PM, Matej Kosik wrote: > Hello, > > When I try to compile the following program: > >   let f1 = function >     {re=a;im=b} -> >        print_float a; >        print_float b >    in >    f1 {re=10.0;im=20.0 > > I get an error message: > >    File "tmp.ml", line 2, characters 2-13: >    Error: Unbound record field label re > > I know how to "fix" the program to be compilable---I have to add > >    type whatever = {re:float; im:float} > > at the top. > Then type inference is able to figure out that "f1" has type "whatever -> unit". > > Why did language designers chosen: > - typing by structure in case of tuples (tuples can be viewed as records with unlabled fields), > - typing by name in case of records. > > Why wasn't typing by structure chosen both for tuples and for records? > If it were, then type of "f1" would be "{re=float;im=float}". > > Best regards. > -- > Matej Košík > > -- > Caml-list mailing list.  Subscription management and archives: > https://sympa-roc.inria.fr/wws/info/caml-list > Beginner's list: http://groups.yahoo.com/group/ocaml_beginners > Bug reports: http://caml.inria.fr/bin/caml-bugs > >