Actually depends on what operation you will perform on your types.
The solution given by @nlucaroni is fine, but if you want to do something more general (and complicated), you can use the entry to store your partial map functions:
type 'a component_m = {
a : intC -> 'a;
b : boolC -> 'a;
c : stringC -> 'a;
}
let map_component m = function
| A a -> m.a a
| B b -> m.b b
| C c -> m.c c
let add = map_component {
a = (fun x -> Some (x + 2));
b = (fun _ -> None);
c = (fun _ -> None);
}
If you do not want to write a function every time (fun _ -> None), you can also use the default value that you extend:
let none = {
a = (fun _ -> None);
b = (fun _ -> None);
c = (fun _ -> None);
}
let add = map_component { none with a = fun x -> Some (x+2) }
, , , .