-
Notifications
You must be signed in to change notification settings - Fork 5
/
Function.fm
40 lines (31 loc) · 1.24 KB
/
Function.fm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
// `Function(A, (x) B(x))` is a synonym for `(x: A) -> B(x)`
Function(A: Type, B: A -> Type): Type
(x: A) -> B(x)
// Calls a function in an argument. The most useless function.
Function.call<A: Type, B: Type>(x: A, f: A -> B): B
f(x)
// Function composition.
Function.comp<A: Type, B: Type, C: Type>(g: B -> C, f: A -> B, x: A): C
g(f(x))
// Given a `x`, returns a function that receives an `y` and returns `x`.
Function.const<A: Type, B: Type>(x: A, y: B): A
x
// Converts a function that receives a pair into a function of 2 arguments.
Function.curry<A: Type, B: Type, C: Type>(f: Pair(A, B) -> C, x: A, y: B): C
f(Pair.new<A><B>(x, y))
// Dependent function composition.
Function.dcomp<A:Type, B:Type, C:B->Type>(g:(b:B)->C(b), f:A -> B, x:A): C(f(x))
g(f(x))
// Flips the two first arguments of a function.
Function.flip<A: Type, B: Type, C: Type>(f: A -> B -> C, y: B, x: A): C
f(x, y)
// The identity function returns its argument.
Function.id<A: Type>(x: A): A
x
// Function application in reverse order.
Function.pipe<A: Type, B: Type>(x: A, f: A -> B): B
f(x)
// Converts a function from 2 arguments to a function that receives a pair.
Function.uncurry<A: Type, B: Type, C: Type>(f: A -> B -> C, p: Pair(A, B)): C
get a b = p
f(a, b)