Browse thread
Phantom types and read-only variables
-
Yaron Minsky
- Yaron Minsky
- Remi Vanicat
- Markus Mottl
[
Home
]
[ Index:
by date
|
by threads
]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
| Date: | -- (:) |
| 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:
[snip]
> 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 }
write:
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? :-)
Regards,
Markus
--
Markus Mottl markus.mottl@gmail.com http://www.ocaml.info