Version française
Home     About     Download     Resources     Contact us    

This site is updated infrequently. For up-to-date information, please visit the new OCaml website at

Browse thread
[Caml-list] inference and phantom types
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: 2002-10-21 (15:23)
From: Julien Cohen <jcohen@l...>
Subject: [Caml-list] inference and phantom types
I read in the thread
that phantom types could be used in ocaml but I have some 
troubles understanding the way they really work.

In the following session I use a phantom type ('a,'b)t to 
simulate a list with an additionnal type 'b. I create a special 
cons preserving the type. I create an (int,bool)t value and when 
I make a cons on it and the phantom type seems not to be well 

         Objective Caml version 3.04

# type ('a,'b) t = 'a list;;
type ('a, 'b) t = 'a list

# let f (x:'a) (y:('a,'b) t) = (x::y : ('a,'b) t);;
val f : 'a -> ('a, 'b) t -> ('a, 'b) t = <fun>

# let (v: (int,bool) t) = [1];;
val v : (int, bool) t = [1]

# f 1 v;;
- : (int, '_a) t = [1; 1]

Is there a fundamental reason for the bool type not to be inferred?
(no response in the ocaml-beginner list)

Julien Cohen

To unsubscribe, mail Archives:
Bug reports: FAQ:
Beginner's list: