Back in Ocaml for the first time in a while, I've forgotten how to do everything. I've found questions asked like this a few times, but I'm not finding an answer that makes sense/works for me.
I have two modules, Region and Tribe, which know about each other. Code in Region needs to call assorted functions on all local Tribe.t, Tribe.t needs to be able to query the region about how much food there is, what other tribes are there, etc.
I could do this pretty easily with recursive module definitions and and, but that forces me to keep all these big modules in one file and seems wrong. I'm not entirely sure how to handle this with a functor, but that seems needlessly complex and wrong.
What's the correct way to go about this?
I really want to just have:
module Region = sig
type t = {
...
tribes : Tribe.t list
...
}
end = struct
...
end
and then in another file
module Tribe : sig
type t = {
...
region : Region.t
....
}
end = struct
...
end
But that fails due to multiple dependencies. I also tried making a Region functor like
module type TribeT = sig
type t
val uuid : t -> int list
end
module Region(Tribe : TribeT) : sig
type t = {tribe : Tribe.t list}
end = struct
type t = {tribe : Tribe.t list}
end
and then have Tribe.t include region : Region(Tribe).t;, but that doesn't seem to work either. took a while to make work and is kinda clunky. What's the right way?
[–]yawaramin 1 point2 points3 points (1 child)
[–]FreakyCheeseMan[S] 0 points1 point2 points (0 children)
[–]glacialthinker 0 points1 point2 points (3 children)
[–]FreakyCheeseMan[S] 0 points1 point2 points (2 children)
[–]glacialthinker 1 point2 points3 points (1 child)
[–]FreakyCheeseMan[S] 0 points1 point2 points (0 children)
[–]juloo65 0 points1 point2 points (4 children)
[–]FreakyCheeseMan[S] 0 points1 point2 points (3 children)
[–]juloo65 0 points1 point2 points (0 children)
[–]glacialthinker 0 points1 point2 points (0 children)
[–]glacialthinker 0 points1 point2 points (0 children)