caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* RE: Record typing question
@ 1999-11-04 14:30 Don Syme
  0 siblings, 0 replies; 3+ messages in thread
From: Don Syme @ 1999-11-04 14:30 UTC (permalink / raw)
  To: 'William Chesters'; +Cc: caml-redistribution


>Spooky, I raised this point a few days ago!

Ah ha - I see that now.  I haven't been keeping up to date with the
discussion list!

>    type 'a foo = { a: 'a; b: 'a }
>    let f x = { x with a = 1 }

> Here "f: 'a foo -> int foo" won't wash, because the "b" field will
> stay an int, contra the definition.  Before lifting the current
> restriction, one would have to check that no type equalities between
> fields are broken.

I guess it should be f: int foo -> int foo.  All the field assignments would
act in parallel as far as the type system goes, so

    type 'a foo = { a: 'a; b: 'a; c: int }
    let f x = { x with a = [x.a]; b = [x.b]  }

would be f: 'a foo -> 'a list foo

Cheers,
Don



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

* Record typing question
  1999-10-29 13:25 Don Syme
@ 1999-10-29 17:44 ` William Chesters
  0 siblings, 0 replies; 3+ messages in thread
From: William Chesters @ 1999-10-29 17:44 UTC (permalink / raw)
  To: caml-list

Spooky, I raised this point a few days ago!

There is a slight complication, because of cases like

    type 'a foo = { a: 'a; b: 'a }
    let f x = { x with a = 1 }

    let _ = f { a: "one"; b: "one" }

Here "f: 'a foo -> int foo" won't wash, because the "b" field will
stay an int, contra the definition.  Before lifting the current
restriction, one would have to check that no type equalities between
fields are broken.

Nevertheless, I don't see a problem in principle and it would be good
to see a more general version.

Don Syme writes:
 > 
 > The typing rule for record overriding seems slightly more restrictive than
 > necessary, though I can imagine this is because it was simplest to implement
 > it this way.  e.g.
 > 
 > # type 'a foo = { a: 'a; b: int };;
 > type 'a foo = { a: 'a; b:int }
 > # let f x = {x with a=1 };;
 > val f : int foo -> int foo = <fun>
 > 
 > Why doesn't f have type 'a foo -> int foo??



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

* Record typing question
@ 1999-10-29 13:25 Don Syme
  1999-10-29 17:44 ` William Chesters
  0 siblings, 1 reply; 3+ messages in thread
From: Don Syme @ 1999-10-29 13:25 UTC (permalink / raw)
  To: caml-list


The typing rule for record overriding seems slightly more restrictive than
necessary, though I can imagine this is because it was simplest to implement
it this way.  e.g.

# type 'a foo = { a: 'a; b: int };;
type 'a foo = { a: 'a; b:int }
# let f x = {x with a=1 };;
val f : int foo -> int foo = <fun>

Why doesn't f have type 'a foo -> int foo??

It's not a big deal, since I can always construct a whole new record term,
but there may be an easy fix.  BTW adding record overriding in 2.02 has
saved me _heaps_ of time, and made it much more productive to use records.
Thanks!

Don






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

end of thread, other threads:[~1999-11-04 17:53 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1999-11-04 14:30 Record typing question Don Syme
  -- strict thread matches above, loose matches on Subject: below --
1999-10-29 13:25 Don Syme
1999-10-29 17:44 ` William Chesters

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