Defining Variants With Constructor Arguments
type listActions =
| Length
| Nth(int);let performListAction = (l: list(int), action: listActions) => {
switch(action) {
| Length => List.length(l)
| Nth(n) => List.nth(l, n)
}
};
performListAction([7,8,9], Nth(1)); /* 8 */
performListAction([1,2,3], Length); /* 3 */Last updated