Skip to content

Commit b816b9d

Browse files
committed
Add curhnum
import churnNum import churnNum
1 parent 1cc5805 commit b816b9d

3 files changed

Lines changed: 52 additions & 0 deletions

File tree

app/Main.hs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
module Main where
22

33
import Base
4+
import ChurchNum
45
import Lib
56

67
main :: IO ()

src/Base.hs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
{-# LANGUAGE NoImplicitPrelude #-}
12
module Base (
23
identity,
34
constant,

src/ChurchNum.hs

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
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

0 commit comments

Comments
 (0)