File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11module Main where
22
33import Base
4+ import ChurchNum
45import Lib
56
67main :: IO ()
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+ -- @help: can't figure out point free version
25+ two x y = x $ x y
26+
27+ -- inc :: Num a => a -> a
28+ inc = (+ 1 )
29+
30+ -- dec :: Num a => a -> a
31+ dec x = x - 1
32+
33+ -- add :: Num a => a -> a -> a
34+ add = (+)
35+
36+ -- sub :: Num a => a -> a -> a
37+ sub = (-)
38+
39+ -- mult :: Num a => a -> a -> a
40+ mul a b = church a (+ b) 0
41+
42+ -- church :: (Eq t1, Num t1) => t1 -> (t2 -> t2) -> t2 -> t2
43+ church 0 = zero
44+ church n = \ f x -> f $ church (n - 1 ) f x
45+
46+ -- unchurch :: ((Integer -> Integer) -> Integer -> t3) -> t3
47+ unchurch = Base. flip ($ (1 + )) 0
48+
49+ -- isZero :: (Eq a, Num a) => a -> Bool
50+ isZero = (==) 0
You can’t perform that action at this time.
0 commit comments