nojaf
August 14, 2024, 8:29pm
1
Hello,
I would need to create bindings for recursive types, but I want the types to be in a separate module:
module Foo = {
module A = {
type t = {b: B.t} // Gives error
}
module B = {
type t = {a: A.t}
}
}
Can I do this in ReScript? If not, how to work around this?
fham
August 14, 2024, 8:58pm
2
Modules can be recursive as well, but then you need to give them explicit module type definitions:
module Foo = {
module rec A: {
type t = {b: B.t}
} = {
type t = {b: B.t}
}
and B: {
type t = {a: A.t}
} = {
type t = {a: A.t}
}
}
3 Likes
nojaf
August 14, 2024, 9:03pm
3
Thanks, I gave up and went for @get
instead:
module Foo = {
type a
type b
module A = {
@get
external b: a => b = "b"
}
module B = {
@get
external a: b => b = "a"
}
}
let a: Foo.a = %raw(`{}`)
let b = a->Foo.A.b
1 Like