Version française
Home     About     Download     Resources     Contact us    
Browse thread
Re: [Caml-list] mutability analysis too strict?
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Remi VANICAT <vanicat@l...>
Subject: Re: [Caml-list] mutability analysis too strict?
"Ohad Rodeh" <ORODEH@il.ibm.com> writes:

> First of all, sorry my mail was sent twice, this was due to mail delivery
> problems
> from my site.
> 
> Perhaps I was not specific enough about what I wanted to acheive. What I
> need
> is a repository that has the following interface:
> 
> module type Repos = sig
>   val put : 'a -> 'b -> unit
>   val get : 'a -> 'b
> end
> 
> An  implementation that looks like this:
> 
> module S : Repos = struct
>    let h = Hashtbl.create 10
>    let put key data = Hashtbl.add h key data
>    let get key = Hashtbl.find h key
> end
> 
> Does not work. Compilation error:
> 
> Signature mismatch:
> Modules do not match:
>   sig
>     val h : ('_a, '_b) Hashtbl.t
>     val put : '_a -> '_b -> unit
>     val get : '_a -> '_b
>   end
> is not included in
>   Repos
> Values do not match:
>   val put : '_a -> '_b -> unit
> is not included in
>   val put : 'a -> 'b -> unit
> 
> I tried also using the Map and Set modules, but they don't really allow
> building
> a repository of immutable values either. Is there any deep reason for this
> behavior? Could you expound on this line:
> 
> > A monomorphic, mutable
> > structure that contains polymorphic data is sound, but cannot be
> expressed
> > in ML's type system where universal quantification must be prenex.
> 
> Ohad.

it's dangerous. Imagine you can do :

put 2 "xd"

what will be the type of :

get 2

how the type inference algorithm can know that it is a string ? it
can't because you can do something like :

if x < y then put 2 "xd"
else put 2 5

and then, the type of get 2 wil be string or int depending on the fact
that x was less than y or not.


-- 
Rémi Vanicat
vanicat@labri.u-bordeaux.fr
http://dept-info.labri.u-bordeaux.fr/~vanicat
-------------------
Bug reports: http://caml.inria.fr/bin/caml-bugs  FAQ: http://caml.inria.fr/FAQ/
To unsubscribe, mail caml-list-request@inria.fr  Archives: http://caml.inria.fr