Skip to content

unused bindings optimisations #73

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 2, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 13 additions & 13 deletions tests/basics-binary-scott/solution.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,28 +17,28 @@ Z = \ f . ( \ x . f \ y . x x y ) ( \ x . f \ y . x x y )

#import Boolean.lc

False = \ f t . f
True = \ f t . t
False = \ f _t . f
True = \ _f t . t

not = \ p . p True False
not = \ p . \ f t . p t f

and = \ p . p p
or = \ p q . p q p
xor = \ p q . p q (not q)
implies = \ p . p (True)
implies = \ p . p True

#import Ordering.lc

LT = \ lt eq gt . lt
EQ = \ lt eq gt . eq
GT = \ lt eq gt . gt
LT = \ lt _eq _gt . lt
EQ = \ _lt eq _gt . eq
GT = \ _lt _eq gt . gt

#import Pair.lc

Pair = \ x y fn . fn x y

fst = \ xy . xy \ x _ . x
snd = \ xy . xy \ _ y . y
fst = \ xy . xy \ x _y . x
snd = \ xy . xy \ _x y . y

first = \ fn xy . xy \ x . Pair (fn x)
second = \ fn xy . xy \ x y . Pair x (fn y)
Expand All @@ -48,11 +48,11 @@ curry = \ fn xy . xy fn

# data Number = End | Even Number | Odd Number

zero = \ end even odd . end
zero = \ end _even _odd . end

shiftR0 = \ n . \ end even odd . even n # mind that a shiftR in LE is a multiplication
shiftR1 = \ n . \ end even odd . odd n # mind that a shiftR in LE is a multiplication
shiftL = \ n . n n I I # mind that a shiftL in LE is a division
shiftR0 = \ n . \ _end even _odd . even n # mind that a shiftR in LE is a multiplication
shiftR1 = \ n . \ _end _even odd . odd n # mind that a shiftR in LE is a multiplication
shiftL = \ n . n n I I # mind that a shiftL in LE is a division

isStrictZero = \ n . n True (K False) (K False) # disallow padding zeroes # O(1)
isZero = \ n . n True isZero (K False) # allow padding zeroes # amortised O(2), so don't worry too much
Expand Down
6 changes: 3 additions & 3 deletions tests/is-prime-scott/solution.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ B = \ f g x . f (g x)
I = \ x . x
K = \ x _ . x
Y = \ f . ( \ x . f (x x) ) ( \ x . f (x x) )
True = \ t f . t
False = \ t f . f
Succ = \ n z s . s n
True = \ t _f . t
False = \ _t f . f
Succ = \ n _z s . s n
Pred = \ n . n 0 I
Plus = \ m n . m n (B Succ (Plus n))
Minus = \ m n . m 0 (B (n m) Minus)
Expand Down
4 changes: 2 additions & 2 deletions tests/is-prime/solution.txt
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# JohanWiltink

Y = \ f . ( \ x . f (x x) ) ( \ x . f (x x) )
True = \ t f . t
False = \ t f . f
True = \ t _f . t
False = \ _t f . f
Succ = \ n s z . s (n s z)
Pred = \ n s z . n ( \ f g . g (f s) ) (\_.z) \x.x
Minus = \ m n . n Pred m
Expand Down
30 changes: 15 additions & 15 deletions tests/prime-sieve/solution.txt
Original file line number Diff line number Diff line change
Expand Up @@ -20,23 +20,23 @@ Z = \ f . ( \ x . f \ y . x x y ) ( \ x . f \ y . x x y )

#import Ordering.lc

LT = \ lt eq gt . lt
EQ = \ lt eq gt . eq
GT = \ lt eq gt . gt
LT = \ lt _eq _gt . lt
EQ = \ _lt eq _gt . eq
GT = \ _lt _eq gt . gt

# import Booleans.lc

False = \ false true . false
True = \ false true . true
False = \ false _true . false
True = \ _false true . true

# data Number = End | Even Number | Odd Number

# zero :: Int
zero = \ end even odd . end
zero = \ end _even _odd . end

# shiftR0,shiftR1 :: Int -> Int
shiftR0 = \ n . \ end even odd . even n # mind that a shiftR in LE is a multiplication
shiftR1 = \ n . \ end even odd . odd n # mind that a shiftR in LE is a multiplication
shiftR0 = \ n . \ _end even _odd . even n # mind that a shiftR in LE is a multiplication
shiftR1 = \ n . \ _end _even odd . odd n # mind that a shiftR in LE is a multiplication

# isZero :: Int -> Bool
isZero = \ n . n True (K False) (K False)
Expand Down Expand Up @@ -84,21 +84,21 @@ minus = \ m n . gt m n zero (unpad (unsafeMinus m n)) # needs explicit unpad or
pair = \ x y . \ pair . pair x y

# fst :: Pair a b -> a
fst = \ xy . xy ( \ x y . x )
fst = \ xy . xy ( \ x _y . x )

# snd :: Pair a b -> b
snd = \ xy . xy ( \ x y . y )
snd = \ xy . xy ( \ _x y . y )

# data Stream a :: Cons a (Stream a)

# cons :: a -> Stream a -> Stream a
cons = \ x xs . \ cons . cons x xs

# head :: Stream a -> a
head = \ xs . xs ( \ x xs . x )
head = \ xs . xs ( \ x _xs . x )

# tail :: Stream a -> Stream a
tail = \ xs . xs ( \ x xs . xs )
tail = \ xs . xs ( \ _x xs . xs )

# map :: (a -> b) -> Stream a -> Stream b
map = \ fn xs . xs ( \ x xs . cons (fn x) (map fn xs) )
Expand All @@ -112,10 +112,10 @@ le = \ m n . compare (head m) (head n) True True False
# data Set a = Nil | Branch a (Set a) (Set a)

# empty :: Set a
empty = \ nil branch . nil
empty = \ nil _branch . nil

# branch :: a -> Set a -> Set a -> Set a
branch = \ x left right . \ nil branch . branch x left right
branch = \ x left right . \ _nil branch . branch x left right

# insert :: (Ord a) => a -> Set a -> Set a
insert = \ x set .
Expand All @@ -129,7 +129,7 @@ insert = \ x set .

# findMin :: (Partial) => Set a -> a
findMin = \ set . set ()
\ x left right .
\ x left _right .
left x ( \ _ _ _ . findMin left )

# minView :: (Partial) => Set a -> (a,Set a)
Expand Down