Sketch of design requirements for a Provider use case #37
jonahbeckford
started this conversation in
General
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Transferred from #14
Context: I'm considering using Provider in DkCoder. The main simplifier is that I have structural information from codept about all the modules, module types and functors in a project. Another simplifier is that I can and do inject modules aliases on the top of each
.ml
script (like a PPX but with awareness of the whole project).One of the last features to implement is conditional modules. For example, having
MyGame_DirectXBackend.ml
compile only on Windows andMyGame_MetalBackend.ml
compile on macOS. And when it does compile, I'd want to pass theMyGame_DirectXBackend
module a Windows DirectX implementation module andMyGame_MetalBackend.ml
an Apple Metal framework module. Basically, do the wiring on behalf of the developer (similar to Spring wiring in Java programs).I have an initial design based on matching functor parameter types (ex.
module Make (Mtl: REQUIRES_APPLE_METAL) = struct let device = Mtl.createSystemDefaultDevice() end
) with one or more corresponding module implementations (ex.module Provides_APPLE_METAL () = struct ... end
).When I get to finalizing the design next year, I might switch to use your Provider implementation. But one big difference is I can only take advantage of module/module type information (ex. the
Provider
andReader
modules were accessed in moduleabc.ml
) rather than value/type information (ex.[> reader ] Provider.package
is an argument to a function). I think I'd have to provide a high-level wrapper aroundProvider.lookup
to perform lookups on a global Provider (or a Provider that I inject into each.ml
script).Anyway, that is my thoughts for now. I probably will ask more questions next year. But I'm open to suggestions before that.
Beta Was this translation helpful? Give feedback.
All reactions