Browse thread
strange behavior with record type definition
[
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: | Jon Harrop <jon@f...> |
| Subject: | Re: [Caml-list] strange behavior with record type definition |
On Friday 11 November 2005 22:59, Florent wrote:
> Hi, I have defined two distinct record's types with a field's name in
> common. But when I try to define a function that uses the first of the
> types, the compiler gives me a type error.
> How can I use my first type in a function ??
>
> This is what I did:
>
> # type t0 = { i : int ; s : string };;
> type t0 = { i : int; s : string; }
> # type t1 = { i : int ; f : float };;
> type t1 = { i : int; f : float; }
> # let f (x:t0) = match x with {i= a; s= b} -> b;;
> Characters 28-40:
> let f (x:t0) = match x with {i= a; s= b} -> b;;
> ^^^^^^^^^^^^
> The record field label s belongs to the type t0
> but is here mixed with labels of type t1
Either use different field names, e.g.:
type t0 = { i0 : int ; s0 : string }
type t1 = { i1 : int ; f1 : float }
or put them in separate modules.
--
Dr Jon D Harrop, Flying Frog Consultancy Ltd.
Objective CAML for Scientists
http://www.ffconsultancy.com/products/ocaml_for_scientists