diff options
author | Péter Diviánszky <divipp@gmail.com> | 2016-06-03 14:48:43 +0200 |
---|---|---|
committer | Péter Diviánszky <divipp@gmail.com> | 2016-06-03 14:48:43 +0200 |
commit | fd11435229b4d763ac6c152e72f00331fc9df2aa (patch) | |
tree | 19d271681576dbab0aa6a98059aad46fc2a8c2a2 /prototypes | |
parent | e1609eb67ec130790a34bfcbabe02c279aa08dda (diff) |
use varname preference
Diffstat (limited to 'prototypes')
-rw-r--r-- | prototypes/LamMachine.hs | 84 |
1 files changed, 42 insertions, 42 deletions
diff --git a/prototypes/LamMachine.hs b/prototypes/LamMachine.hs index 1cdbd20b..4d30a927 100644 --- a/prototypes/LamMachine.hs +++ b/prototypes/LamMachine.hs | |||
@@ -30,7 +30,7 @@ import FreeVars | |||
30 | data Exp_ | 30 | data Exp_ |
31 | = Var_ | 31 | = Var_ |
32 | | Int_ !Int -- ~ constructor with 0 args | 32 | | Int_ !Int -- ~ constructor with 0 args |
33 | | Lam_ !Exp | 33 | | Lam_ String{-for pretty print-} !Exp |
34 | | Op1_ !Op1 !Exp | 34 | | Op1_ !Op1 !Exp |
35 | | Con_ String{-for pretty print-} !Int [Exp] | 35 | | Con_ String{-for pretty print-} !Int [Exp] |
36 | | Case_ [String]{-for pretty print-} !Exp ![Exp] -- TODO: simplify? | 36 | | Case_ [String]{-for pretty print-} !Exp ![Exp] -- TODO: simplify? |
@@ -48,8 +48,8 @@ data Exp = Exp_ !FV !Exp_ | |||
48 | deriving (Eq, Show) | 48 | deriving (Eq, Show) |
49 | 49 | ||
50 | data EnvPiece | 50 | data EnvPiece |
51 | = ELet !Exp | 51 | = ELet String{-for pretty print-} !Exp |
52 | | EDLet1 !DExp | 52 | | EDLet1 String{-for pretty print-} !DExp |
53 | | ECase_ !FV ![String] ![Exp] | 53 | | ECase_ !FV ![String] ![Exp] |
54 | | EOp2_1 !Op2 !Exp | 54 | | EOp2_1 !Op2 !Exp |
55 | | EOp2_2 !Op2 !Exp | 55 | | EOp2_2 !Op2 !Exp |
@@ -81,16 +81,16 @@ pattern EnvPiece sfv p <- (getEnvPiece -> (sfv, p)) | |||
81 | EOp2_1 op e -> EOp2_1 op (uppS sfv e) | 81 | EOp2_1 op e -> EOp2_1 op (uppS sfv e) |
82 | EOp2_2 op e -> EOp2_2 op (uppS sfv e) | 82 | EOp2_2 op e -> EOp2_2 op (uppS sfv e) |
83 | ECase_ u s es -> ECase_ (expand u' u) s es | 83 | ECase_ u s es -> ECase_ (expand u' u) s es |
84 | ELet (Exp_ u e) -> ELet (Exp_ (sDrop 1 u' `expand` u) e) | 84 | ELet n (Exp_ u e) -> ELet n (Exp_ (sDrop 1 u' `expand` u) e) |
85 | EDLet1 z -> EDLet1 $ uppDE u' 1 z | 85 | EDLet1 n z -> EDLet1 n $ uppDE u' 1 z |
86 | 86 | ||
87 | getEnvPiece = \case | 87 | getEnvPiece = \case |
88 | EOp2_1 op (Exp_ u e) -> (SFV 0 u, EOp2_1 op (Exp_ (selfContract u) e)) | 88 | EOp2_1 op (Exp_ u e) -> (SFV 0 u, EOp2_1 op (Exp_ (selfContract u) e)) |
89 | EOp2_2 op (Exp_ u e) -> (SFV 0 u, EOp2_2 op (Exp_ (selfContract u) e)) | 89 | EOp2_2 op (Exp_ u e) -> (SFV 0 u, EOp2_2 op (Exp_ (selfContract u) e)) |
90 | ECase_ u s es -> (SFV 0 u, ECase_ (selfContract u) s es) | 90 | ECase_ u s es -> (SFV 0 u, ECase_ (selfContract u) s es) |
91 | ELet (Exp_ u e) -> (SFV 1 $ fv 1 0 u, ELet $ Exp_ (selfContract u) e) | 91 | ELet n (Exp_ u e) -> (SFV 1 $ fv 1 0 u, ELet n $ Exp_ (selfContract u) e) |
92 | EDLet1 DExpNil -> (mempty, EDLet1 DExpNil) | 92 | EDLet1 n DExpNil -> (mempty, EDLet1 n DExpNil) |
93 | EDLet1 (DExpCons_ u x y) -> (SFV 0 $ sDrop 1 u, EDLet1 $ DExpCons_ (onTail selfContract 1 u) x y) | 93 | EDLet1 n (DExpCons_ u x y) -> (SFV 0 $ sDrop 1 u, EDLet1 n $ DExpCons_ (onTail selfContract 1 u) x y) |
94 | 94 | ||
95 | uppS (SFV _ x) (Exp_ u a) = Exp_ (expand x u) a | 95 | uppS (SFV _ x) (Exp_ u a) = Exp_ (expand x u) a |
96 | 96 | ||
@@ -98,7 +98,7 @@ pattern DExpCons :: EnvPiece -> DExp -> DExp | |||
98 | pattern DExpCons a b <- (getDExpCons -> (a, b)) | 98 | pattern DExpCons a b <- (getDExpCons -> (a, b)) |
99 | where DExpCons (EnvPiece ux a) DExpNil = DExpCons_ (fromSFV s) (EnvPiece ux' a) DExpNil | 99 | where DExpCons (EnvPiece ux a) DExpNil = DExpCons_ (fromSFV s) (EnvPiece ux' a) DExpNil |
100 | where (s, D1 ux') = diffT $ D1 ux | 100 | where (s, D1 ux') = diffT $ D1 ux |
101 | DExpCons (ELet a) (dDown 0 -> Just d) = d | 101 | DExpCons (ELet _ a) (dDown 0 -> Just d) = d |
102 | DExpCons (EnvPiece ux a) (DExpCons_ u x y) = DExpCons_ (fromSFV s) (EnvPiece ux' a) (DExpCons_ u' x y) | 102 | DExpCons (EnvPiece ux a) (DExpCons_ u x y) = DExpCons_ (fromSFV s) (EnvPiece ux' a) (DExpCons_ u' x y) |
103 | where (s, D2 (SFV 0 u') ux') = diffT $ D2 (SFV 0 u) ux | 103 | where (s, D2 (SFV 0 u') ux') = diffT $ D2 (SFV 0 u) ux |
104 | 104 | ||
@@ -127,16 +127,16 @@ pattern Op1 op a <- Exp_ u (Op1_ op (upp u -> a)) | |||
127 | where Op1 op (Exp_ ab x) = Exp_ ab $ Op1_ op $ Exp_ (selfContract ab) x | 127 | where Op1 op (Exp_ ab x) = Exp_ ab $ Op1_ op $ Exp_ (selfContract ab) x |
128 | pattern Var' i = Exp_ (VarFV i) Var_ | 128 | pattern Var' i = Exp_ (VarFV i) Var_ |
129 | pattern Var i = Var' i | 129 | pattern Var i = Var' i |
130 | pattern Lam i <- Exp_ u (Lam_ (upp (incFV u) -> i)) | 130 | pattern Lam n i <- Exp_ u (Lam_ n (upp (incFV u) -> i)) |
131 | where Lam (Exp_ vs ax) = Exp_ (sDrop 1 vs) $ Lam_ $ Exp_ (compact vs) ax | 131 | where Lam n (Exp_ vs ax) = Exp_ (sDrop 1 vs) $ Lam_ n $ Exp_ (compact vs) ax |
132 | pattern Con a b i <- Exp_ u (Con_ a b (map (upp u) -> i)) | 132 | pattern Con a b i <- Exp_ u (Con_ a b (map (upp u) -> i)) |
133 | where Con a b x = Exp_ s $ Con_ a b bz where (s, bz) = deltas x | 133 | where Con a b x = Exp_ s $ Con_ a b bz where (s, bz) = deltas x |
134 | pattern Case a b c <- Exp_ u (Case_ a (upp u -> b) (map (upp u) -> c)) | 134 | pattern Case a b c <- Exp_ u (Case_ a (upp u -> b) (map (upp u) -> c)) |
135 | where Case cn a b = Exp_ s $ Case_ cn az bz where (s, az: bz) = deltas $ a: b | 135 | where Case cn a b = Exp_ s $ Case_ cn az bz where (s, az: bz) = deltas $ a: b |
136 | 136 | ||
137 | pattern Let i x <- App (Lam x) i | 137 | pattern Let n i x <- App (Lam n x) i |
138 | where Let i (down 0 -> Just x) = x | 138 | where Let _ i (down 0 -> Just x) = x |
139 | Let i x = App (Lam x) i | 139 | Let n i x = App (Lam n x) i |
140 | 140 | ||
141 | pattern InHNF a <- (getHNF -> Just a) | 141 | pattern InHNF a <- (getHNF -> Just a) |
142 | where InHNF a@Int{} = a | 142 | where InHNF a@Int{} = a |
@@ -212,7 +212,7 @@ type GenSteps e | |||
212 | 212 | ||
213 | type StepTag = String | 213 | type StepTag = String |
214 | 214 | ||
215 | focusNotUsed (MSt (EDLet1 x `DEnvCons` _) _) = not $ usedVar' 0 x | 215 | focusNotUsed (MSt (EDLet1 _ x `DEnvCons` _) _) = not $ usedVar' 0 x |
216 | focusNotUsed _ = True | 216 | focusNotUsed _ = True |
217 | 217 | ||
218 | steps :: forall e . Int -> GenSteps e | 218 | steps :: forall e . Int -> GenSteps e |
@@ -220,7 +220,7 @@ steps lev nostep bind cont (MSt vs e) = case e of | |||
220 | 220 | ||
221 | Con cn i xs | 221 | Con cn i xs |
222 | | lz == 0 || focusNotUsed (MSt vs e) -> step "con hnf" $ MSt vs $ InHNF e | 222 | | lz == 0 || focusNotUsed (MSt vs e) -> step "con hnf" $ MSt vs $ InHNF e |
223 | | otherwise -> step "copy con" $ MSt (foldr DEnvCons vs $ ELet <$> zs) $ InHNF $ Con cn i xs' -- share complex constructor arguments | 223 | | otherwise -> step "copy con" $ MSt (foldr DEnvCons vs $ ELet "" <$> zs) $ InHNF $ Con cn i xs' -- share complex constructor arguments |
224 | where | 224 | where |
225 | lz = Nat $ length zs | 225 | lz = Nat $ length zs |
226 | (xs', concat -> zs) = unzip $ f 0 xs | 226 | (xs', concat -> zs) = unzip $ f 0 xs |
@@ -240,8 +240,8 @@ steps lev nostep bind cont (MSt vs e) = case e of | |||
240 | 240 | ||
241 | DEnvNil -> bind "whnf" nostep $ MSt DEnvNil $ InHNF a | 241 | DEnvNil -> bind "whnf" nostep $ MSt DEnvNil $ InHNF a |
242 | 242 | ||
243 | ELet x `DEnvCons` vs -> step "goUp" $ MSt vs $ InHNF $ Let x $ InHNF a | 243 | ELet n x `DEnvCons` vs -> step "goUp" $ MSt vs $ InHNF $ Let n x $ InHNF a |
244 | x `DEnvCons` vs | Let y e <- a -> step "pakol" $ MSt (upP 0 1 x `DEnvCons` ELet y `DEnvCons` vs) e | 244 | x `DEnvCons` vs | Let n y e <- a -> step "pakol" $ MSt (upP 0 1 x `DEnvCons` ELet n y `DEnvCons` vs) e |
245 | x `DEnvCons` vs -> case x of | 245 | x `DEnvCons` vs -> case x of |
246 | EOp2_1 SeqOp b -> case a of | 246 | EOp2_1 SeqOp b -> case a of |
247 | Int{} -> step "seq" $ MSt vs b | 247 | Int{} -> step "seq" $ MSt vs b |
@@ -252,8 +252,8 @@ steps lev nostep bind cont (MSt vs e) = case e of | |||
252 | Con cn i es -> step "case" $ MSt vs $ foldl App (cs !! i) es -- TODO: remove unused cases | 252 | Con cn i es -> step "case" $ MSt vs $ foldl App (cs !! i) es -- TODO: remove unused cases |
253 | _ -> step "case hnf" $ MSt vs $ InHNF $ Case cns (InHNF a) cs | 253 | _ -> step "case hnf" $ MSt vs $ InHNF $ Case cns (InHNF a) cs |
254 | EOp2_1 AppOp b -> case a of | 254 | EOp2_1 AppOp b -> case a of |
255 | Lam (down 0 -> Just x) -> step "appdel" $ MSt vs x -- TODO: remove b | 255 | Lam _ (down 0 -> Just x) -> step "appdel" $ MSt vs x -- TODO: remove b |
256 | Lam x -> step "app" $ MSt (ELet b `DEnvCons` vs) x | 256 | Lam n x -> step "app" $ MSt (ELet n b `DEnvCons` vs) x |
257 | _ -> step "app hnf" $ MSt vs $ InHNF $ App (InHNF a) b | 257 | _ -> step "app hnf" $ MSt vs $ InHNF $ App (InHNF a) b |
258 | EOp2_1 op b -> step "op2_2 hnf" $ MSt (EOp2_2 op (InHNF a) `DEnvCons` vs) b | 258 | EOp2_1 op b -> step "op2_2 hnf" $ MSt (EOp2_2 op (InHNF a) `DEnvCons` vs) b |
259 | EOp2_2 op b -> case (b, a) of | 259 | EOp2_2 op b -> case (b, a) of |
@@ -265,11 +265,11 @@ steps lev nostep bind cont (MSt vs e) = case e of | |||
265 | int LessEq a b = if a <= b then T else F | 265 | int LessEq a b = if a <= b then T else F |
266 | int EqInt a b = if a == b then T else F | 266 | int EqInt a b = if a == b then T else F |
267 | _ -> step "op2 hnf" $ MSt vs $ InHNF $ Op2 op b (InHNF a) | 267 | _ -> step "op2 hnf" $ MSt vs $ InHNF $ Op2 op b (InHNF a) |
268 | EDLet1 (dDown 0 -> Just d) -> zipUp (InHNF a) vs d | 268 | EDLet1 _ (dDown 0 -> Just d) -> zipUp (InHNF a) vs d |
269 | EDLet1 d -> zipUp (up 0 1 a) (ELet (InHNF a) `DEnvCons` vs) d | 269 | EDLet1 n d -> zipUp (up 0 1 a) (ELet n (InHNF a) `DEnvCons` vs) d |
270 | 270 | ||
271 | where | 271 | where |
272 | zipDown 0 e (ELet z `DEnvCons` zs) = MSt (EDLet1 e `DEnvCons` zs) z | 272 | zipDown 0 e (ELet n z `DEnvCons` zs) = MSt (EDLet1 n e `DEnvCons` zs) z |
273 | zipDown j e (z@ELet{} `DEnvCons` zs) = zipDown (j-1) (z `DExpCons` e) zs | 273 | zipDown j e (z@ELet{} `DEnvCons` zs) = zipDown (j-1) (z `DExpCons` e) zs |
274 | zipDown j e (z `DEnvCons` zs) = zipDown j (z `DExpCons` e) zs | 274 | zipDown j e (z `DEnvCons` zs) = zipDown j (z `DExpCons` e) zs |
275 | 275 | ||
@@ -306,9 +306,9 @@ instance ViewShow Exp where | |||
306 | pShow e@(Exp_ fv x) = showFE green vi fv $ | 306 | pShow e@(Exp_ fv x) = showFE green vi fv $ |
307 | case {-if vi then Exp_ (selfContract fv) x else-} e of | 307 | case {-if vi then Exp_ (selfContract fv) x else-} e of |
308 | Var (Nat i) -> DVar i | 308 | Var (Nat i) -> DVar i |
309 | Let a b -> shLet "" (pShow a) $ pShow b | 309 | Let n a b -> shLet n (pShow a) $ pShow b |
310 | Seq a b -> DOp "`seq`" (Infix 1) (pShow a) (pShow b) | 310 | Seq a b -> DOp "`seq`" (Infix 1) (pShow a) (pShow b) |
311 | Lam e -> shLam "" $ pShow e | 311 | Lam n e -> shLam n $ pShow e |
312 | Con s i xs -> foldl DApp (text s) $ pShow <$> xs | 312 | Con s i xs -> foldl DApp (text s) $ pShow <$> xs |
313 | Int i -> pShow' i | 313 | Int i -> pShow' i |
314 | Y e -> "Y" `DApp` pShow e | 314 | Y e -> "Y" `DApp` pShow e |
@@ -341,16 +341,16 @@ instance ViewShow MSt where | |||
341 | 341 | ||
342 | g y DEnvNil = y | 342 | g y DEnvNil = y |
343 | g y z@(DEnvCons p env) = flip g env $ {-showFE red vi (case p of EnvPiece f _ -> f) $-} case p of | 343 | g y z@(DEnvCons p env) = flip g env $ {-showFE red vi (case p of EnvPiece f _ -> f) $-} case p of |
344 | EDLet1 x -> shLet "" y (h x) | 344 | EDLet1 n x -> shLet n y (h x) |
345 | ELet x -> shLet "" (pShow x) y | 345 | ELet n x -> shLet n (pShow x) y |
346 | ECase cns xs -> shCase cns y (pShow <$> xs) | 346 | ECase cns xs -> shCase cns y (pShow <$> xs) |
347 | EOp2_1 op x -> shOp2 op y (pShow x) | 347 | EOp2_1 op x -> shOp2 op y (pShow x) |
348 | EOp2_2 op x -> shOp2 op (pShow x) y | 348 | EOp2_2 op x -> shOp2 op (pShow x) y |
349 | 349 | ||
350 | h DExpNil = onred $ white "*" --TODO? | 350 | h DExpNil = onred $ white "*" --TODO? |
351 | h z@(DExpCons p (h -> y)) = showFE blue vi (case p of EnvPiece f _ -> f) $ case p of | 351 | h z@(DExpCons p (h -> y)) = showFE blue vi (case p of EnvPiece f _ -> f) $ case p of |
352 | EDLet1 x -> shLet "" y (h x) | 352 | EDLet1 n x -> shLet n y (h x) |
353 | ELet x -> shLet "" (pShow x) y | 353 | ELet n x -> shLet n (pShow x) y |
354 | ECase cns xs -> shCase cns y (pShow <$> xs) | 354 | ECase cns xs -> shCase cns y (pShow <$> xs) |
355 | EOp2_1 op x -> shOp2 op y (pShow x) | 355 | EOp2_1 op x -> shOp2 op y (pShow x) |
356 | EOp2_2 op x -> shOp2 op (pShow x) y | 356 | EOp2_2 op x -> shOp2 op (pShow x) y |
@@ -388,7 +388,7 @@ pattern Cons a b = Con "Cons" 1 [a, b] | |||
388 | caseBool x f t = Case ["False", "True"] x [f, t] | 388 | caseBool x f t = Case ["False", "True"] x [f, t] |
389 | caseList x n c = Case ["[]", "Cons"] x [n, c] | 389 | caseList x n c = Case ["[]", "Cons"] x [n, c] |
390 | 390 | ||
391 | id_ = Lam (Var 0) | 391 | id_ = Lam "x" (Var 0) |
392 | 392 | ||
393 | if_ b t f = caseBool b f t | 393 | if_ b t f = caseBool b f t |
394 | 394 | ||
@@ -398,29 +398,29 @@ test = id_ `App` id_ `App` id_ `App` id_ `App` Int 13 | |||
398 | 398 | ||
399 | test' = id_ `App` (id_ `App` Int 14) | 399 | test' = id_ `App` (id_ `App` Int 14) |
400 | 400 | ||
401 | foldr_ f e = Y $ Lam $ Lam $ caseList (Var 0) (up 0 2 e) (Lam $ Lam $ up 0 4 f `App` Var 1 `App` (Var 3 `App` Var 0)) | 401 | foldr_ f e = Y $ Lam "g" $ Lam "as" $ caseList (Var 0) (up 0 2 e) (Lam "x" $ Lam "xs" $ up 0 4 f `App` Var 1 `App` (Var 3 `App` Var 0)) |
402 | 402 | ||
403 | filter_ p = foldr_ (Lam $ Lam $ if_ (p `App` Var 1) (Cons (Var 1) (Var 0)) (Var 0)) Nil | 403 | filter_ p = foldr_ (Lam "y" $ Lam "ys" $ if_ (p `App` Var 1) (Cons (Var 1) (Var 0)) (Var 0)) Nil |
404 | 404 | ||
405 | and2 a b = if_ a b F | 405 | and2 a b = if_ a b F |
406 | 406 | ||
407 | and_ = foldr_ (Lam $ Lam $ and2 (Var 1) (Var 0)) T | 407 | and_ = foldr_ (Lam "a" $ Lam "b" $ and2 (Var 1) (Var 0)) T |
408 | 408 | ||
409 | map_ f = foldr_ (Lam $ Lam $ Cons (f (Var 1)) (Var 0)) Nil | 409 | map_ f = foldr_ (Lam "z" $ Lam "zs" $ Cons (f (Var 1)) (Var 0)) Nil |
410 | 410 | ||
411 | neq a b = not_ $ Op2 EqInt a b | 411 | neq a b = not_ $ Op2 EqInt a b |
412 | 412 | ||
413 | from_ = Y $ Lam $ Lam $ Cons (Var 0) $ Var 1 `App` Op2 Add (Var 0) (Int 1) | 413 | from_ = Y $ Lam "from" $ Lam "n" $ Cons (Var 0) $ Var 1 `App` Op2 Add (Var 0) (Int 1) |
414 | 414 | ||
415 | idx xs n = caseList xs undefined $ Lam $ Lam $ if_ (Op2 EqInt n $ Int 0) (Var 1) $ idx (Var 0) (Op2 Sub n $ Int 1) | 415 | idx xs n = caseList xs undefined $ Lam "q" $ Lam "qs" $ if_ (Op2 EqInt n $ Int 0) (Var 1) $ idx (Var 0) (Op2 Sub n $ Int 1) |
416 | 416 | ||
417 | t = runMachinePure $ idx (from_ `App` Int 3) (Int 5) | 417 | t = runMachinePure $ idx (from_ `App` Int 3) (Int 5) |
418 | 418 | ||
419 | takeWhile_ p xs = caseList xs Nil $ Lam $ Lam $ if_ (p (Var 1)) (Cons (Var 1) $ takeWhile_ p (Var 0)) Nil | 419 | takeWhile_ p xs = caseList xs Nil $ Lam "x" $ Lam "xs" $ if_ (p (Var 1)) (Cons (Var 1) $ takeWhile_ p (Var 0)) Nil |
420 | 420 | ||
421 | sum_ = foldr_ (Lam $ Lam $ Op2 Add (Var 1) (Var 0)) (Int 0) | 421 | sum_ = foldr_ (Lam "a" $ Lam "b" $ Op2 Add (Var 1) (Var 0)) (Int 0) |
422 | 422 | ||
423 | sum' = Y $ Lam $ Lam $ caseList (Var 0) (Int 0) $ Lam $ Lam $ Op2 Add (Var 1) $ Var 3 `App` Var 0 | 423 | sum' = Y $ Lam "sum" $ Lam "xs" $ caseList (Var 0) (Int 0) $ Lam "y" $ Lam "ys" $ Op2 Add (Var 1) $ Var 3 `App` Var 0 |
424 | 424 | ||
425 | infixl 4 `sApp` | 425 | infixl 4 `sApp` |
426 | 426 | ||
@@ -430,9 +430,9 @@ sApp a b = Seq b (App a b) | |||
430 | accsum acc [] = acc | 430 | accsum acc [] = acc |
431 | accsum acc (x: xs) = let z = acc + x `seq` accsum z xs | 431 | accsum acc (x: xs) = let z = acc + x `seq` accsum z xs |
432 | -} | 432 | -} |
433 | accsum = Y $ Lam $ Lam $ Lam $ caseList (Var 0) (Var 1) $ Lam $ Lam $ Var 4 `sApp` Op2 Add (Var 3) (Var 1) `App` Var 0 | 433 | accsum = Y $ Lam "accsum" $ Lam "acc" $ Lam "xs" $ caseList (Var 0) (Var 1) $ Lam "y" $ Lam "ys" $ Var 4 `sApp` Op2 Add (Var 3) (Var 1) `App` Var 0 |
434 | 434 | ||
435 | fromTo = Y $ Lam $ Lam $ Lam $ Cons (Var 1) $ if_ (Op2 EqInt (Var 0) (Var 1)) Nil $ Var 2 `App` Op2 Add (Var 1) (Int 1) `App` Var 0 | 435 | fromTo = Y $ Lam "fromTo" $ Lam "begin" $ Lam "end" $ Cons (Var 1) $ if_ (Op2 EqInt (Var 0) (Var 1)) Nil $ Var 2 `App` Op2 Add (Var 1) (Int 1) `App` Var 0 |
436 | 436 | ||
437 | t' n = sum' `App` (fromTo `App` Int 0 `App` Int n) -- takeWhile_ (\x -> Op2 LessEq x $ Int 3) (from_ `App` Int 0) | 437 | t' n = sum' `App` (fromTo `App` Int 0 `App` Int n) -- takeWhile_ (\x -> Op2 LessEq x $ Int 3) (from_ `App` Int 0) |
438 | 438 | ||
@@ -447,7 +447,7 @@ primes = 2:3: filter (\n -> and $ map (\p -> n `mod` p /= 0) (takeWhile (\x -> x | |||
447 | main = primes !! 3000 | 447 | main = primes !! 3000 |
448 | -} | 448 | -} |
449 | 449 | ||
450 | test'' = Lam (Int 4) `App` Int 3 | 450 | test'' = Lam "f" (Int 4) `App` Int 3 |
451 | 451 | ||
452 | tests | 452 | tests |
453 | = hnf test == hnf (Int 13) | 453 | = hnf test == hnf (Int 13) |