* changing the type of records using "with"
@ 2006-07-12 13:56 Eric Breck
2006-07-13 2:43 ` [Caml-list] " Jacques Garrigue
0 siblings, 1 reply; 2+ messages in thread
From: Eric Breck @ 2006-07-12 13:56 UTC (permalink / raw)
To: caml-list
Hi folks,
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?
thanks,
Eric Breck
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [Caml-list] changing the type of records using "with"
2006-07-12 13:56 changing the type of records using "with" Eric Breck
@ 2006-07-13 2:43 ` Jacques Garrigue
0 siblings, 0 replies; 2+ messages in thread
From: Jacques Garrigue @ 2006-07-13 2:43 UTC (permalink / raw)
To: ebreck; +Cc: caml-list
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
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2006-07-13 2:41 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2006-07-12 13:56 changing the type of records using "with" Eric Breck
2006-07-13 2:43 ` [Caml-list] " Jacques Garrigue
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox