[Alice-users] Functors that return environments with Functors
Chris Rathman
chrisr at virtualcommitment.com
Sun Jun 26 22:54:55 CEST 2005
Was trying to do some stuff with Functors related to bundling operations
around state. Can't seem to do what I want to do but since it's still an
idea that's not firm, I thought I'd simplify the source of the problem. The
three examples use a module that sent to or returned from various functors
in the examples:
signature T =
sig
type t
val s : t list
end
Nothing too involved. Just want to see that I can pass a type as well as a
value. Alice ML does allow me to return a functor via a functor along the
lines of:
(* This compiles fine *)
functor Dummy0 () : T =
struct
type t = int
val s = nil
end
functor F0 (structure AType : T) =
struct
type t = AType.t
val x = AType.s
functor Fx () = Dummy0()
end
Having a taste of this feature, I thought I'd go about the next logical step
and start passing around a module within the returned functor. I'm not sure
why the compiler is complaining here? All I'm trying to do is directly
passing the same module I got passed within the parent functor.
(* This gives me an error:
module expression does not match functor parameter
signature:
structure BType
is missing
*)
functor Dummy1 (structure BType : T) : T =
struct
type t = BType.t
val s = BType.s
end
functor F1 (structure CType : T) =
struct
type t = CType.t
val x = CType.s
functor Fy () = Dummy1(CType)
end
Well, having come to a dead end on passing around modules, I stripped down
to the bone the feature that I was really want to get to - self referring
functors. But it seems that Functors can't be recursive called (if that's
the proper term for the effect that I'm trying to do here.
(* This gives me an error:
unknown structure or functor `F2'
*)
functor F2 () =
struct
type t = int
val x = 1234::nil
(* functor Fz () = F2() *)
end
So what I really wanted to do was have a Functor that is passed a module as
in the second example, and have it return another functor that modifies that
environment as a module parameter to itself. Kind of a Declarative Functor
if you will.
So, am I just trying to abuse the notion of Functors? Or is there a way
around these two errors?
Thanks
Chris Rathman
More information about the alice-users
mailing list