* A functor to produce recursive modules ?
@ 2008-05-22 20:58 Fabrice Marchant
2008-05-23 6:18 ` [Caml-list] " Alain Frisch
0 siblings, 1 reply; 9+ messages in thread
From: Fabrice Marchant @ 2008-05-22 20:58 UTC (permalink / raw)
To: caml-list
Hi !
Apologize. This topic isnt't exactly at its right place : belongs to Beginners-list.
However no answer about this question there and so much clever people here, a denser traffic...
Please how to define recursive modules that are parametrized by an OrderedType ?
Say these modules types are Mod and ModSet.
(Because a function f in module Mod uses a Set of Mod)
The problem is I need recursive functors that returns 2 modules.
Waiting for a solution, I bypass the problem in defining a non-recursive functor Mod.Make and a Mod function f that returns a Mod List instead of the wanted Mod Set.
module StringMod = Mod.Make ( String )
Of course it's then possible to convert the StringMod List to a StringMod Set but a cleaner work would be to write this a single time a general way inside the functor Mod.Make...
Here is an example :
http://fabrice.marchant.free.fr/graph/example/
The module 'digraph' holds a Make functor that produces an oriented graph of any OrderedType.
The function 'search_loops' returns a list of the loops:Digraph found in the Digraph.
Please how to change things to return a _ Set _ of Digraphs instead ?
The manual explains how to define simple recursive modules, but I do not see the way to perform this with parametred modules.
Any light ?
Fabrice
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [Caml-list] A functor to produce recursive modules ?
2008-05-22 20:58 A functor to produce recursive modules ? Fabrice Marchant
@ 2008-05-23 6:18 ` Alain Frisch
2008-05-23 18:00 ` Fabrice Marchant
` (2 more replies)
0 siblings, 3 replies; 9+ messages in thread
From: Alain Frisch @ 2008-05-23 6:18 UTC (permalink / raw)
To: Fabrice Marchant; +Cc: caml-list
Fabrice Marchant wrote:
> Hi !
>
> Apologize. This topic isnt't exactly at its right place : belongs to Beginners-list.
> However no answer about this question there and so much clever people here, a denser traffic...
>
> Please how to define recursive modules that are parametrized by an OrderedType ?
> Say these modules types are Mod and ModSet.
> (Because a function f in module Mod uses a Set of Mod)
>
> The problem is I need recursive functors that returns 2 modules.
I'm not sure to understand. Maybe a functor that returns a pair of
mutually recursive modules is what you want.
module F(X : Set.OrderedType) = struct
module rec Mod : sig
type t = X of int * ModSet.t
val compare: t -> t -> int
val of_list: t list -> t
end
=
struct
type t = X of int * ModSet.t
let compare (X (i, _)) (X (j, _)) = compare i j
let of_list i l = X (i, List.fold_right ModSet.add l ModSet.empty)
end
and ModSet : Set.S with type elt = Mod.t = Set.Make(Mod)
end
-- Alain
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [Caml-list] A functor to produce recursive modules ?
2008-05-23 6:18 ` [Caml-list] " Alain Frisch
@ 2008-05-23 18:00 ` Fabrice Marchant
2008-05-23 19:40 ` Fabrice Marchant
2008-05-23 19:42 ` Fabrice Marchant
2 siblings, 0 replies; 9+ messages in thread
From: Fabrice Marchant @ 2008-05-23 18:00 UTC (permalink / raw)
To: caml-list
Thanks a lot Alain !
> > The problem is I need recursive functors that returns 2 modules.
>
> I'm not sure to understand. Maybe a functor that returns a pair of
> mutually recursive modules is what you want.
That's it !
> module F(X : Set.OrderedType) = struct
> module rec Mod : sig
> type t = X of int * ModSet.t
> val compare: t -> t -> int
> val of_list: t list -> t
val of_list: int -> ModSet.elt list -> t
> end
> =
> struct
> type t = X of int * ModSet.t
> let compare (X (i, _)) (X (j, _)) = compare i j
> let of_list i l = X (i, List.fold_right ModSet.add l ModSet.empty)
> end
> and ModSet : Set.S with type elt = Mod.t = Set.Make(Mod)
> end
This was the kind of example I needed.
Up to now, I don't have written many functors. My problem here was simply I didn't thought to nest the two recursive modules inside a functor.
This becomes obvious now.
Regards,
Fabrice
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [Caml-list] A functor to produce recursive modules ?
2008-05-23 6:18 ` [Caml-list] " Alain Frisch
2008-05-23 18:00 ` Fabrice Marchant
@ 2008-05-23 19:40 ` Fabrice Marchant
2008-05-23 19:42 ` Fabrice Marchant
2 siblings, 0 replies; 9+ messages in thread
From: Fabrice Marchant @ 2008-05-23 19:40 UTC (permalink / raw)
To: caml-list
Bonsoir,
Désolé de vous avoir écrit en mauvais anglais. C'était une erreur : je visais la liste.
Merci de votre réponse : bien sûr, il fallait entourer les modules interdépendants par un foncteur et je n'y songeais pas !
Sincères salutations.
Fabrice Marchant
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [Caml-list] A functor to produce recursive modules ?
2008-05-23 6:18 ` [Caml-list] " Alain Frisch
2008-05-23 18:00 ` Fabrice Marchant
2008-05-23 19:40 ` Fabrice Marchant
@ 2008-05-23 19:42 ` Fabrice Marchant
2008-05-23 22:02 ` Till Varoquaux
2008-05-23 22:25 ` Jeremy Yallop
2 siblings, 2 replies; 9+ messages in thread
From: Fabrice Marchant @ 2008-05-23 19:42 UTC (permalink / raw)
To: caml-list
However, even if the method is clear, I run into problems trying to apply it on these 2 recursive modules :
map to sets and a set of map to sets.
module F ( X : Set.OrderedType ) = struct
module rec Mod : sig
module XSet :
sig
type elt = X.t
type t = Set.Make( X ).t
end
module XMap :
sig
type key = X.t
type 'a t = 'a Map.Make( X ).t
end
type elt = X.t
type t = XSet.t XMap.t
end
=
struct
module XSet = Set.Make( X )
module XMap = Map.Make( X )
type elt = X.t
type t = XSet.t XMap.t
end
and ModSet : Set.S with type elt = Mod.t = Set.Make( Mod )
end
Got this internal message from ocaml 3.10.1 :
"Fatal error: exception Assert_failure("typing/path.ml", 48, 22)"
Maybe should the a' type be declared (as XSet.t) ?
Any light ?
Fabrice
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [Caml-list] A functor to produce recursive modules ?
2008-05-23 22:02 ` Till Varoquaux
@ 2008-05-23 21:37 ` Fabrice Marchant
0 siblings, 0 replies; 9+ messages in thread
From: Fabrice Marchant @ 2008-05-23 21:37 UTC (permalink / raw)
To: caml-list
On Fri, 23 May 2008 23:02:06 +0100
"Till Varoquaux" <till.varoquaux@gmail.com> wrote:
> This is most definitely a bug in OCaml's type system. Ocaml is
> amazingly robust but when you start using more exotic features bugs
> occure ;-).
>
> You should fill in a bug report at:
> caml.inria.fr/mantis
Thanks, I'll try to do this sunday.
Regards,
Fabrice
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [Caml-list] A functor to produce recursive modules ?
2008-05-23 22:25 ` Jeremy Yallop
@ 2008-05-23 21:37 ` Fabrice Marchant
0 siblings, 0 replies; 9+ messages in thread
From: Fabrice Marchant @ 2008-05-23 21:37 UTC (permalink / raw)
To: caml-list
On Fri, 23 May 2008 23:25:14 +0100
Jeremy Yallop <jeremy.yallop@ed.ac.uk> wrote:
> Fabrice Marchant wrote:
> > However, even if the method is clear, I run into problems trying to
> > apply it on these 2 recursive modules : map to sets and a set of map
> > to sets.
>
> This doesn't appear to require recursive modules, since ModSet is not
> used within Mod. Except for the missing "compare" (in your version),
> it's equivalent to the following:
>
> module F ( X : Set.OrderedType ) = struct
> module Mod : sig
> module XSet :
> sig
> type elt = X.t
> type t = Set.Make( X ).t
> end
>
> module XMap :
> sig
> type key = X.t
> type 'a t = 'a Map.Make( X ).t
> end
>
> type elt = X.t
> type t = XSet.t XMap.t
> val compare : t -> t -> int
> end =
> struct
> module XSet = Set.Make( X )
> module XMap = Map.Make( X )
>
> type elt = X.t
> type t = XSet.t XMap.t
> let compare = XMap.compare XSet.compare
> end
> module ModSet : Set.S with type elt = Mod.t = Set.Make( Mod )
> end
> > Got this internal message from ocaml 3.10.1 : "Fatal error: exception
> > Assert_failure("typing/path.ml", 48, 22)"
>
> I agree with Till that you should report this bug.
>
> Jeremy.
>
Hi !
You're right. But about the lack of "compare" and use of ModSet within Mod :
I just ditched the code that was unnecessary to exhibit the naughty message.
Regards,
Fabrice
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [Caml-list] A functor to produce recursive modules ?
2008-05-23 19:42 ` Fabrice Marchant
@ 2008-05-23 22:02 ` Till Varoquaux
2008-05-23 21:37 ` Fabrice Marchant
2008-05-23 22:25 ` Jeremy Yallop
1 sibling, 1 reply; 9+ messages in thread
From: Till Varoquaux @ 2008-05-23 22:02 UTC (permalink / raw)
To: Fabrice Marchant; +Cc: caml-list
This is most definitely a bug in OCaml's type system. Ocaml is
amazingly robust but when you start using more exotic features bugs
occure ;-).
You should fill in a bug report at:
caml.inria.fr/mantis
Till
On Fri, May 23, 2008 at 8:42 PM, Fabrice Marchant
<fabrice.marchant@orange.fr> wrote:
> However, even if the method is clear, I run into problems trying to apply it on these 2 recursive modules :
> map to sets and a set of map to sets.
>
> module F ( X : Set.OrderedType ) = struct
> module rec Mod : sig
> module XSet :
> sig
> type elt = X.t
> type t = Set.Make( X ).t
> end
> module XMap :
> sig
> type key = X.t
> type 'a t = 'a Map.Make( X ).t
> end
> type elt = X.t
> type t = XSet.t XMap.t
> end
> =
> struct
> module XSet = Set.Make( X )
> module XMap = Map.Make( X )
>
> type elt = X.t
> type t = XSet.t XMap.t
> end
> and ModSet : Set.S with type elt = Mod.t = Set.Make( Mod )
> end
>
> Got this internal message from ocaml 3.10.1 :
> "Fatal error: exception Assert_failure("typing/path.ml", 48, 22)"
>
> Maybe should the a' type be declared (as XSet.t) ?
>
> Any light ?
>
> Fabrice
>
> _______________________________________________
> Caml-list mailing list. Subscription management:
> http://yquem.inria.fr/cgi-bin/mailman/listinfo/caml-list
> Archives: http://caml.inria.fr
> Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
> Bug reports: http://caml.inria.fr/bin/caml-bugs
>
--
http://till-varoquaux.blogspot.com/
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [Caml-list] A functor to produce recursive modules ?
2008-05-23 19:42 ` Fabrice Marchant
2008-05-23 22:02 ` Till Varoquaux
@ 2008-05-23 22:25 ` Jeremy Yallop
2008-05-23 21:37 ` Fabrice Marchant
1 sibling, 1 reply; 9+ messages in thread
From: Jeremy Yallop @ 2008-05-23 22:25 UTC (permalink / raw)
To: Fabrice Marchant; +Cc: caml-list
Fabrice Marchant wrote:
> However, even if the method is clear, I run into problems trying to
> apply it on these 2 recursive modules : map to sets and a set of map
> to sets.
This doesn't appear to require recursive modules, since ModSet is not
used within Mod. Except for the missing "compare" (in your version),
it's equivalent to the following:
module F ( X : Set.OrderedType ) = struct
module Mod : sig
module XSet :
sig
type elt = X.t
type t = Set.Make( X ).t
end
module XMap :
sig
type key = X.t
type 'a t = 'a Map.Make( X ).t
end
type elt = X.t
type t = XSet.t XMap.t
val compare : t -> t -> int
end =
struct
module XSet = Set.Make( X )
module XMap = Map.Make( X )
type elt = X.t
type t = XSet.t XMap.t
let compare = XMap.compare XSet.compare
end
module ModSet : Set.S with type elt = Mod.t = Set.Make( Mod )
end
> Got this internal message from ocaml 3.10.1 : "Fatal error: exception
> Assert_failure("typing/path.ml", 48, 22)"
I agree with Till that you should report this bug.
Jeremy.
^ permalink raw reply [flat|nested] 9+ messages in thread
end of thread, other threads:[~2008-05-23 23:30 UTC | newest]
Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-05-22 20:58 A functor to produce recursive modules ? Fabrice Marchant
2008-05-23 6:18 ` [Caml-list] " Alain Frisch
2008-05-23 18:00 ` Fabrice Marchant
2008-05-23 19:40 ` Fabrice Marchant
2008-05-23 19:42 ` Fabrice Marchant
2008-05-23 22:02 ` Till Varoquaux
2008-05-23 21:37 ` Fabrice Marchant
2008-05-23 22:25 ` Jeremy Yallop
2008-05-23 21:37 ` Fabrice Marchant
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox