caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: skaller <skaller@users.sourceforge.net>
To: Andreas Rossberg <AndreasRossberg@web.de>
Cc: caml-list@inria.fr
Subject: Re: [Caml-list] Instruction selection in the OCaml compiler:Modulesor classes?
Date: Sun, 25 Feb 2007 04:39:34 +1100	[thread overview]
Message-ID: <1172338774.5345.21.camel@rosella.wigram> (raw)
In-Reply-To: <00c401c75824$36265fe0$15b2a8c0@wiko>

On Sat, 2007-02-24 at 15:58 +0100, Andreas Rossberg wrote:
> "skaller" <skaller@users.sourceforge.net>:
> >
> > It seems like a module functor allows both anonymous
> > signatures (structural) and also anonymous argument
> > modules (structural), yet you cannot have
> > anonymous functor applications: you have to bind the application to
> > a module name.
> 
> Not at all. For instance, given
> 
>   module Id(X : sig type t end) = X
>   module A = struct type t = int end
> 
> it is perfectly legal to write:
> 
>   module A' = Id(Id(Id(A)))
> 
> Obviosuly, the inner applications of Id are all "anonymous".
> 
> Likewise, you can say
> 
>   (3 : Id(Id(A)).t)
> 
> Also purely anonymous applications.

I had no idea you could do that!


> You can more or less do that already, as long as you introduce a suitable 
> global module to host the integer type:
> 
>   module Int = struct type t = int let compare = compare end
> 
>   signature A = sig ... val foo : u -> Set.Make(Int).t -> unit ... end
>   signature B = sig ... val bar : v -> w -> Set.Make(Int).t ... end
> 
> Admittedly, the type looks a bit ugly, and it would be even nicer if Int was 
> in the stdlib. But that are merely a questions of library design.

[..]

> Due to the "weak syntactic notion of module equivalence" I was mentioning 
> earlier you have to make sure that all these type expressions really refer 
> to the same Int module. This is a limitation of OCaml's module type system, 
> and may be what sometimes gives the impression of "nominal" typing. 

Yes .. I think I see. Two such modules 'Int' would have the same type,
but not the same 'identity'. In a similar way that

module Int' = struct type t = int let compare = mycompare end

has the same type as Int .. but it's a different module because
the value of 'compare' member is different.

I think what you're saying also explains some of the weird
sharing constraints sometimes seen.

[When I tried to implement modular functors in Felix I couldn't
figure out what was going on and had to give up .. typeclasses
were easier, but it's discouraging to find you can only have
one total order defined for integers.. :]


-- 
John Skaller <skaller at users dot sf dot net>
Felix, successor to C++: http://felix.sf.net


      reply	other threads:[~2007-02-24 17:39 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-02-22 14:38 Instruction selection in the OCaml compiler: Modules or classes? Joel Reymont
2007-02-22 17:21 ` [Caml-list] " Tom
2007-02-22 17:38 ` Xavier Leroy
2007-02-22 19:55 ` Chris King
2007-02-22 19:59 ` Markus Mottl
2007-02-23 16:13 ` brogoff
2007-02-23 18:14   ` Tom
2007-02-23 19:28     ` [Caml-list] Instruction selection in the OCaml compiler: Modulesor classes? Andreas Rossberg
2007-02-24  2:51       ` skaller
2007-02-24 11:48         ` David Baelde
     [not found]           ` <4a708d20702240518l2c430b06r18fe64cabe5cbe9@mail.gmail.com>
2007-02-24 13:33             ` Lukasz Stafiniak
2007-02-24 14:58         ` [Caml-list] Instruction selection in the OCaml compiler:Modulesor classes? Andreas Rossberg
2007-02-24 17:39           ` skaller [this message]

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=1172338774.5345.21.camel@rosella.wigram \
    --to=skaller@users.sourceforge.net \
    --cc=AndreasRossberg@web.de \
    --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).