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.

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: 2006-05-04 (22:37) From: Jeremy Yallop Subject: Re: [Caml-list] Oddness with recursive polymorphic variants
```brogoff wrote:
> On Thu, 4 May 2006, Luc Maranget wrote:
>
>>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
>
>
> Not enough polymorphism, the error message seems clear
>
> type 'a h = 'a constraint 'a = [> `A];;
> let k (x : 'a h) = (x : g)

Thanks for the reply.  That doesn't seem to be what I want, though.  The
input to k should have type 'f'.  The output should have type 'g'.  Your
'k' can be called with values that don't match type 'f':

# k `C;;
- : g = `C

The following does what I want:

let k (#f as x:f) = (x:g)

I'd like to understand why it behaves differently from the following:

let k (x:f) = (x:g)

Jeremy.

```