Version française
Home     About     Download     Resources     Contact us    
Browse thread
Union of 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 Garrigue <garrigue@m...>
Subject: Re: [Caml-list] Union of polymorphic variants...
From: Stephane Glondu <steph@glondu.net>
> Why isn't possible to do the following?
> 
> type b = [`A of [`B of bool]]
> type c = [`A of [`C of char]]
> type a = [b|c]
> 
> I expect the last declaration to be equivalent to:
> 
> type a = [`A of [`B of bool | `C of char]]

Because union of polymorphic variant is flat.
So the above requires the parameter of `A to be of type both
[`B of bool] and [`C of char].

The reason is that dispatch only looks at the head constructor:

let f = function
  | #b as x -> fb x
  | #c as x -> fc x

is actually

let f = function
  | `A _ as x -> fb x
  | `A _ as x -> fc x

which only types if both parameters have the same type.

Polymorphic variants are _not_ XML types.
Use ocamlduce for that :-)

    Jacques