caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* Conditionals based on phantom types
@ 2010-08-02  7:07 Joseph Young
  2010-08-02  7:49 ` [Caml-list] " Lukasz Stafiniak
  2010-08-03 15:39 ` Goswin von Brederlow
  0 siblings, 2 replies; 9+ messages in thread
From: Joseph Young @ 2010-08-02  7:07 UTC (permalink / raw)
  To: caml-list

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


^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2010-08-04  3:05 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-08-02  7:07 Conditionals based on phantom types Joseph Young
2010-08-02  7:49 ` [Caml-list] " Lukasz Stafiniak
2010-08-02  8:02   ` bluestorm
2010-08-03  2:46     ` Joseph Young
2010-08-03  6:15       ` Joseph Young
2010-08-03  6:57         ` bluestorm
2010-08-04  2:41           ` Joseph Young
2010-08-03 15:47     ` Goswin von Brederlow
2010-08-03 15:39 ` Goswin von Brederlow

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).