caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Andreas Rossberg <rossberg@mpi-sws.org>
To: Leo White <lpw25@cam.ac.uk>
Cc: David Sheets <sheets@alum.mit.edu>, Caml List <caml-list@inria.fr>
Subject: Re: [Caml-list] First-class Functor Forgetting for Free
Date: Mon, 12 Aug 2013 13:01:59 +0200	[thread overview]
Message-ID: <5208C0A7.2040906@mpi-sws.org> (raw)
In-Reply-To: <86bo549sv9.fsf@cam.ac.uk>

On 08/11/2013 04:58 PM, Leo White wrote:
>>>> There is no implicit subtyping in OCaml's core language. The reason for that is not code generation, but type inference. For example, what type should the following function be given if the subtyping you ask for could apply?
>>>>
>>>>   let g x = let module X = (val x : D) in X.(f x)
>>>
>>> Something like val g : [< (module D)] or simply val g : (module D)
>>> where the type constraint relation is implicit seems reasonable. I
>>> don't know if you consider polymorphic variant types as part of the
>>> core language (or perhaps they aren't implicit because they propagate
>>> inequalities?).
>>
>> I don't think type inference for polymorphic variants works the way you think it does. Inference for both variants and objects is based on row polymorphism, not subtyping. A type like [< A] is actually a polymorphic type with a hidden type variable, not a subtype bound, even though the surface syntax intentionally hides that fact (which isn't always helpful). Module signatures are totally different beasts, where matching _is_ a form of subtyping.
>
> I think David is suggesting that "with-constraints" on first-class
> modules could be handled with row polymorphism, and I don't know of any
> reason why they couldn't. It would certainly be a more flexible way to
> type them. So,
>
>    let g x = let module X = (val x : D) in X.(f x)
>
> would have a type:
>
>    (module D with ..) -> int

This certainly is a nice suggestive syntax, but it is assuming an 
underlying semantic similarity that does not exist. Semantically, the 
type sharing equations on signatures have very little in common with 
rows, and I have a hard time imagining what interpreting the above as a 
row would even mean, or how it would fit in with either core or module 
typing. (I could go into boring technical details here, but I'll leave 
it at that. :) )

/Andreas


  reply	other threads:[~2013-08-12 11:02 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-08-11  1:55 David Sheets
2013-08-11  7:53 ` Andreas Rossberg
2013-08-11 13:29   ` David Sheets
2013-08-11 14:32     ` Andreas Rossberg
2013-08-11 14:58       ` Leo White
2013-08-12 11:01         ` Andreas Rossberg [this message]
2013-08-12 11:37           ` Leo White
2013-08-12 12:15             ` Andreas Rossberg
2013-08-12 13:06               ` Leo White
2013-08-12 14:15                 ` Andreas Rossberg
2013-08-12 15:17                   ` Leo White
2013-08-12 16:08                     ` Andreas Rossberg
2013-08-12 16:46                       ` Leo White
2013-08-13 11:22                         ` Andreas Rossberg

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=5208C0A7.2040906@mpi-sws.org \
    --to=rossberg@mpi-sws.org \
    --cc=caml-list@inria.fr \
    --cc=lpw25@cam.ac.uk \
    --cc=sheets@alum.mit.edu \
    /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).