Version française
Home     About     Download     Resources     Contact us    
Browse thread
[Caml-list] Re: findlib-0.8.1 and ocaml-3.07+beta1
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: james woodyatt <jhw@w...>
Subject: Re: [Caml-list] Re: findlib-0.8.1 and ocaml-3.07+beta1
On Thursday, Jul 24, 2003, at 18:28 US/Pacific, Karl Zilles wrote:
> james woodyatt wrote:
>> I'm specifically excited about the polymorphic generalization of 
>> covariant parts of expansive expressions.
>
> I read about this in the changes document, but I'm unable to wrap my 
> head around it.
>
> > For instance, if f: unit -> 'a list, "let x = f ()"
> > gives "x" the generalized type forall 'a. 'a list, instead of '_a 
> list
> > as before.
>
> Can someone simplify this for me?  Under what circumstances would this 
> be useful?

Sure.  I see it with functors.  Consider the following example:

	# module type X = sig
	    type +'a t
	    val f: unit -> 'a t
	  end;;

This is a module type I plan to use as the input to a functor.  The top 
responds with this following:

	module type X = sig type +'a t val f : unit -> 'a t end

So, imagine you want to write a functor like so:

	# module Y(X: X) = struct
	    let x = X.f ()
	  end;;

Here's what the 3.06 top-level says is the type of that module:

	module Y : functor (X : X) -> sig val x : '_a X.t end

Here's what the 3.07+beta1 version says:

	module Y : functor (X : X) -> sig val x : 'a X.t end

This is so much better.  In the 3.06 case, I get a module whose type 
isn't complete yet.  In the 3.07+beta1 case, I get a module whose type 
is complete.  With 3.06, I have to write 'x' as a function that returns 
a constructed object every time I call it.  With 3.07+beta1, I can 
write 'x' as a value that gets constructed once when the functor is 
called.


-- 
j h woodyatt <jhw@wetware.com>
that's my village calling... no doubt, they want their idiot back.

-------------------
To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners