[
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] changing the type of records using "with" |
From: Eric Breck <ebreck@cs.cornell.edu>
> I noticed the following behavior of the typing system:
>
> # type 'a foo = {a: 'a; b: int};;
> type 'a foo = { a : 'a; b : int; }
> # let one = { a = (); b = 5};;
> val one : unit foo = {a = (); b = 5}
> # let two = {one with a = "Hello"};;
> val two : string foo = {a = "Hello"; b = 5}
>
> i.e. "{one with ... }" can have a different polymorphic type argument
> than "one" does. This has been handy for me on a couple of
> occasions, but is it a documented feature that I can count on working
> in future versions of ocaml, or is it a quirk of the current version?
This behaviour is intentional. My interpretation of the reference
manual is that {one with a = "Hello"} should be strictly equivalent to
{a = "Hello"; b = one.b}. As a result I would say that requiring two.a
and one.a to have the same type would depart from this specification.
Jacques Garrigue