@not-rusty We can solve this by creating a module type that can be both IDb and ILog and using that in execSomething. The solution will look like this
// Creating a type that can be both IDb and ILog
module type IDbLog = {
include IDb
include ILog
}
// Getting `IDbLog` as input
let execSomething = (module(Env: IDbLog)) => {
let _user = Db.fetchUser(module(Env), "user patata")
Log.debug(module(Env), "User: what")
}
I think that’s the standard approach, but I was curious if there was a way to make the compiler infer the module dependencies, that’s why I used first class modules.
The nice thing in the F# article is that you can do something like this:
let foo env = // env :> IDb and env :> ILog
let user = Db.fetchUser env 123 // env :> IDb
Log.debug env "User: %A" user // env :> ILog
And be properly inferred. I’m probably overcomplicating dependency injection, but that pattern in F# was nice. I probably could try something with open objects, but that’s overcomplicating the issue.