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-03 (06:57)
From: bluestorm <bluestorm.dylc@g...>
Subject: Re: [Caml-list] Conditionals based on phantom types
On Tue, Aug 3, 2010 at 8:15 AM, Joseph Young <ocaml@optimojoe.com> wrote:
> module Units : sig
>    type t
>    val to_feet : float -> [`Feet]*t
>    val to_meters : float -> [`Meters]*t
>    [..]
> end

With this type, the value representation of units is not abstract
anymore (and it is not very useful to have still t abstract). The user
can analyse the values you give him and access the unit member. This
is the difference with the ('a t) representation were the relation
between 'a and values is hidden outside the module.

For example, your user can write something like that, wich could be
indesirable :

let convert [ `Feet ] * Units.t -> [ `Meters ] * Units.t =
  function (`Feet, t) -> (`Meters, t)