Version française
Home     About     Download     Resources     Contact us    
Browse thread
[Caml-list] Getting rid of impossible polymorphic variant tags from infered types
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Florian Hars <hars@b...>
Subject: Re: [Caml-list] Getting rid of impossible polymorphic variant tags from infered types
Claudio Sacerdoti Coen wrote:
>  If you really need to exclude the `Fnord value at compile time, an
>  alternative solution is to use phantom types:
> 
> type 'a foo = [ `Foo | `Bar | `Fnord ]
> let f_r (v : 'a foo) (init : ([> `NoFnord] foo) list) =
>  match v with
>    `Fnord -> init
>  | _ -> v :: init
>  ;;

But this gives me the worst of both worlds, no? I have to define a function f_r 
for every type I might want to use in place of foo, *and* the type checker can 
still see the `Fnord that isn't there:

# let l' = List.fold_right f_r [`Fnord; `Foo; `Bar] [] ;;
val l' : _[> `NoFnord] foo list = [`Foo; `Bar]
# match List.hd l' with
   | `Foo -> print_endline "Foo!"
   | `Bar -> print_endline "Bar!";;
This pattern matches values of type [< `Bar | `Foo]
but is here used to match values of type
   [> `NoFnord] foo = [ `Bar | `Fnord | `Foo]
The first variant type does not allow tag(s) `Fnord

So the "| #foo_flat as v -> v :: init" version seems to be the only workable 
solution.

Yours, Florian.

-------------------
To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners