Version française
Home     About     Download     Resources     Contact us    

This site is updated infrequently. For up-to-date information, please visit the new OCaml website at

Browse thread
Type error
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: 2005-04-02 (07:50)
From: Jacques Garrigue <garrigue@m...>
Subject: Re: [Caml-list] Type error
From: Jon Harrop <>

> I've got a type error:
> This type of expression, <height:int; width:int; _..> -> unit, contains type 
> variables that cannot be generalized
> which appears with the form:
> let f =
>   let t = ref None in
>   fun data -> ...
> but not in the unnested form:
> let t = ref None
> let f =
>   fun data -> ...
> Is that supposed to happen? I thought those two forms were exactly
> equivalent.  

They are not.
The criterion to decide whether to generalize type variables in a
definition is whether it is syntactically a "value" or not.
Since [ref None] is not a value, your first definition ends up not
being a value, and cannot be generalized.
The second one is ok, because probably t is later constrained to have
a specific type (not containing type variables) and f is now a "value"
and can be properly generalized.
Note also that this error message does not occur if you provide an
interface for your module. But you may in place have a message about a
type not being included in another, if you really expected the
function to be polymorphic.

Jacques Garrigue