-
Notifications
You must be signed in to change notification settings - Fork 5
/
Functor.fm
27 lines (24 loc) · 966 Bytes
/
Functor.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
T Functor<F: Type -> Type>
| Functor.new(
map: <A: Type, B: Type> -> (A -> B) -> F(A) -> F(B)
);
Functor.map<F: Type -> Type>(f: Functor(F)): <A: Type, B: Type> -> (A -> B) -> F(A) -> F(B)
case f:
| f.map;
Functor.const<F: Type -> Type>(f: Functor(F)): <A: Type, B: Type> -> A -> F(B) -> F(A)
<A, B> (a)
Functor.map<>(f)<,>(Function.const<,>(a))
// VerifiedFunctor is a Functor
// with map satisfying the functor laws
// map id == id
// map (f . g) == map f . map g
T VerifiedFunctor<F: Type -> Type, f: Functor(F)>
| VerifiedFunctor.new(
id: <A: Type> ->
(fa: F(A)) -> Equal(F(A), Functor.map<F>(f)<A, A>(Function.id<A>, fa), Function.id<F(A)>(fa)),
comp: <A: Type, B: Type, C: Type> ->
(fa: F(A)) -> (g: B -> C) -> (h: A -> B) ->
Equal(F(C),
Functor.map<F>(f)<A, C>(Function.comp<A, B, C>(g, h), fa),
Function.comp<F(A), F(B), F(C)>(Functor.map<F>(f)<B, C>(g), Functor.map<F>(f)<A, B>(h))(fa))
);