I am trying to build a sequence of recursive modules in ocaml. Here is a minimally simple example:
module rec Foo : sig
type t =
| A of int
| B of Foo.t
end = struct
type t =
| A of int
| B of Foo.t
end
module rec Bar : sig
open Foo
type map_t = int -> Foo.t
type t = { foo : map_t }
val bar_of_foo : Foo.t -> t
end = struct
open Foo
let rec bar_of_foo f = match f with
| A a -> let ff (_:int) = a in
{ Bar.foo = ff }
| B b -> { foo = bar_of_foo b.foo }
end
Compilation fails in function bar_of_foo, in the match of A, with Error: unbound type constructor f.
I don't understand why this is happening - field foo is defined as having type map_t = int -> Foo.t, and f has signature int -> Foo.t.
I've also tried simply referring to record field foo as foo rather than Bar.foo (in the match case for B - that gives me an Errror: unbound record field foo error).
Any pointers or advice gratefully received.
Steve
f(the outermostfbeing a parameter tobar_of_foo) has signatureint -> int, since it usesa : intas its return value. I think it's a good idea to remove the name clash. (2) I fail to see recursive dependencies betweenFooandBar. I just see thatBarusesFoo, but not the other way around. - Anton Trunovbar_of_foo. The first line: ` | A a -> let ff (_:int) = a in { Bar.foo = ff }` starts by matching with typeA( =Foo.A). And, the type ofFoo.Aisint. So I understand why the signature offfisint -> int. But A is one of the variants ofFoo.t, so why canbar_of_foonot have signatureFoo.t -> int? - Steve Gooberman-Hill