Safe Haskell | Safe-Inferred |
---|
Implements common subexpression elimination (CSE) with hashconsig algorithm as described in
the paper 'Implementing Explicit and Finding Implicit Sharing in EDSLs' by Oleg Kiselyov.
You can define your datatype as a fixpoint type. Then the only thing you need to perform CSE
is to define an instance of the class Traversable
for your datatype.
- type VarName = Int
- type Dag f = IntMap (f VarName)
- fromDag :: Dag f -> [(VarName, f VarName)]
- cse :: (Eq (f Int), Ord (f Int), Traversable f) => Fix f -> Dag f
- letCse :: (Eq (f Int), Ord (f Int), Traversable f) => Fix (Let f) -> Dag f
- data Let f a
- letCata :: (Functor f, Traversable f) => (f a -> a) -> Fix (Let f) -> a
- letCataM :: (Applicative m, Monad m, Traversable f) => (f a -> m a) -> Fix (Let f) -> m a
- letWrapper :: (Fix (Let f) -> a) -> (a -> Fix (Let f)) -> a -> (a -> a) -> a
Documentation
Implicit sharing
cse :: (Eq (f Int), Ord (f Int), Traversable f) => Fix f -> Dag fSource
Performs common subexpression elimination with implicit sharing.
Explicit sharing
letCse :: (Eq (f Int), Ord (f Int), Traversable f) => Fix (Let f) -> Dag fSource
Performs common subexpression elimination with explicit sharing.
To make sharing explicit you can use the datatype Let
.
letCata :: (Functor f, Traversable f) => (f a -> a) -> Fix (Let f) -> aSource
Catamorphism for fixpoint types wrapped in the type Let
.
letCataM :: (Applicative m, Monad m, Traversable f) => (f a -> m a) -> Fix (Let f) -> m aSource
Monadic catamorphism for fixpoint types wrapped in the type Let
.