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

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Julien Signoles <Julien.Signoles@l...>
Subject: Re: [Caml-list] polymorphic variants and promotion
Hello Johannes,

> What I don't understand is why the promotion of [`A of int] to [> `A of int]
> is not possible in general:
>
> # `A 1;;
> - : [> `A of int ] = `A 1
> # (`A 1 : [`A of int]) ;;
> - : [ `A of int ] = `A 1
> # ((`A 1 : [`A of int]) : [> `A of int]) ;;
> - : [ `A of int ] = `A 1
>
> Does anyone have an answer?

You have to use coercion in order to promote:
# (`A 1 : [ `A of int ] :> [> `A of int ]);;
- : [> `A of int ] = `A 1

--
Julien