In our app we have a need for a possible extension of module types using a functor. In this module, we have a “default” version of this poly variant.
With the help of this “default” and the lower bounds constraint, we define a “minimal” type.
We also define a functor and the type of this functor’s arguments.
And finally, we want to extend these minimal poly variant s via passing a set of “extension” poly variants.
To give you a better idea of what we are trying, here’s a short snippet that demonstrates our set-up and issue
module Color = {
type composite<'t> = {colors: 't}
type defaultColor = [#Red | #Green | #Blue]
type otherColor<'t> = [
| #combined(composite<'t>)
| #otherCombined(composite<'t>)
]
type minimalColor<'a> = [> defaultColor] as 'a
type rec default = [defaultColor | otherColor<default>]
module type Config = {
// Should require at least `defaultColor` to be passed to our `Make` functor
type extension = minimalColor<defaultColor>
}
module Make = (Config: Config) => {
type color = [defaultColor | Config.extension]
type rec t = [color | default]
}
}
module Impl = {
include Color.Make({
/*
Signature mismatch:
...
Type declarations do not match:
type rec extension = [#Ext1 | #Ext2]
is not included in
type rec extension = Color.minimalColor<Color.defaultColor>
File "playground.res", line 16, characters 3-47: Expected declaration
File "playground.res", line 29, characters 4-36: Actual declaration
*/
type extension = [#Ext1 | #Ext2]
})
}
Or here’s the same code in a simple playground.
Any and all advice are very welcome!