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
question about polymorphic variants
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: 2008-05-02 (17:35)
From: Jacques Le Normand <rathereasy@g...>
Subject: question about polymorphic variants
Hello caml-list,
when I try to run the following code:


type sometype =
  ([
    `Foo of int
  | `Bar of int
  | `Var of 'a ref
  ] as 'a)
type someother =
  ([
    `Foo of int
  | `Var of 'a ref
  ] as 'a)

let foo : someother = `Foo 5;;
(foo :> sometype)

in my ocaml repl, it gives me the following error

This expression cannot be coerced to type
  sometype = [ `Bar of int | `Foo of int | `Var of sometype ref ];
it has type someother = [ `Foo of int | `Var of someother ref ]
but is here used with type
  [< sometype ] = [< `Foo of int | `Var of sometype ref ]
Type someother = [ `Foo of int | `Var of someother ref ]
is not compatible with type
  sometype = [ `Bar of int | `Foo of int | `Var of sometype ref ]
The first variant type does not allow tag(s) `Bar



how do I get around this?