English version
Accueil     À propos     Téléchargement     Ressources     Contactez-nous    

Ce site est rarement mis à jour. Pour les informations les plus récentes, rendez-vous sur le nouveau site OCaml à l'adresse ocaml.org.

Browse thread
A strange typing error with polymorphic variants
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: 2009-10-27 (10:28)
From: Marc de Falco <marc@d...>
Subject: A strange typing error with polymorphic variants
Hi, I've come across a very strange error, and I'm not sure if it is
a bug or a feature.

The following code :
type 'a p = R of 'a t | E of float
    and 'a t = { mutable p : 'a p; c : 'a }
let f =
    let x = sqrt(2.0) in
    fun () -> { c = `A; p = E 0.0 }

generates the error :
  The type of this expression, unit -> _[> `A ] t,
  contains type variables that cannot be generalized

but if I change the x definition to "let x = 2.0 in" then it works.

Another solution is to add a dummy parameter "let f ?(dummy=())" this works
When I say that it works, I mean that the resulting type of f is
 val f : unit -> [> `A ] t
I've seen that in the dev version of ocaml this error has been removed but
the type of f is still "val f : unit -> _[> `A] t" which is not the thing
that I want.

Is that an expected behavior ?