-
Notifications
You must be signed in to change notification settings - Fork 44
/
Term.hs
39 lines (32 loc) · 1.03 KB
/
Term.hs
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
module Simplicity.Term
( Category, iden, comp, (>>>), (&&&)
, Core, unit, injl, injr, match, pair, take, drop
) where
import Control.Category (Category, (>>>))
import qualified Control.Category as Cat
import Prelude hiding (take, drop)
-- same precidence as in Control.Arrow.
infixr 3 &&&
iden :: Category term => term a a
iden = Cat.id
comp :: Category term => term a b -> term b c -> term a c
comp = (>>>)
class Category term => Core term where
unit :: term a ()
injl :: term a b -> term a (Either b c)
injr :: term a c -> term a (Either b c)
match :: term (a, c) d -> term (b, c) d -> term (Either a b, c) d
pair :: term a b -> term a c -> term a (b, c)
take :: term a c -> term (a, b) c
drop :: term b c -> term (a, b) c
(&&&) :: Core term => term a b -> term a c -> term a (b, c)
(&&&) = pair
instance Core (->) where
unit = const ()
injl t a = Left (t a)
injr t a = Right (t a)
match s _ (Left a, c) = s (a, c)
match _ t (Right b, c) = t (b, c)
pair s t a = (s a, t a)
take t (a, _) = t a
drop t (_, b) = t b