caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: skaller <skaller@users.sourceforge.net>
To: Vsevolod Fedorov <sevaAtWork@mail.ru>
Cc: caml-list@yquem.inria.fr
Subject: Re: [Caml-list] function specialization
Date: Wed, 16 Nov 2005 00:11:55 +1100	[thread overview]
Message-ID: <1132060315.9002.24.camel@rosella> (raw)
In-Reply-To: <00a701c5e9da$1b0ebc20$670aa8c0@seva>

On Tue, 2005-11-15 at 14:45 +0300, Vsevolod Fedorov wrote:
> Hello!

>   (*   ^^^ This expression has type string -> unit but is here used with
> type int -> unit *)

Here is a simpler case:

let use (f: 'a -> unit) = f 1; f ""

The appearance of a 'free' type variable in the function
signature implicitly implies the quantification:

For all 'a . let use (f: 'a -> unit) =  f 1; f ""

which says, for each type 'a, there is a function 'use' ..

Inside a particular instance of use, 'a is fixed.

In Ocaml this design bug has been fixed for record and object fields:

type t = { f: 'a . 'a -> unit }
let use (wrap: t) = wrap.f 1; wrap.f ""

Here the quantifier is explicit and binds only the
type of the field f; and the record type t is entirely 
monomorphic.

Note that the first interpretation is necessary
in the first case, by considering:

let f (x:int) = ()
use f;

we simply cannot have the inner

f ""

type correctly. In the second case, you cannot
instantiate the field with that f, because it
is the wrong type -- the field requires the
function to be polymorphic.

With any luck this design bug will eventually be
properly fixed, so you can write:

let use (f: 'a . 'a -> unit) =  f 1; f ""

-- 
John Skaller <skaller at users dot sf dot net>
Felix, successor to C++: http://felix.sf.net


      parent reply	other threads:[~2005-11-15 13:12 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-11-15 11:45 Vsevolod Fedorov
2005-11-15 12:57 ` [Caml-list] " Alessandro Baretta
2005-11-15 13:00 ` Jørgen Hermanrud Fjeld
2005-11-15 13:11 ` skaller [this message]

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=1132060315.9002.24.camel@rosella \
    --to=skaller@users.sourceforge.net \
    --cc=caml-list@yquem.inria.fr \
    --cc=sevaAtWork@mail.ru \
    /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).