caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Leo White <lpw25@cam.ac.uk>
To: Goswin von Brederlow <goswin-v-b@web.de>
Cc: caml-list@inria.fr
Subject: Re: [Caml-list] Problem with universal functions in a module
Date: Thu, 08 Jan 2015 16:25:49 +0000	[thread overview]
Message-ID: <86k30xutma.fsf@cam.ac.uk> (raw)
In-Reply-To: <20150108152157.GA4890@frosties> (Goswin von Brederlow's message of "Thu, 8 Jan 2015 16:21:57 +0100")

> I don't see how there can be much added complexity involved. The
> higher-rank polymorphism is already allowed in records and objects so
> the type system knows how to deal with them. At least when they are
> annotated. I wouldn't need ocaml to infere those types.

It is possible that higher-rank types would not add too much complexity
to OCaml.

However, there is an important difference between that and the
higher-rank polymorphism provided by records and objects: whether to
instantiate a type or not must be inferred. For example, compare this
example using polymorphic methods:

    let f (x : < m: 'a. 'a -> 'a >) =
      let poly =
        if true then x
        else object method m : 'a. 'a -> 'a = id end
      in
      let mono =
        if true then x#m
        else (fun x -> x + 1)
      in
        (poly, mono)

with this example using proper higher-rank types:

    let f (x : 'a. 'a -> 'a) =
      let poly =
        if true then x
        else id
      in
      let mono =
        if true then x
        else (fun x -> x + 1)
      in
        (poly, mono)

Using objects with polymorphic methods we can trivially see that the
first use of `x` is not instantiated whilst the second use of `x` is
instantiated because the first uses the object itself whilst the second
uses the method `m`.

With higher-rank polymorphism, we must infer this information. I don't
think this can be done in a principal way, without adding complexity to
the type langauge (see MLF), so there would need to be some additional
type annotations.

Regards,

Leo

  reply	other threads:[~2015-01-08 16:25 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 [this message]
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

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=86k30xutma.fsf@cam.ac.uk \
    --to=lpw25@cam.ac.uk \
    --cc=caml-list@inria.fr \
    --cc=goswin-v-b@web.de \
    /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).