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
27
27
hSetEncoding stdout utf8 -- this is required to handle UTF-8 characters like λ
28
28
29
29
-- testSource <-readFile "test/tak.ths"
30
- let testSource = " main = (\\ x y -> x) 3 4"
30
+ let testSource = " main = (\\ x y -> + x x) 3 4"
31
31
putStrLn " The sourcecode: "
32
32
putStrLn testSource
33
33
@@ -36,7 +36,7 @@ main = do
36
36
mapM_ print env
37
37
putStrLn " "
38
38
39
- let expr = compile env babs0 -- abstractSimple -- abstractToSKI
39
+ let expr = compile env abstractToSKI
40
40
putStrLn " The main expression compiled to SICKYB combinator expressions:"
41
41
print expr
42
42
putStrLn " "
Original file line number Diff line number Diff line change @@ -48,14 +48,17 @@ transLink _globals (Int k) = CInt k
48
48
transLink globals (Var c) = fromJust $ lookup (fromString c) globals
49
49
transLink _globals l@ (Lam _ _) = error $ " lambdas should be abstracted already " ++ show l
50
50
51
-
51
+ -- | the set of primary operations: combinators + basic arithmetic functions
52
52
primitives :: GlobalEnv
53
53
primitives = let (-->) = (,) in
54
54
[ I --> CFun id
55
55
, K --> CFun (CFun . const )
56
56
, S --> CFun (\ f -> CFun $ \ g -> CFun $ \ x -> f! x! (g! x))
57
57
, B --> CFun (\ f -> CFun $ \ g -> CFun $ \ x -> f! (g! x))
58
58
, 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)
59
62
, IF --> CFun (\ (CInt cond) -> CFun $ \ thenExp -> CFun $ \ elseExp -> if cond == 1 then thenExp else elseExp)
60
63
, Y --> CFun (\ (CFun f) -> fix f)
61
64
, ADD --> arith (+)
Original file line number Diff line number Diff line change @@ -17,6 +17,7 @@ import Parser (Environment, Expr (..))
17
17
18
18
type Error = String
19
19
20
+ -- improved bracket abstraction according to https://tromp.github.io/cl/LC.pdf (section 3.2)
20
21
babs :: Environment -> Expr -> Expr
21
22
babs env (Lam x e)
22
23
| Var " i" :@ _x <- t = t
@@ -77,6 +78,7 @@ opt (Var "i" :@ n@(Int _n)) = n
77
78
opt ((Var " s" :@ (Var " k" :@ e1)) :@ (Var " k" :@ e2)) = Var " k" :@ (e1 :@ e2)
78
79
opt ((Var " s" :@ e1) :@ (Var " k" :@ e2)) = (Var " c" :@ e1) :@ e2
79
80
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"
80
82
opt (x :@ y) = opt x :@ opt y
81
83
opt x = x
82
84
@@ -124,7 +126,7 @@ cccAbs env (Var s)
124
126
cccAbs env (m :@ n) = cccAbs env m :@ cccAbs env n
125
127
cccAbs _env x = x
126
128
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'
128
130
deriving (Eq , Show )
129
131
130
132
fromString :: String -> Combinator
@@ -133,6 +135,9 @@ fromString "k" = K
133
135
fromString " s" = S
134
136
fromString " b" = B
135
137
fromString " c" = C
138
+ fromString " s'" = S'
139
+ fromString " b'" = B'
140
+ fromString " c'" = C'
136
141
fromString " y" = Y
137
142
fromString " p" = P
138
143
fromString " +" = ADD
You can’t perform that action at this time.
0 commit comments