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
compiling large file hogs RAM and takes a long time.
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Jacques GARRIGUE <garrigue@m...>
Subject: Re: [Caml-list] large parametrized polymorphic variant type combinations take forever to compile
From: Jon Harrop <>

> Isn't it a really bad idea to autogenerate polymorphic variant type 
> constructors anyway because, sooner or later, you'll get a hash clash? In 
> fact, wouldn't that be platform specific?

Indeed, a hash clash can happen. It will be detected at compile time,
but in a generated setting it may be harder to fix. Fortunately, at
least this is not platform specific: the hash function for variants is
defined only once and for all. Also, it is explicitly defined so that
names of up to 4 characters will all get different hash values.

On the other hand, as the intent of polymorphic variants is to be able
to use understandable constructor names, rather than complex
imbrications of datatypes, a large part of their interest is lost here.

> I would recommend factoring the sum type by the argument types of the 
> contructors in this case. Looking at Sam's files, this is trivial. Just 
> replace this:
> with this:
> type t1 = [
> | `t1_int of [
>   | `a
>   | `a0
>   | `a10000 ] * int
> | `t1_float of [`b] * float
> ]

This is mostly a matter of taste, but this might help producing better
code, independently of the compilation time. Of course, one can also
think of types that you cannot decompose this way, if the type of the
argument is always different for instance.

Jacques Garrigue