caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Jacques Garrigue <garrigue@math.nagoya-u.ac.jp>
To: Leo P White <lpw25@cam.ac.uk>
Cc: Goswin von Brederlow <goswin-v-b@web.de>,
	OCaml Mailing List <caml-list@inria.fr>
Subject: Re: [Caml-list] Problem with universal functions in a module
Date: Fri, 9 Jan 2015 10:02:30 +0900	[thread overview]
Message-ID: <E368A617-5F0D-4525-84BC-E380B08A3ED0@math.nagoya-u.ac.jp> (raw)
In-Reply-To: <86k30xutma.fsf@cam.ac.uk>

On 2015/01/09 01:25, Leo White wrote:
> 
>> 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.

Actually the formal system for polymorphic methods use a notion of boxing/unboxing
of first-class polymorphic values. It would be trivial to add it to ocaml's type system.
There was not much demand originally, but with the introduction of GADTs it becomes
more interesting.

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

Note also that first-class modules already provide another flexible approach to first-class
polymorphism, and while you need to define a package type, equality of package
types is structural since 4.02.

   module type T = sig val f : 'a -> 'a end

   let f (module X : T) =
     let poly : (module T) =
       if true then (module X)
       else (module struct let f x = x end)
     in
     let mono =
       if true then X.f
       else (fun x -> x + 1)
     in
       (poly, mono)

As you can see here, the only slightly heavy part is the syntax for building modules.

Jacques Garrigue

  reply	other threads:[~2015-01-09  1:02 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 [this message]
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=E368A617-5F0D-4525-84BC-E380B08A3ED0@math.nagoya-u.ac.jp \
    --to=garrigue@math.nagoya-u.ac.jp \
    --cc=caml-list@inria.fr \
    --cc=goswin-v-b@web.de \
    --cc=lpw25@cam.ac.uk \
    /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).