Hello all!
Huge fan of this wonderful programming language so far. I absolutely love it.
I do have a couple questions about the optimal path forward on a couple of module-related issues - please excuse me if these are considered trivial. I don’t have prior OCaml experience so my grasp on modules in general is going to be lower than some other peoples’. Here are the issues I’m having:
- Multiple files under one module
Is it possible to spread out a module across files without using something like include ...? I’d love the ability to do this:
ParentModule/
| SubModule.res
| AnotherOne.res
And then access things like ParentModule.SubModule.foo.
- “Bare minimum” interface functionality
I’d really like to be able to enforce a minimum compliance for modules using a module type, but still allow for any types/functions defined that are defined in said module that are “extra” (with respect to the module type) still be publicly accessible/exported. Is this possible? This is what I’m referring to:
module type Foo = {
type t = string
}
module Bar: Foo = {
type t = string
// "extra" functionality
let baz = x => x + 2
}
Bar.baz(4)->ignore
// ERROR: can't find Bar.baz
Is this simply just considered an anti-pattern in ReScript? Would it be recommended to always use the interface on a minimum-compliance submodule like so:
module type Foo = {
type t = string
}
module Bar = {
module Spec: Foo = {
type t = string
}
// "extra" functionality
let baz = x => x + 2
}
Bar.baz(4)->ignore
I would really appreciate any help navigating these questions. It’s entirely possible I’m just reaching for the wrong tool - so just let me know. Thank you all in advance. This is a truly wonderful programming language and I’m so very excited to use it!