caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: "Lukasz Stafiniak" <lukstafi@gmail.com>
To: "caml users" <caml-list@inria.fr>
Subject: [Caml-list] Instruction selection in the OCaml compiler: Modulesor classes?
Date: Sat, 24 Feb 2007 14:33:12 +0100	[thread overview]
Message-ID: <4a708d20702240533r573a1d1w218d5ae4bde8c814@mail.gmail.com> (raw)
In-Reply-To: <4a708d20702240518l2c430b06r18fe64cabe5cbe9@mail.gmail.com>

[I'm sorry, I forgot to send to the list!]

On 2/24/07, David Baelde <david.baelde@gmail.com> wrote:
> On 2/24/07, skaller <skaller@users.sourceforge.net> wrote:
> > 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. If we really had structural typing that name would
> > simply be an alias. Why can't we eliminate that name? ***
>
> One worthy remark here might be that side-effects can occur at functor
> instantiation. Then, forcing the user to think about when the
> instantiation occurs is useful...
>
Yet OCaml already has trouble with some nasty patterns of effects at
functor instantiation.

Taken from one of the slides at http://www.cs.cmu.edu/~rwh/courses/modules/

This is good (Skaller: does it solve your problem?):

module type DICT = functor (Key : Set.OrderedType) -> sig
 type 'a dict
 val domain : 'a dict -> Set.Make(Key).t
end;;

module type PRIO_QUEUE = functor (Elt : Set.OrderedType) -> sig
 type queue
 val contents : queue -> Set.Make(Elt).t
end;;

module QueuedDict (Data : Set.OrderedType)
 (MyDict : DICT) (MyPrioQueue : PRIO_QUEUE) =
struct
 module Dict = MyDict (Data)
 module PQ = MyPrioQueue (Data)
 module DataSet = Set.Make (Data)
 let queued_domain dict pq =
   DataSet.equal (Dict.domain dict) (PQ.contents pq)
end;;

This is bad:

let moonFull = let v = ref false in fun () -> v := not !v; !v
;;

module type S = sig
 type t
 val x : t
 val f : t -> t
 val g : t -> t -> bool
end;;

module Weird (Top : sig end) = (struct
 type t = int
 let x = if moonFull () then 1 else 2
 let f x = x + 2
 let g x y = (3*x + 2*y) / (x - y + 1) = 7
end : S);;

module Gen (X : functor (Top : sig end) -> S) = X (struct end);;

module W1 = Gen (Weird);; (* moon full now *)
module W2 = Gen (Weird);; (* moon no longer full now *)
W1.g W1.x W2.x;;


  parent reply	other threads:[~2007-02-24 13:33 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 [this message]
2007-02-24 14:58         ` [Caml-list] Instruction selection in the OCaml compiler:Modulesor classes? Andreas Rossberg
2007-02-24 17:39           ` skaller

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=4a708d20702240533r573a1d1w218d5ae4bde8c814@mail.gmail.com \
    --to=lukstafi@gmail.com \
    --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).