File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ {-# LANGUAGE NoImplicitPrelude #-}
12module Base (
23 identity ,
34 constant ,
Original file line number Diff line number Diff line change 1+ module ChurchNum (
2+ zero , -- point free
3+ one , -- point free
4+ two , -- point free
5+ inc , -- point free
6+ dec ,
7+ add ,
8+ sub ,
9+ mul , -- point free
10+ church ,
11+ unchurch ,-- point free
12+ isZero
13+ ) where
14+
15+ import Base
16+
17+ -- zero :: p2 -> t3 -> t3
18+ zero = Base. flip constant
19+
20+ -- one :: (t1 -> t2) -> t1 -> t2
21+ one = apply
22+
23+ -- two :: (t -> t) -> t -> t
24+ two x y = x $ x y
25+
26+ -- inc :: Num a => a -> a
27+ inc = (+ 1 )
28+
29+ -- dec :: Num a => a -> a
30+ dec x = x - 1
31+
32+ -- add :: Num a => a -> a -> a
33+ add = (+)
34+
35+ -- sub :: Num a => a -> a -> a
36+ sub = (-)
37+
38+ -- mult :: Num a => a -> a -> a
39+ mul a b = church a (+ b) 0
40+
41+ -- church :: (Eq t1, Num t1) => t1 -> (t2 -> t2) -> t2 -> t2
42+ church 0 = zero
43+ church n = \ f x -> f $ church (n - 1 ) f x
44+
45+ -- unchurch :: ((Integer -> Integer) -> Integer -> t3) -> t3
46+ unchurch = Base. flip ($ (1 + )) 0
47+
48+ -- isZero :: (Eq a, Num a) => a -> Bool
49+ isZero = (==) 0
You can’t perform that action at this time.
0 commit comments