I am trying to share types between functor arguments like the following code. What’s a good way to do this?
module MyFilter = {
module type Filter = {
type filterType;
type state = {data: filterType};
let toString: filterType => string;
};
type colorFilter =
| Yellow
| Red
module RedFilter: Filter = {
type filterType=colorFilter;
type state = {data: filterType};
let toString = (color: filterType) => "Red";
};
module YellowFilter: Filter = {
type filterType=colorFilter;
type state = {data: filterType};
let toString = (color: filterType) => "Yellow";
};
};
let yellow: MyFilter.colorFilter = Yellow;
let red: MyFilter.colorFilter = Red;
MyFilter.YellowFilter.toString(yellow);
MyFilter.RedFilter.toString(red);
The code generates an error:
We've found a bug for you!
OCaml preview 32:40-45
This has type:
MyFilter.colorFilter
But somewhere wanted:
MyFilter.YellowFilter.filterType
Here’s the code in the playground: