In my codebase I have two sets of events which can be generated by two different subsystems. It would be convenient for these to be dealt with by a single function at the point where the subsystems both feed in.
So I have the two sets of variants:
type foo = [`EventA | `EventB] type bar = [`EventC]
What I want to do is to have a function who can take the union of these variants. Playing around I managed to get this code to compile:
let foobar : [foo | bar] -> unit = ...
The issue is on the application side. When I try something like:
let v : foo = ... foobar v
I get a type error: saying that
v does not have type `EventC
I can fix this by explicitly subtyping v:
(v :> [foo | bar]) however this feels like it shouldn’t be necessary and that there should be something I can do to the signature of
foobar to fix this?
(Things I’ve tried so far:
[< ... ] doesn’t seem to work in that subsequent matches on those actions loose the typing information,
[> ...] still has the same issues as
[ ... ])