Version française
Home     About     Download     Resources     Contact us    
Browse thread
typing, records and "with"
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Markus Mottl <mottl@m...>
Subject: typing, records and "with"
Hello,

it seems that the inferred type in combination with the "with" construct
(records) could sometimes be more general. Eg.:

  type 'a t = {a : 'a; b : int}

  let x = {a = 1; b = 2}
  let y = {x with a = "1"}

This leads to the following error:

  File "bla.ml", line 4, characters 9-10:
  This expression has type int t but is here used with type string t

But everything is fine with the following binding of y:

  let y = {a = "1"; b = x.b}

Maybe 'a shouldn't be bound to the type parameter of the "source record"
within the "with" construct, but checked only against the "general"
type for consistency - this would find errors as in:

  type 'a t = {a : 'a; b : 'a}

  let x = {a = 1; b = 2}
  let y = {x with a = "1"}

Regards,
Markus Mottl

-- 
Markus Mottl, mottl@miss.wu-wien.ac.at, http://miss.wu-wien.ac.at/~mottl