aboutsummaryrefslogtreecommitdiff
path: root/stdlib/source/lux/abstract/functor.lux
blob: a259673d46cbfbc8e783b8b8fe6fbc1c9eeb3d83 (plain)
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
(.module: lux)

(signature: #export (Functor f)
  (: (All [a b]
       (-> (-> a b)
           (-> (f a) (f b))))
     map))

(type: #export (Fix f)
  (f (Fix f)))

(type: #export (And f g)
  (All [a] (& (f a) (g a))))

(type: #export (Or f g)
  (All [a] (| (f a) (g a))))

(type: #export (Then f g)
  (All [a] (f (g a))))

(def: #export (compose (^open "f@.") (^open "g@."))
  {#.doc "Functor composition."}
  (All [F G] (-> (Functor F) (Functor G) (Functor (..Then F G))))
  (structure
   (def: (map f fga)
     (f@map (g@map f) fga))))

(signature: #export (Contravariant f)
  (: (All [a b]
       (-> (-> b a)
           (-> (f a) (f b))))
     map-1))