Version française
Home     About     Download     Resources     Contact us    
Browse thread
Oddness with recursive polymorphic variants
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: luc.maranget@i...
Subject: Re: [Caml-list] Oddness with recursive polymorphic variants
> I have two polymorphic variant types, as follows:
> 
>   type f = [`A | `B of f]
>   type g = [f | `C]
> 
> Next, I have a function from f to g:
> 
>   let s1 : f -> g = function
>     | `A -> `A
>     | `B b -> b
> 
> Sadly, the compiler rejects this:
> 
>     Characters 57-58:
>       | `B b -> b;;
>                 ^
>   This expression has type f but is here used with type g
>   The first variant type does not allow tag(s) `C
> 
> The error message seems odd.  Why should it matter that g has more tags 
> than f, since every value of f is a value of g (by definition)?


I cannot really explain why it matters, but I can supply a minimal (?) example

type f = [`A ]
type g = [f | `C]

let k (x:f) = (x:g);;
               ^
This expression has type f but is here used with type g
The first variant type does not allow tag(s) `C


-- Luc