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
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: 2008-06-25 (16:29)
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.


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 =
	val parse: string -> float

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

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

module Myparser : PARSER =
	let parse = float_of_string

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!
Dario Teixeira

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