[
Home
]
[ Index:
by date
|
by threads
]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
| Date: | -- (:) |
| From: | Jacques Garrigue <garrigue@m...> |
| Subject: | Re: [Caml-list] Another polymorphism puzzle |
From: Manos Renieris <er@cs.brown.edu>
> Worse:
>
> # let f x = { () with foo = 3};;
> val f : 'a -> int t = <fun>
> # let f x = { 42 with foo = 3};;
> val f : 'a -> int t = <fun>
>
> I think this qualifies as a bug. Especially since the documentation
> says the expr on the left hand side of with has to be a record.
What do you mean by worse? You just exhibit an immediate consequence
of the typing of f below.
> Thu, Mar 31, 2005 at 09:02:14PM -0500, Yaron Minsky wrote:
> > # type 'a t = { foo: 'a };;
> > type 'a t = { foo : 'a; }
> > # let f x = { x with foo = 3 };;
> > val f : 'a -> int t = <fun>
Now, why does it happen?
The reason is simply that the typing of {x with fields} follows
closely its semantics:
build a record from the given fields, extracting values from x
when a field is missing.
Consequence: if you provide all the fields, then there is no missing
field, so x can be completely ignored.
Following the manual, the typing could be more restrictive, but the
current typing is perfectly sound.
Jacques Garrigue