summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorPéter Diviánszky <divipp@gmail.com>2016-05-14 00:46:01 +0200
committerPéter Diviánszky <divipp@gmail.com>2016-05-14 00:49:27 +0200
commit2cb670b19f41f2cd0dcbda0b697e80d5a3e6b922 (patch)
treefee715604669013d0b24026bf64bcf6488c5cadb /src
parented1366697ad7ccf9f369e07161a0f51791fd093e (diff)
speedup primes example
Diffstat (limited to 'src')
-rw-r--r--src/LambdaCube/Compiler/Core.hs9
-rw-r--r--src/LambdaCube/Compiler/Pretty.hs10
2 files changed, 11 insertions, 8 deletions
diff --git a/src/LambdaCube/Compiler/Core.hs b/src/LambdaCube/Compiler/Core.hs
index 76d16a66..45ebda38 100644
--- a/src/LambdaCube/Compiler/Core.hs
+++ b/src/LambdaCube/Compiler/Core.hs
@@ -240,6 +240,7 @@ conTypeName :: ConName -> TyConName
240conTypeName (ConName _ _ t) = case snd $ getParams t of TyCon n _ -> n 240conTypeName (ConName _ _ t) = case snd $ getParams t of TyCon n _ -> n
241 241
242mkFun_ md (FunName _ _ (DeltaDef ar f) _) as _ | length as == ar = f md as 242mkFun_ md (FunName _ _ (DeltaDef ar f) _) as _ | length as == ar = f md as
243mkFun_ md f@(FunName _ _ (ExpDef e) _) xs _ = Neut $ Fun_ md f xs $ hnf $ foldlrev app_ e xs
243mkFun_ md f xs y = Neut $ Fun_ md f xs $ hnf y 244mkFun_ md f xs y = Neut $ Fun_ md f xs $ hnf y
244 245
245mkFun :: FunName -> [Exp] -> Exp -> Exp 246mkFun :: FunName -> [Exp] -> Exp -> Exp
@@ -412,14 +413,6 @@ instance MkDoc Exp where
412 Let a b -> shLet_ (pShow a) (pShow b) 413 Let a b -> shLet_ (pShow a) (pShow b)
413 RHS x -> text "_rhs" `DApp` mkDoc pr x 414 RHS x -> text "_rhs" `DApp` mkDoc pr x
414 415
415showNth n = show n ++ f (n `div` 10 `mod` 10) (n `mod` 10)
416 where
417 f 1 _ = "th"
418 f _ 1 = "st"
419 f _ 2 = "nd"
420 f _ 3 = "rd"
421 f _ _ = "th"
422
423pattern FFix f <- Fun (FunName (FTag FprimFix) _ _ _) [f, _] _ 416pattern FFix f <- Fun (FunName (FTag FprimFix) _ _ _) [f, _] _
424 417
425getFixLam (Lam (Neut (Fun s@(FunName _ loc _ _) xs _))) 418getFixLam (Lam (Neut (Fun s@(FunName _ loc _ _) xs _)))
diff --git a/src/LambdaCube/Compiler/Pretty.hs b/src/LambdaCube/Compiler/Pretty.hs
index 0dd09107..a357a9eb 100644
--- a/src/LambdaCube/Compiler/Pretty.hs
+++ b/src/LambdaCube/Compiler/Pretty.hs
@@ -410,3 +410,13 @@ instance PShow a => PShow (Set.Set a) where
410--instance (PShow s, PShow a) => PShow (Map s a) where 410--instance (PShow s, PShow a) => PShow (Map s a) where
411-- pShow = braces . vcat . map (\(k, t) -> pShow k <> P.colon <+> pShow t) . Map.toList 411-- pShow = braces . vcat . map (\(k, t) -> pShow k <> P.colon <+> pShow t) . Map.toList
412 412
413--------------------------------------------------------
414
415showNth n = show n ++ f (n `div` 10 `mod` 10) (n `mod` 10)
416 where
417 f 1 _ = "th"
418 f _ 1 = "st"
419 f _ 2 = "nd"
420 f _ 3 = "rd"
421 f _ _ = "th"
422