Copyright | (c) Kimiyuki Onaka 2021 |
---|---|
License | Apache License 2.0 |
Maintainer | kimiyuki95@gmail.com |
Stability | experimental |
Portability | portable |
Safe Haskell | None |
Language | Haskell2010 |
\[ \newcommand\int{\mathbf{int}} \newcommand\bool{\mathbf{bool}} \newcommand\list{\mathbf{list}} \]
Synopsis
- run :: (MonadAlpha m, MonadError Error m) => Program -> m Program
- rule :: MonadAlpha m => RewriteRule m
- reduceScanlBuild :: Monad m => RewriteRule m
- reduceFoldlSetAtRecurrence :: MonadAlpha m => RewriteRule m
- reduceFoldlSetAtAccumulation :: MonadAlpha m => RewriteRule m
- reduceFoldlSetAtGeneric :: MonadAlpha m => RewriteRule m
- getRecurrenceFormulaBase :: Expr -> ([Expr], Expr)
- getRecurrenceFormulaStep1 :: MonadAlpha m => Integer -> Type -> VarName -> VarName -> Expr -> m (Maybe Expr)
- getRecurrenceFormulaStep :: MonadAlpha m => Integer -> Integer -> Type -> VarName -> VarName -> Expr -> m (Maybe Expr)
Documentation
run :: (MonadAlpha m, MonadError Error m) => Program -> m Program Source #
run
replaces Foldl
with Scanl
.
Example
Before:
let xs = range n xs[0] <- 0 xs[1] <- 1 foldl (fun a i -> do xs[i + 2] <- xs[i] + xs[i + 1] xs ) xs (range (n - 2))
After:
0 : map snd ( scanl (fun a i -> (snd a, fst a + snd a)) (0, 1) (range (n - 2)))
List of builtin functions which are reduced
Build functions
Nil
\(: \forall \alpha. \list(\alpha)\)Cons
\(: \forall \alpha. \alpha \to \list(\alpha) \to \list(\alpha)\)Range1
\(: \int \to \list(\int)\)Build
\(: \forall \alpha. (\list(\alpha) \to \alpha) \to \list(\alpha) \to \int \to \list(\alpha)\)
Map functions
Scanl
\(: \forall \alpha \beta. (\beta \to \alpha \to \beta) \to \beta \to \list(\alpha) \to \list(\beta)\)SetAt
\(: \forall \alpha. \list(\alpha) \to \int \to \alpha \to \list(\alpha)\)
Fold functions
internal rules
rule :: MonadAlpha m => RewriteRule m Source #
reduceScanlBuild :: Monad m => RewriteRule m Source #
reduceFoldlSetAtRecurrence :: MonadAlpha m => RewriteRule m Source #
- This assumes that
Range2
andRange3
are already converted toRange1
(ShortCutFusion
). - This assumes that combinations
Foldl
andMap
squashed (ShortCutFusion
). - This assumes that constants are already folded (
ConstantFolding
).
reduceFoldlSetAtAccumulation :: MonadAlpha m => RewriteRule m Source #
- This assumes that
Range2
andRange3
are already converted toRange1
(ShortCutFusion
). - This assumes that combinations
Foldl
andMap
squashed (ShortCutFusion
). - This assumes that constants are already folded (
ConstantFolding
).
reduceFoldlSetAtGeneric :: MonadAlpha m => RewriteRule m Source #
getRecurrenceFormulaBase :: Expr -> ([Expr], Expr) Source #
getRecurrenceFormulaBase
makes a pair ((a_0, ..., a_{k - 1}), a)
from setat (... (setat a 0 a_0) ...) (k - 1) a_{k - 1})
.
getRecurrenceFormulaStep1 :: MonadAlpha m => Integer -> Type -> VarName -> VarName -> Expr -> m (Maybe Expr) Source #
getRecurrenceFormulaStep1
removes At
in body
.
getRecurrenceFormulaStep :: MonadAlpha m => Integer -> Integer -> Type -> VarName -> VarName -> Expr -> m (Maybe Expr) Source #
getRecurrenceFormulaStep
replaces At
in body
with Proj
.