File tree Expand file tree Collapse file tree 5 files changed +12
-10
lines changed
Expand file tree Collapse file tree 5 files changed +12
-10
lines changed Original file line number Diff line number Diff line change @@ -65,7 +65,7 @@ ackermann = [r|
6565factorial :: SourceCode
6666factorial = [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
7171fibonacci :: SourceCode
Original file line number Diff line number Diff line change @@ -82,10 +82,10 @@ toCL (m `App` n) = toCL m :@ toCL n
8282toCL (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 )
8787trueCL :: CL
88- trueCL = Com K
88+ trueCL = Com A
8989
9090falseCL :: CL
91- falseCL = Com A
91+ falseCL = Com K
Original file line number Diff line number Diff line change @@ -230,10 +230,10 @@ binaryMathOp op p1 p2 = do
230230
231231-- Helper functions to create Scott-encoded boolean Graph structures
232232allocTrue :: ST s (STRef s (Graph s ))
233- allocTrue = newSTRef (Comb K )
233+ allocTrue = newSTRef (Comb A )
234234
235235allocFalse :: 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
239239binaryCompOp ::
Original file line number Diff line number Diff 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
131133desugarIf :: Expr -> Expr
132134desugarIf (((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
134136desugarIf (App e1 e2) = App (desugarIf e1) (desugarIf e2)
135137desugarIf (Lam x e) = Lam x (desugarIf e)
136138desugarIf expr = expr -- Var, Int remain unchanged
Original file line number Diff line number Diff line change @@ -14,7 +14,7 @@ basicArithmetic = [r|
1414
1515basicComparison :: SourceCode
1616basicComparison = [r |
17- expected = k
17+ expected = a
1818 main = eql 5 5
1919|]
2020
You can’t perform that action at this time.
0 commit comments