English version
Accueil     À propos     Téléchargement     Ressources     Contactez-nous    

Ce site est rarement mis à jour. Pour les informations les plus récentes, rendez-vous sur le nouveau site OCaml à l'adresse ocaml.org.

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?