Re: Efficency in OCaml

From: Markus Mottl (mottl@miss.wu-wien.ac.at)
Date: Sat Sep 04 1999 - 18:50:19 MET DST


From: Markus Mottl <mottl@miss.wu-wien.ac.at>
Message-Id: <199909041550.RAA18090@miss.wu-wien.ac.at>
Subject: typing, records and "with"
To: caml-list@inria.fr (OCAML)
Date: Sat, 4 Sep 1999 17:50:19 +0100 (MET DST)

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



This archive was generated by hypermail 2b29 : Sun Jan 02 2000 - 11:58:25 MET