caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* [Caml-list] Ocaml: typing by name vs. typing by structure
@ 2011-10-16 18:51 Matej Kosik
  2011-10-16 19:24 ` Gabriel Scherer
  0 siblings, 1 reply; 5+ messages in thread
From: Matej Kosik @ 2011-10-16 18:51 UTC (permalink / raw)
  To: Caml List

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

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2011-10-17 13:53 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-10-16 18:51 [Caml-list] Ocaml: typing by name vs. typing by structure Matej Kosik
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

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).