File tree Expand file tree Collapse file tree 3 files changed +12
-4
lines changed Expand file tree Collapse file tree 3 files changed +12
-4
lines changed Original file line number Diff line number Diff line change @@ -27,7 +27,7 @@ main = do
2727 hSetEncoding stdout utf8 -- this is required to handle UTF-8 characters like λ
2828
2929 -- testSource <-readFile "test/tak.ths"
30- let testSource = " main = (\\ x y -> x) 3 4"
30+ let testSource = " main = (\\ x y -> + x x) 3 4"
3131 putStrLn " The sourcecode: "
3232 putStrLn testSource
3333
@@ -36,7 +36,7 @@ main = do
3636 mapM_ print env
3737 putStrLn " "
3838
39- let expr = compile env babs0 -- abstractSimple -- abstractToSKI
39+ let expr = compile env abstractToSKI
4040 putStrLn " The main expression compiled to SICKYB combinator expressions:"
4141 print expr
4242 putStrLn " "
Original file line number Diff line number Diff line change @@ -48,14 +48,17 @@ transLink _globals (Int k) = CInt k
4848transLink globals (Var c) = fromJust $ lookup (fromString c) globals
4949transLink _globals l@ (Lam _ _) = error $ " lambdas should be abstracted already " ++ show l
5050
51-
51+ -- | the set of primary operations: combinators + basic arithmetic functions
5252primitives :: GlobalEnv
5353primitives = let (-->) = (,) in
5454 [ I --> CFun id
5555 , K --> CFun (CFun . const )
5656 , S --> CFun (\ f -> CFun $ \ g -> CFun $ \ x -> f! x! (g! x))
5757 , B --> CFun (\ f -> CFun $ \ g -> CFun $ \ x -> f! (g! x))
5858 , C --> CFun (\ f -> CFun $ \ g -> CFun $ \ x -> f! x! g)
59+ , B' --> CFun (\ p -> CFun $ \ q -> CFun $ \ r -> CFun $ \ s -> p! q! (r! s)) -- B' P Q R S = P Q (R S)
60+ , C' --> CFun (\ p -> CFun $ \ q -> CFun $ \ r -> CFun $ \ s -> p! (q! s)! r) -- C' P Q R S = P (Q S) R
61+ , S' --> CFun (\ p -> CFun $ \ q -> CFun $ \ r -> CFun $ \ s -> p! (q! s)! (r! s)) -- S' P Q R S = P (Q S) (R S)
5962 , IF --> CFun (\ (CInt cond) -> CFun $ \ thenExp -> CFun $ \ elseExp -> if cond == 1 then thenExp else elseExp)
6063 , Y --> CFun (\ (CFun f) -> fix f)
6164 , ADD --> arith (+)
Original file line number Diff line number Diff line change @@ -17,6 +17,7 @@ import Parser (Environment, Expr (..))
1717
1818type Error = String
1919
20+ -- improved bracket abstraction according to https://tromp.github.io/cl/LC.pdf (section 3.2)
2021babs :: Environment -> Expr -> Expr
2122babs env (Lam x e)
2223 | Var " i" :@ _x <- t = t
@@ -77,6 +78,7 @@ opt (Var "i" :@ n@(Int _n)) = n
7778opt ((Var " s" :@ (Var " k" :@ e1)) :@ (Var " k" :@ e2)) = Var " k" :@ (e1 :@ e2)
7879opt ((Var " s" :@ e1) :@ (Var " k" :@ e2)) = (Var " c" :@ e1) :@ e2
7980opt ((Var " s" :@ (Var " k" :@ e1)) :@ e2) = (Var " b" :@ e1) :@ e2
81+ opt ((Var " s" :@ ((Var " b" :@ Var " p" ) :@ Var " q" )) :@ Var " r" ) = ((Var " s1" :@ Var " p" ) :@ Var " q" ) :@ Var " r"
8082opt (x :@ y) = opt x :@ opt y
8183opt x = x
8284
@@ -124,7 +126,7 @@ cccAbs env (Var s)
124126cccAbs env (m :@ n) = cccAbs env m :@ cccAbs env n
125127cccAbs _env x = x
126128
127- data Combinator = I | K | S | B | C | Y | P | ADD | SUB | MUL | DIV | REM | SUB1 | EQL | GEQ | ZEROP | IF
129+ data Combinator = I | K | S | B | C | Y | P | ADD | SUB | MUL | DIV | REM | SUB1 | EQL | GEQ | ZEROP | IF | B' | C' | S'
128130 deriving (Eq , Show )
129131
130132fromString :: String -> Combinator
@@ -133,6 +135,9 @@ fromString "k" = K
133135fromString " s" = S
134136fromString " b" = B
135137fromString " c" = C
138+ fromString " s'" = S'
139+ fromString " b'" = B'
140+ fromString " c'" = C'
136141fromString " y" = Y
137142fromString " p" = P
138143fromString " +" = ADD
You can’t perform that action at this time.
0 commit comments