Version française
Home     About     Download     Resources     Contact us    
Browse thread
Not a variant??
[ 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] Not a variant??
From: Jacques Carette <carette@mcmaster.ca>

> The function f1 below works fine -- so type d is seen to be a variant type.
> However, f2 does not compile because type c is *not* a variant type. 
> 
> However, if one looks at O'Caml's output for type c, it visually looks 
> like a variant, while that of d does not.  This is highly confusing.
> 
> This looks like a bug to me -- both c and d should be recognized as 
> variant types.
> 
> Jacques
> 
> type a = [`A ]
> type b = [`B ]
> type 'a c = 'a
>     constraint 'a = [< a | b]
>     ;;

The message is maybe not clear enough: for pattern-matching and
inheritance, you need an "exact" variant type, i.e. a type whose lower
and upper bounds are identical. This is clearly not the case for
c. The standard workaround is to write:

type c0 = [a | b]
type 'a c = 'a constraint 'a = [< c0]

Jacques Garrigue