Version française
Home     About     Download     Resources     Contact us    
Browse thread
generalizing a polymorphic variant
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Remi VANICAT <vanicat+egroups@l...>
Subject: Re: "ocaml_beginners"::[] generalizing a polymorphic variant
Julien Cohen <jcohen@a...> writes:

> Hi,
>
> if I have a [`A] I can write a function that gives me a [>`A] with the 
> same value :
>
> Objective Caml version 3.04
>
> # let (v:[`A])=`A;;
> val v : [ `A] = `A
> # let f = function `A -> `A ;;
> val f : [< `A] -> [> `A] = <fun>
> # f v;;
> - : _[> `A] = `A
> #
>
> My question is : is there a mean to build a function that would give a 
> [>..] from a [..] for every type of the form [`tag1 of t1 | ...]
>
> For example if this function is called gen and I have a value v with 
> type [`A | `B] then (gen v) would have type _[>`A | `B] .
>
> Remember I know to write such a function for A type but I want gen to 
> work with ALL types.
>
> I think this function cannot exists since I cannot write its type.

Its seem to be the case. By the way :
# `A;;
- : [> `A] = `A

so, if you don't use explicit type, you have your [> `A], and :
# let e = (`A : [`A]);;
val e : [ `A] = `A
# (e : [ `A] :> [> `A]);;
- : [> `A] = `A

so you don't need a function, you only need coercions.

-- 
Rémi Vanicat
vanicat@l...
http://dept-info.labri.u-bordeaux.fr/~vanicat