Version française
Home     About     Download     Resources     Contact us    
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: -- (:)
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?