Higher Order Types and Parameters
bvssvni opened this issue · comments
Sven Nilsen commented
Related to #610
A Higher Order Type is written \-> T
and accepts any type T
or a closure returning T
:
fn foo(a: \-> f64, b: \-> f64) -> \-> f64 {
return a + b
}
The \
type operator can be thought of as specifying an unknown type ("from something") defined at runtime when calling the function. The type checker reports an error if the "from something" type does not match each other for every argument.
Examples
A higher order line:
line(a: \-> vec4, b: \-> vec4, t : \-> f64) = a + (b - a) * t
A higher order quadratic bezier:
qbez(a : \-> vec4, b: \-> vec4, c: \-> vec4, t: \-> f64) =
line(line(a, b, t), line(b, c, t), t)
Sven Nilsen commented
An alternative is to write \T
instead of \-> T
.
Sven Nilsen commented
Two other alternatives are \> T
or -> T
.
Sven Nilsen commented
Closing, see #610 (comment)