caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* using functors in objects
@ 2008-04-10  0:52 Jacques Le Normand
  2008-04-10 12:05 ` [Caml-list] " Andrej Bauer
  0 siblings, 1 reply; 4+ messages in thread
From: Jacques Le Normand @ 2008-04-10  0:52 UTC (permalink / raw)
  To: caml-list

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

hello caml-list,
I would like to do something like this:

module A (X: sig type t end) =
struct
  class c =
  object
    val b = (None : X.t option)
  end
end

class d =
module Y = A(struct type t = d end)
object
  inherit Y.c
end

which, of course, gives me a syntax error. is it possible to bind a module
inside a class?
--Jacques

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

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [Caml-list] using functors in objects
  2008-04-10  0:52 using functors in objects Jacques Le Normand
@ 2008-04-10 12:05 ` Andrej Bauer
  2008-04-11  7:52   ` Julien Signoles
  0 siblings, 1 reply; 4+ messages in thread
From: Andrej Bauer @ 2008-04-10 12:05 UTC (permalink / raw)
  To: Jacques Le Normand; +Cc: caml-list

Perhaps something like this with recursive modules. I have a feeling it
can be simplified, though.

Andrej

--------------------
module A (X: sig type t end) =
struct
  class c =
  object
    val b = (None : X.t option)
  end
end

module rec D : sig
  class d : object val b : D.d option end
end =
struct
  class d =
  object
    inherit Y.c
  end
end

and Y :
sig
  class c : object val b : D.d option end
end =
  A(struct type t = D.d end)

class d = D.d

----------------


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [Caml-list] using functors in objects
  2008-04-10 12:05 ` [Caml-list] " Andrej Bauer
@ 2008-04-11  7:52   ` Julien Signoles
  2008-04-11 11:59     ` Andrej Bauer
  0 siblings, 1 reply; 4+ messages in thread
From: Julien Signoles @ 2008-04-11  7:52 UTC (permalink / raw)
  To: Andrej Bauer; +Cc: Jacques Le Normand, caml-list


> Perhaps something like this with recursive modules. I have a feeling it
> can be simplified, though.
>
> Andrej
>
> --------------------
> module A (X: sig type t end) =
> struct
>  class c =
>  object
>    val b = (None : X.t option)
>  end
> end
>
> module rec D : sig
>  class d : object val b : D.d option end
> end =
> struct
>  class d =
>  object
>    inherit Y.c
>  end
> end
>
> and Y :
> sig
>  class c : object val b : D.d option end
> end =
>  A(struct type t = D.d end)
>
> class d = D.d
>
> ----------------

it doesn't work because the recursive modules cannot be safely 
initialized in such a case:

$ ocamlc -v
The Objective Caml compiler, version 3.10.1
Standard library directory: /home/jsignole/local/godi/lib/ocaml/std-lib
$ ocamlc -o modclass modclass.ml
$ ./modclass
Fatal error: exception Undefined_recursive_module("modclass.ml", 23, 2)

Yet I haven't a good solution for such a think :-(.

--
Julien


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [Caml-list] using functors in objects
  2008-04-11  7:52   ` Julien Signoles
@ 2008-04-11 11:59     ` Andrej Bauer
  0 siblings, 0 replies; 4+ messages in thread
From: Andrej Bauer @ 2008-04-11 11:59 UTC (permalink / raw)
  To: caml-list caml-list

Julien Signoles wrote:
> $ ocamlc -v
> The Objective Caml compiler, version 3.10.1
> Standard library directory: /home/jsignole/local/godi/lib/ocaml/std-lib
> $ ocamlc -o modclass modclass.ml
> $ ./modclass
> Fatal error: exception Undefined_recursive_module("modclass.ml", 23, 2)

Oh my god! What ever happened to safety?! You know, the little theorem
that says "If a program is well typed then it does not explode in your
face".

I naively thought it would work because it compiled. Yuck!

Andrej


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2008-04-11 11:56 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-04-10  0:52 using functors in objects Jacques Le Normand
2008-04-10 12:05 ` [Caml-list] " Andrej Bauer
2008-04-11  7:52   ` Julien Signoles
2008-04-11 11:59     ` Andrej Bauer

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).