Version française
Home     About     Download     Resources     Contact us    
Browse thread
Phantom types: transparency vs rogue unification
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Dario Teixeira <darioteixeira@y...>
Subject: Re: [Caml-list] Phantom types: transparency vs rogue unification
> Note that I would personally implement Stringies_IO a
> Functor over 
> Stringies rather than having explicit dependencies.
> 

Hi,

Indeed!  In the meantime I've also thought of a functor-based solution,
which does the job even though it looks rather contrived:

_________________________________________________________
module type PARSER =
sig
	val parse: string -> float
end

module type STRINGIES =
sig
	type 'a t
	val make: float -> string t
	val add: string t -> string t -> string t
	val parse: string -> string t
end

module Stringies (Parser : PARSER): STRINGIES =
struct
	type 'a t = float
	let make x = x
	let add a b = a +. b
	let parse = Parser.parse
end

module Myparser : PARSER =
struct
	let parse = float_of_string
end

module Mystringies = Stringies (Myparser)

open Mystringies

let ola = add (make 1.0) (make 2.0);;
let ola = add (make 1.0) 2.0;; (* Error *)
_________________________________________________________


Thanks for your time!
Cheers,
Dario Teixeira




      __________________________________________________________
Sent from Yahoo! Mail.
A Smarter Email http://uk.docs.yahoo.com/nowyoucan.html