When using a functor from another file-module it’s just a function call - the behavior I want. But I can’t move it to another file-module because it depends on the types from the first.
Do you have any suggestions/hacks on what to do in the situation?
I’m not aware of any technique to influence the compiler, but would you be able to move the big function to its own module and pass the values you need as arguments with generic types? For example:
module Kind = {
let bigFunction = (make: () => 'a, use: 'a => string) => {
Js.log("Imagine a lot of code instead of this Js.log")
make()->use
}
}
module MakeSmth = (
Details: {
type t
let make: () => t
let use: t => string
},
) => {
let bigFunction = () => Kind.bigFunction(Details.make, Details.use)
}
module Cat = MakeSmth({
type t = string
let make = () => "cat"
let use = value => value
})
module Dog = MakeSmth({
type t = int
let make = () => 123
let use = value => Belt.Int.toString(value)
})
The problem is that functor still requires the types from the module where it’s used that causes dependencies cycle. I’m thinking to move all the shared types to another file-module to resolve this, but I wasn’t able to do it after the first try. Although it looks like it’s the right way to go.
I never used this functionality of the language before, and not sure what the downsides might be, but it seems that if you use a regular function with module/unpack instead of a functor, the inlining does not occur: