English version
Accueil     À propos     Téléchargement     Ressources     Contactez-nous    
Browse thread
Conditionals based on phantom types
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Joseph Young <ocaml@o...>
Subject: Conditionals based on phantom types
Hi,
 	Is there any way to write a conditional based on the type 
information of a value?  Specifically, if we use phantom types to write a 
module such as

module Units : sig
     type 'a t
     val to_feet : float -> [`Feet ] t
     val to_meters : float -> [`Meters] t
     val add : 'a t -> 'a t -> 'a t
     val print : 'a t -> unit
end = struct
     type 'a t = float
     let to_feet x=x
     let to_meters x=x
     let add x y = x +. y
     let print x = Printf.printf "%f (units)" x
end;;

is there anyway to modify the print statement to correctly denote which 
units are used?

 	Thanks.

Joe