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: | Florian Weimer <fw@d...> |
| Subject: | Re: [Caml-list] strange behavior with record type definition |
* Florent:
> Ok but with these two record types defined :
> type t0 = { x : int ; y : int } ;;
> type t1 = { x : int } ;;
>
> There is no ambiguity about the following expression's type:
> { x = 0 ; y = 0 } ;;
> Why can't the t0 type be infered ?
Other common cases are ambiguous, for example:
let proj_x v = v.x
Standard ML provides what you want, and you must specify all record
fields unless the record type can be inferred by other means. For
example,
fun proj_x v = #x v
or
fun proj_x { x = x, ... } = x
does not type-check, you must write:
fun proj_x { x = x, y = _ } = x
This becomes quite cumbersome if there are more than two or three
components. There is a workaround using datatypes, i.e. write
datatype t0 = T0 of { x : int, y : int }
and
fun proj_x (T0 { x = x, ... }) = x
So both approaches have their drawbacks.