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 and read-only variables
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: 2005-02-05 (19:21)
From: Markus Mottl <markus.mottl@g...>
Subject: Re: [Caml-list] Phantom types and read-only variables
On Sat, 05 Feb 2005, Yaron Minsky wrote:
> I'm trying to use phantom types to build a "freezable" variable, where
> I can create a version of the variable to which write operations can
> not be applied.  Here's my first attempt, which was rejected by the
> compiler:
> I do basically understand why the compiler rejects module N.  It
> basically complains that the freeze in M is not compatible with the
> constraints on N.  In particular:
> Values do not match:
>   val freeze : 'a -> 'a
> is not included in
>   val freeze : 'a t -> ro t
> So, what's the right approach here?

Hm, it seems to me that the compiler could do a better job here.

Instead of writing:

  type 'a t = { mutable value: int }


  type v = { mutable value: int }
  type 'a t = v

This should make the code compile.

I think the compiler should be able to infer automatically that 'a isn't
used on the right hand side of the record definition (i.e. that it is
just a phantom type) without using the hint of a separate monomorphic
record definition.  I guess this feature should be trivial to add.
Maybe in the next release? :-)


Markus Mottl    markus.mottl@gmail.com    http://www.ocaml.info