Skip to content

Commit f9be3c6

Browse files
thmathma
authored andcommitted
on the way to B', C' and S'
1 parent f5546b8 commit f9be3c6

File tree

3 files changed

+12
-4
lines changed

3 files changed

+12
-4
lines changed

app/Main.hs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff 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 ""

src/HhiReducer.hs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,14 +48,17 @@ transLink _globals (Int k) = CInt k
4848
transLink globals (Var c) = fromJust $ lookup (fromString c) globals
4949
transLink _globals l@(Lam _ _) = error $ "lambdas should be abstracted already " ++ show l
5050

51-
51+
-- | the set of primary operations: combinators + basic arithmetic functions
5252
primitives :: GlobalEnv
5353
primitives = 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 (+)

src/LambdaToSKI.hs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import Parser (Environment, Expr (..))
1717

1818
type Error = String
1919

20+
-- improved bracket abstraction according to https://tromp.github.io/cl/LC.pdf (section 3.2)
2021
babs :: Environment -> Expr -> Expr
2122
babs env (Lam x e)
2223
| Var "i" :@ _x <- t = t
@@ -77,6 +78,7 @@ opt (Var "i" :@ n@(Int _n)) = n
7778
opt ((Var "s" :@ (Var "k" :@ e1)) :@ (Var "k" :@ e2)) = Var "k" :@ (e1 :@ e2)
7879
opt ((Var "s" :@ e1) :@ (Var "k" :@ e2)) = (Var "c" :@ e1) :@ e2
7980
opt ((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"
8082
opt (x :@ y) = opt x :@ opt y
8183
opt x = x
8284

@@ -124,7 +126,7 @@ cccAbs env (Var s)
124126
cccAbs env (m :@ n) = cccAbs env m :@ cccAbs env n
125127
cccAbs _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

130132
fromString :: String -> Combinator
@@ -133,6 +135,9 @@ fromString "k" = K
133135
fromString "s" = S
134136
fromString "b" = B
135137
fromString "c" = C
138+
fromString "s'" = S'
139+
fromString "b'" = B'
140+
fromString "c'" = C'
136141
fromString "y" = Y
137142
fromString "p" = P
138143
fromString "+" = ADD

0 commit comments

Comments
 (0)