If i have two poly variants, with one extending another.
And I make a switch statement that captures the outer value
is there a natural way to pass the tail into a function that takes type inner?
The compiler complains but it seems like it should be inferred?
Yes you can do that. Use the type definition as an abbreviation in the pattern.
See playground
type inner = [#A(int) | #B(int)]
let fninner = (x: inner) => {
switch x {
| #A(i) => i
| #B(i) => i * i
}
}
type outer = [#C | inner]
let fnouter = (x: outer) => {
switch x {
| #C => 3
| #...inner as x => x->fninner
}
}
Edit: here is section from manual about this syntax
Edit 2: Fixed the link to the playground (originally it was to the OP’s playground)
4 Likes
Ahh there it is.
Thanks Ryan!
1 Like