This seems like this should work, but let me give an example
I'm building a little constraint solver library, and I defined multiple constraint types, Unary, Binary, and Nary for how many variables it operates on.
pub type Constraint(a) {
Unary(fn(a) -> Bool)
Binary(fn(a, a) -> Bool)
Nary(fn(List(a)) -> Bool)
}
// the commented signature feels like it should be possible
// the function only ever returns a Unary constraint
// Why would you ever have to pattern match on the return since you know which variant it is?
// fn is_even() -> Constraint(Int).Unary {
pub fn is_even() -> Constraint(Int) {
Unary(fn(x: Int) -> Bool { x % 2 == 0 })
}
This seems like it would be an expressive construct, but I bet there are complications that make it weird or not possible that I'm not thinking of. Or maybe there is a more accurate way to express what I want