caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Matej Kosik <kosik@fiit.stuba.sk>
To: Caml List <caml-list@inria.fr>
Subject: [Caml-list] Ocaml: typing by name vs. typing by structure
Date: Sun, 16 Oct 2011 20:51:13 +0200	[thread overview]
Message-ID: <4E9B27A1.5070309@fiit.stuba.sk> (raw)

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

             reply	other threads:[~2011-10-16 18:51 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-10-16 18:51 Matej Kosik [this message]
2011-10-16 19:24 ` Gabriel Scherer
2011-10-16 20:24   ` Matej Košík
2011-10-16 20:54     ` Gabriel Scherer
2011-10-17 13:53     ` AUGER Cedric

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=4E9B27A1.5070309@fiit.stuba.sk \
    --to=kosik@fiit.stuba.sk \
    --cc=caml-list@inria.fr \
    /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).