Version française
Home     About     Download     Resources     Contact us    
Browse thread
[Caml-list] simple typing question
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Michael Vanier <mvanier@c...>
Subject: Re: [Caml-list] simple typing question
> From: Pierre Weis <pierre.weis@inria.fr>
> Date: Tue, 2 Jul 2002 11:14:58 +0200 (MET DST)
> Cc: caml-list@inria.fr
> Content-Type: text/plain; charset=ISO-8859-1
> 
> > 
> > I imagine this has been asked and answered before, so I apologize in
> > advance.
> > 
> > Compare these two functions:
> > 
> > # let f x = List.map (fun y -> y) x ;;
> > val f : 'a list -> 'a list = <fun>
> > 
> > and
> > 
> > # let f = List.map (fun y -> y) ;;
> > val f : '_a list -> '_a list = <fun>
> > 
> > Why does the second use the '_a type variable instead of 'a?  I thought
> > that special type variables only had to do with polymorphic references.
> > The FAQ states that the latter expression can't be generalized, but I don't
> > really understand why.
> > 
> > Mike
> 
> This is explained in the FAQ of the language either in english
> 
> http://pauillac.inria.fr/caml/FAQ/FAQ_EXPERT-eng.html#polymorphisme
> 
> ou en français:
> 
> http://pauillac.inria.fr/caml/FAQ/FAQ_EXPERT-fra.html#polymorphisme
> 
> If you don't understand the explanations, please let me know.
> 
> Cordialement,
> 
> Pierre Weis
> 
> INRIA, Projet Cristal, Pierre.Weis@inria.fr, http://pauillac.inria.fr/~weis/
> 
> 
> 

I *almost* understand.  I understand the need for restrictions with
polymorphic references.  The stated rule is that for

  let name = expr1 ...

  The type of expr1 is generalized when expr1 is a function, an identifier
  or a constant. Otherwise the identifier name is not polymorphic (type
  variables are not generalized).

And later it's stated that when expr1 is "map (function x -> x)" it's an
application, so it isn't generalized.  However, it's an application that
evaluates to a function, so it seems like it would meet the stated
criteria.  Also, I'm not sure why such a restrictive rule is needed.  If
expr1 doesn't manipulate references, why can't it be generalized?  Sorry to
belabor this.

Mike

-------------------
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