From: Goswin von Brederlow <goswin-v-b@web.de>
To: Jacques Garrigue <garrigue@math.nagoya-u.ac.jp>
Cc: Leo P White <lpw25@cam.ac.uk>, OCaml Mailing List <caml-list@inria.fr>
Subject: Re: [Caml-list] Problem with universal functions in a module
Date: Sat, 10 Jan 2015 19:02:24 +0100 [thread overview]
Message-ID: <20150110180223.GB32757@frosties> (raw)
In-Reply-To: <E368A617-5F0D-4525-84BC-E380B08A3ED0@math.nagoya-u.ac.jp>
On Fri, Jan 09, 2015 at 10:02:30AM +0900, Jacques Garrigue wrote:
> 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
Modules don't improve anything here. The problem is still that you
can't hide the implementation of the boxing:
# let make : ('a -> 'a) -> (module T) = function
| fn -> (module struct let f = fn end);;
Error: Signature mismatch:
Modules do not match: sig val f : '_a -> '_a end is not included in T
Values do not match:
val f : '_a -> '_a
is not included in
val f : 'a -> 'a
And you need different modules for different kind of types. Like 'a t,
('a, 'b) t, ... So I think modules are just as unflexible as objects
and records here.
MfG
Goswin
next prev parent reply other threads:[~2015-01-10 18: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
2015-01-10 18:02 ` Goswin von Brederlow [this message]
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=20150110180223.GB32757@frosties \
--to=goswin-v-b@web.de \
--cc=caml-list@inria.fr \
--cc=garrigue@math.nagoya-u.ac.jp \
--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