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
list of objects
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Xavier Leroy <Xavier.Leroy@i...>
Subject: Re: list of objects
Your approach looks reasonable.  As for your question:

> let sig_list = [new plain; new simple] 
> On compilation, this produces:
>   The type of this expression, '_a Sigs.plain list,
>   contains type variables that cannot be generalized
> However sending the exact same code to the top level,
> produces:
> val sig_list : '_a Sigs.plain list = [<obj>; <obj>]
> Works just fine! What gives?

The '_a is a non-generalized type variable, i.e. an unknown type that
will be determined later at first use.  (See the FAQ for more detailed

For separately-compiled units, the notion of "first use" is unclear,
since the unit can be referenced by several other separately-compiled
units, which could each instantiate the unknown type in different
ways.  So, to keep things simple, the compiler requires that no
non-generalized type variables remain in the types inferred for
definitions of a compilation unit.

Thus, you need to put either a .mli file giving the type you want for
sig_list, or a type constraint on the definition of sig_list:
        let sig_list = ([new plain; new simple] : t Sigs.plain list)
with the type you want for "t".

Hope this helps,

- Xavier Leroy