caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Ashish Agarwal <agarwal1975@gmail.com>
To: Gabriel Scherer <gabriel.scherer@gmail.com>
Cc: Andreas Rossberg <rossberg@mpi-sws.org>, caml List <caml-list@inria.fr>
Subject: Re: [Caml-list] Re: "module type of" on sub-module of functor result
Date: Thu, 23 Feb 2012 14:30:00 +0000	[thread overview]
Message-ID: <CAMu2m2Kt1TnzhpEHdOPN3uOpgbTqMkeL+_jjobvssSuB=3Lgug@mail.gmail.com> (raw)
In-Reply-To: <CAPFanBF-AEROr713A+UutLFeVB0xOPmeke2HNXXy2ewqnJ0H9A@mail.gmail.com>

[-- Attachment #1: Type: text/plain, Size: 3111 bytes --]

Thanks for all the helpful replies.

On Thu, Feb 23, 2012 at 10:05 AM, Gabriel Scherer <gabriel.scherer@gmail.com
> wrote:

> Apologies for muddling the water here: I'm not a module system expert
> (but working on it;) and my description was not technically accurate.
> Thanks Andreas and Jacques for the correction.
>
> In the meantime, here is a nicer workaround for you Ashish:
>
>  (* instead of representing the signature of MapLabels below directly,
>     we build a functor that returns the image signature *)
>  module MAPLABELS (Ord : BatInterfaces.OrderedType) = struct
>    module M = BatMap.Make(Ord)
>    module type S = module type of M.Labels
>  end
>
>  module MapLabels = struct
>    module Make (Ord : BatInterfaces.OrderedType) : MAPLABELS(Ord).S =
> struct
>      module M = BatMap.Make(Ord)
>      include M.Labels
>    end
>  end
>
>  module Test = MapLabels.Make(String)
>  module MS = BatMap.Make(String)
>  (* Test.t and MS.t are compatible, thanks to applicative functors *)
>  let test = Test.add ~key:"foo" ~data:1 MS.empty
>
> On Thu, Feb 23, 2012 at 12:17 AM, Jacques Garrigue
> <garrigue@math.nagoya-u.ac.jp> wrote:
> > On 2012/02/23, at 3:49, Andreas Rossberg wrote:
> >
> >> On Feb 22, 2012, at 18.24 h, Gabriel Scherer wrote:
> >>>> [A(B)] and  [A.B] are syntacticly valid module_expr's but
> >>>> [A(B).C] isn't. Is this because of an inherent limitation in the
> >>>> module system?
> >>>
> >>> I believe so. When you apply a functor, you may get fresh types as a
> >>> result -- the generative (abstract, algebraic) types of the functor
> >>> image. If you write `module M = A(B)`, the fresh types have a clear
> >>> identity: M.t, M.q etc; similarly if you pass A(B) to a functor with
> >>> formal parameter X, it is X.t, X.q etc. But if you write `module M =
> >>> A(B).C`, there is no syntactic way to name the fresh types generated
> >>> by the functor application; in particular, naming them A(B).t would be
> >>> incorrect -- because you could mix types of different applications.
> >>>
> >>> For example, what would be the signature of A(B).C with:
> >>>
> >>> module B = struct end
> >>> module A(X : sig end) = struct
> >>>   type t
> >>>   module C = struct type q = t end
> >>> end
> >>>
> >>> ?
> >>
> >> Are you perhaps thinking of SML-style generative functors here? Because
> with Ocaml's applicative functors F(A) in fact always returns the same
> abstract types, and you _can_ actually refer to types via the notation
> F(A).t ;-)
> >
> > This is not strictly correct, because of the possibility of avoidance.
> > I.e. you are allowed to apply a functor to a structure rather than a
> path, and in that case the behavior of the functor becomes generative,
> > so the problem described by Gabriel really applies in that case.
> >
> > Going back to the question of "module type of", it is currently
> implemented by typing the module expression in the usual way.
> > So extending it to a stronger form of module expression would require
> changing that, and introduce extra complexity.
> > Doable, but don't hold your breath...
> >
> > Jacques Garrigue
> >
>

[-- Attachment #2: Type: text/html, Size: 3962 bytes --]

  reply	other threads:[~2012-02-23 14:30 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-02-21 18:16 [Caml-list] " Ashish Agarwal
2012-02-21 19:37 ` [Caml-list] " Ashish Agarwal
2012-02-21 20:32   ` Hezekiah M. Carty
2012-02-22 16:18     ` Milan Stanojević
2012-02-22 16:40       ` Till Varoquaux
2012-02-22 17:24         ` Gabriel Scherer
2012-02-22 18:49           ` Andreas Rossberg
2012-02-22 23:17             ` Jacques Garrigue
2012-02-23 10:05               ` Gabriel Scherer
2012-02-23 14:30                 ` Ashish Agarwal [this message]
2012-02-22 17:35         ` Ashish Agarwal
2012-02-22 17:48           ` Gabriel Scherer

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='CAMu2m2Kt1TnzhpEHdOPN3uOpgbTqMkeL+_jjobvssSuB=3Lgug@mail.gmail.com' \
    --to=agarwal1975@gmail.com \
    --cc=caml-list@inria.fr \
    --cc=gabriel.scherer@gmail.com \
    --cc=rossberg@mpi-sws.org \
    /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).