Skip to content

Commit d7344eb

Browse files
author
Thomas Mahler
committed
reverse order of if then else code
1 parent 7aaf166 commit d7344eb

File tree

5 files changed

+12
-10
lines changed

5 files changed

+12
-10
lines changed

app/Main.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ ackermann = [r|
6565
factorial :: SourceCode
6666
factorial = [r|
6767
fact = y(λf n. if (eql n 0) 1 (* n (f (- n 1))))
68-
main = fact 100
68+
main = fact 10
6969
|]
7070

7171
fibonacci :: SourceCode

src/CLTerm.hs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -82,10 +82,10 @@ toCL (m `App` n) = toCL m :@ toCL n
8282
toCL (Int i) = INT i
8383

8484
-- | Scott-encoded TRUE and FALSE using basic SKI combinators
85-
-- TRUE = λt e. t = K
86-
-- FALSE = λt e. e = A (where A is λx y. y)
85+
-- TRUE = λt e. e = A (selects second argument)
86+
-- FALSE = λt e. t = K (selects first argument)
8787
trueCL :: CL
88-
trueCL = Com K
88+
trueCL = Com A
8989

9090
falseCL :: CL
91-
falseCL = Com A
91+
falseCL = Com K

src/GraphReduction.hs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -230,10 +230,10 @@ binaryMathOp op p1 p2 = do
230230

231231
-- Helper functions to create Scott-encoded boolean Graph structures
232232
allocTrue :: ST s (STRef s (Graph s))
233-
allocTrue = newSTRef (Comb K)
233+
allocTrue = newSTRef (Comb A)
234234

235235
allocFalse :: ST s (STRef s (Graph s))
236-
allocFalse = newSTRef (Comb A)
236+
allocFalse = newSTRef (Comb K)
237237

238238
-- Binary comparison operations that return TRUE/FALSE combinators
239239
binaryCompOp ::

src/LambdaToSKI.hs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -127,10 +127,12 @@ abstractToCCC = cccAbs
127127

128128
-- | Desugar If expressions to Scott encoded boolean applications
129129
-- Detects pattern: ((if condition) thenExpr) elseExpr
130-
-- and transforms it to: condition thenExpr elseExpr
130+
-- and transforms it to: condition elseExpr thenExpr
131+
-- With TRUE=A (selects second arg) and FALSE=K (selects first arg)
132+
-- This ensures TRUE selects thenExpr and FALSE selects elseExpr
131133
desugarIf :: Expr -> Expr
132134
desugarIf (((Var "if" `App` condition) `App` thenExpr) `App` elseExpr) =
133-
(desugarIf condition `App` desugarIf thenExpr) `App` desugarIf elseExpr
135+
(desugarIf condition `App` desugarIf elseExpr) `App` desugarIf thenExpr
134136
desugarIf (App e1 e2) = App (desugarIf e1) (desugarIf e2)
135137
desugarIf (Lam x e) = Lam x (desugarIf e)
136138
desugarIf expr = expr -- Var, Int remain unchanged

test/SimpleTestSources.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ basicArithmetic = [r|
1414

1515
basicComparison :: SourceCode
1616
basicComparison = [r|
17-
expected = k
17+
expected = a
1818
main = eql 5 5
1919
|]
2020

0 commit comments

Comments
 (0)