caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Lauri Alanko <la@iki.fi>
To: caml-list@inria.fr
Subject: Re: [Caml-list] Signature monomorphism in functors
Date: Tue, 18 Jan 2011 14:10:36 +0200	[thread overview]
Message-ID: <20110118121036.GK323@melkinpaasi.cs.helsinki.fi> (raw)
In-Reply-To: <7f9a42a3cac8ea539f9f48432cd8a5af.squirrel@mail.mpi-sws.org>

On Tue, Jan 18, 2011 at 11:02:31AM +0100, rossberg@mpi-sws.org wrote:
> > module M3A : S3 with module M = M2 = struct
> >   module M = M2
> > end
> >
> > module F(M_ : S1) : S3 with module M = M_ = struct
> >   module M = M_
> > end
> >
> > module M3B : S3 with module M = M2 = F(M2)

> I disagree with this assessment: you can abstract the module just fine, as
> long as you do it at the signature you were using it at, namely S2, not S1.
> I don't think it should be surprising that you narrow the type of an
> expression when you narrow the types of its free variables.

True enough. The real problem is that a functor forces one to fix a
single signature into which the argument module is narrowed.

Still, I think this is legitimately as surprising as the fact that in
Hindley-Milner, beta reduction doesn't reflect well-typedness:

((fun x -> x) 42, (fun x -> x) true) : int * bool

but a seemingly legitimate abstraction

(fun f -> (f 42, f true)) (fun x -> x) is ill-typed.

I guess what I want is "bounded signature polymorphism" of some sort:

module F(A : sig module type S <: S1 module M : S end) 
  : S3 with module M = A.M = 
struct
  module M = A.M
end

module M3B : S3 with module M = M2 = 
  F(struct module type S = S2 module M = M2 end)

Alas, there are no signature bounds in ocaml and I cannot offhand
think of a way to encode them.

>   module F (X : sig val x : int end) =
>   struct
>     val y = 1
>     include X
>     val z = x + y
>   end
> 
> Without coercive subtyping semantics, what would be the meaning of:
> 
>   module A = F (struct val x = 2 val y = 3 end)

That's a good example. In fact I have always felt a bit uneasy about
the possibility of including an argument module. Now I know why.

For what it's worth, I figured out that for my current purposes, it
suffices if I simply do, for each subsignature S2 of S1:

module type S4 = sig
  module MM : S2
  include S3 with type M.t = MM.t
end

module F2(M_ : S2) : S4 with module MM = M_ = struct
  module MM = M_
  include F(M_)
end

module M3B : S4 with module MM = M2 = F2(M2)

I would have liked to shadow M with MM, but having to access it with a
different name is not too big of a deal for me, thankfully.


Lauri

  parent reply	other threads:[~2011-01-18 12:10 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-01-18  2:00 Lauri Alanko
2011-01-18 10:02 ` rossberg
2011-01-18 10:22   ` rossberg
2011-01-18 12:10   ` Lauri Alanko [this message]
2011-01-18 14:03     ` Jacques Garrigue
2011-01-18 16:41     ` 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=20110118121036.GK323@melkinpaasi.cs.helsinki.fi \
    --to=la@iki.fi \
    --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).