* parameterized signatures
@ 1999-12-22 19:32 Chris Tilt
1999-12-23 10:44 ` Markus Mottl
0 siblings, 1 reply; 2+ messages in thread
From: Chris Tilt @ 1999-12-22 19:32 UTC (permalink / raw)
To: OCAML
Bonjour. S'il vous plaît pardon le manque de Français aujourd'hui.
Merci.
I have read (although poorly understood) the recent postings regarding
the need for parameterized signatures, which I think would help. Please
let me ask the question a different way.
Is there a way to refer to the type of a functor defined by a .mli file
in another .mli file? I am attempting to build a parameterized type and
they build a sub-type which will provide a specific implementation of
that signature. My problem is in expressing the interface of the second
type to use the constructed type from the first file.
Since some people have asked for a generalized graph module, and I also
have the need, I am trying to package one. Here is a snipet to help
explain my question. The issue is in the very last line.
Sorry for the long post and example. BTW, this code is being used in
production of a real product! Thank you all for your support of a great
programming language!
Merci, Chris
---- pgraph.mli ----
(* supply the core graph functionality *)
module type ParameterizedGraphType =
sig
type t
type edge
type vertex
val compare: t -> t -> int
end
module type S =
sig
type vid
type pEdge
type vertex = Vertex of vid * pVertex
type edge = Edge of vid * vid * pEdge
type t
type graph = t
... some functions ...
end
module Make : functor (Param: ParameterizedGraphType) ->
(S with type vid = Param.t
and type pVertex = Param.vertex
and type pEdge = Param.edge)
---- pgraph.ml -----
implements pgraph.mli in the usual way
---- wgraph.ml -----
(* use the ParameterizedGraphType module (Pgraph) to build a custom
graph which has Html.window values as vertex attributes. This is
used by the old-generation profiler product *)
module type WindowGraphType =
sig
type t = string
type vertex = Html.window
type edge = float * float
val compare: string -> string -> int
end
=====> the problem area. How do I express the type of this module?
module type Wgraph = Pgraph.S ???
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: parameterized signatures
1999-12-22 19:32 parameterized signatures Chris Tilt
@ 1999-12-23 10:44 ` Markus Mottl
0 siblings, 0 replies; 2+ messages in thread
From: Markus Mottl @ 1999-12-23 10:44 UTC (permalink / raw)
To: Chris Tilt; +Cc: OCAML
Hello,
> Is there a way to refer to the type of a functor defined by a .mli file
> in another .mli file?
> =====> the problem area. How do I express the type of this module?
> module type Wgraph = Pgraph.S ???
Acessing .mli-files as signatures is currently not possible. If I remember
right, I have already asked once whether this could be allowed, but I was
told that this would cause confusions about module names and module-type
names.
Therefore, if I use functors I normally do not use an .mli-file to restrict
the interface, but split up the code in something like:
foo_intf.ml
foo_impl.ml
and restrict the modules/functors explicitely.
"foo_intf.ml" contains, for example:
module type SPEC = sig ... end
module type T = sig ... end
and "foo_impl.ml":
open Foo_intf
module Make (Spec : SPEC) : (T with ...) = struct ... end
Sometimes it is necessary to "reexport" types from the "specification"
module.
Then I do this like:
module Make (Spec_ : SPEC) : (T with ...) = struct
module Spec = Spec_
open Spec
...
end
Of course, the signature T will then have to include something like:
module type SPEC = sig ... end
module type T = sig
module Spec : SPEC
open Spec
end
and will thus make available all types in "Spec".
I hope this helps!
Best regards,
Markus Mottl
--
Markus Mottl, mottl@miss.wu-wien.ac.at, http://miss.wu-wien.ac.at/~mottl
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~1999-12-23 16:38 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1999-12-22 19:32 parameterized signatures Chris Tilt
1999-12-23 10:44 ` Markus Mottl
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox