PistonDevelopers / dyon

A rusty dynamically typed scripting language

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Higher Order Types and Parameters

bvssvni opened this issue · comments

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)

An alternative is to write \T instead of \-> T.

Two other alternatives are \> T or -> T.

Closing, see #610 (comment)