caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Goswin von Brederlow <goswin-v-b@web.de>
To: caml-list@inria.fr
Subject: Re: [Caml-list] Problem with universal functions in a module
Date: Mon, 12 Jan 2015 15:28:26 +0100	[thread overview]
Message-ID: <20150112142825.GA4820@frosties> (raw)
In-Reply-To: <86mw5q4gjo.fsf@cam.ac.uk>

On Sat, Jan 10, 2015 at 06:49:31PM +0000, Leo White wrote:
> > I don't see anything to infere there. Only thing I see is that in the
> > case of mono the universal function has to be unified with a single
> > type function. But 'a . 'a -> 'a should unify with int -> int
> > resulting in int -> int without problems.
> 
> 'a. 'a -> 'a cannot unify with int -> int. If it did then 'a. 'a -> 'a
> wouldn't be polymorphic: it could not be used as both int -> int and
> float -> float. Instead 'a. 'a -> 'a must be instantiated to 'b -> 'b
> which can then be unified with int -> int. It is the descision whether
> or not to perform this instantiation that needs to be infered.
> 
> To understand the full range of issues associated with higher-rank and
> impredicative polymorphism I suggest reading the relevant literature
> (e.g. "MLF: raising ML to the power of system F", "Semi-explicit
> first-class polymorphism for ML", "Flexible types: robust type inference
> for first-class polymorphism", "Boxy types: inference for higher-rank
> types and impredicativity", ...).
> 
> Regards,
> 
> Leo

I acknowledge that I'm weak on the theory here but from the example
the rules seems to be pretty simple:

    When trying to unify a universal function with a polymorphic or
    monomorphic function first instantiate.

As said I don't expect ocaml to infer what functions are universal.
That can be annotated. So the question isn't if we can infer from the
mono case wether the function is universal or monomorphic. The
function must already be annotated as universal. Dropping the
universality to allow unification with other types seems to be
straight forward though.

In laymans terms: A function 'a . 'a -> 'a can always be used where 'b
-> 'b (or in this case int -> int) is expected. That doesn't change
the type of the function itself though.

MfG
	Goswin

      reply	other threads:[~2015-01-12 14:28 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-01-07 13:50 Goswin von Brederlow
2015-01-07 15:30 ` Goswin von Brederlow
2015-01-07 17:26 ` Jeremy Yallop
2015-01-08  9:45   ` Ben Millwood
2015-01-08 15:21     ` Goswin von Brederlow
2015-01-08 16:25       ` Leo White
2015-01-09  1:02         ` Jacques Garrigue
2015-01-10 18:02           ` Goswin von Brederlow
2015-01-10 17:52         ` Goswin von Brederlow
2015-01-10 18:49           ` Leo White
2015-01-12 14:28             ` Goswin von Brederlow [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=20150112142825.GA4820@frosties \
    --to=goswin-v-b@web.de \
    --cc=caml-list@inria.fr \
    /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).