caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: "Gérard Huet" <Gerard.Huet@inria.fr>
To: John Max Skaller <skaller@ozemail.com.au>
Cc: caml-list@pauillac.inria.fr
Subject: Re: [Caml-list] Error: Type variables, that can not be generalized?!
Date: Fri, 21 Feb 2003 17:20:10 +0100	[thread overview]
Message-ID: <5972C25A-45B8-11D7-8D22-0003938819CE@inria.fr> (raw)
In-Reply-To: <3E559D48.8030800@ozemail.com.au>


Le vendredi, 21 fév 2003, à 04:30 Europe/Paris, John Max Skaller a 
écrit :

> BTW: I've always been baffled by the seeminly wrong nomenclature
> 'generalisation' when in fact unification involves *specialising*
> types/type variables. Does it refer to the seeking of the
> 'most general' unifier -- that is, the most general specialisation?
>
> Error messages like
>
> "The type of this expression, ('_a, `_b) Hashtbl.t,
> contains type variables that cannot be generalized"
>
> seem counterintuitive when in fact the problem is
> that variables can't be made specific enough.

Generalisation refers to transforming a free type variable into a 
universally quantified type
variable. Hindley-Milner polymorphism is more than first order 
unification, it allows
instantiation of a variable by types mutually incompatible. This is why 
ML allows
let i x = x in (i "a",i 0) c
because i has a truly polymorphic type a -> a, which get instantiated 
in string -> string
and int -> int, even though string and int are not unifiable.
Or even better :
  let i x = x in (i i);;
  - : '_a -> '_a = <fun>
and indeed :
let foo = let i x = x in (i i) in (foo foo);;
This expression has type 'a -> 'a but is here used with type 'a

The trick is that "let x=M in N" is treated differently from the redex 
(fun x->N)M,
and rather like M[x<-N] where the various occurrences of x may receive 
different type
assignments

GH



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


  reply	other threads:[~2003-02-21 16:16 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2003-02-20 19:50 Oliver Bandel
2003-02-20 19:54 ` Basile STARYNKEVITCH
2003-02-21  3:30   ` John Max Skaller
2003-02-21 16:20     ` Gérard Huet [this message]
2003-02-21  0:23 Arturo Borquez

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=5972C25A-45B8-11D7-8D22-0003938819CE@inria.fr \
    --to=gerard.huet@inria.fr \
    --cc=caml-list@pauillac.inria.fr \
    --cc=skaller@ozemail.com.au \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).