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
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: 2010-08-02 (07:31)
From: Joseph Young <ocaml@o...>
Subject: Conditionals based on phantom types
 	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

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