Functions exported by this module can be used to fuse programs as follows:
import HFusion.HFusion import Control.Monad.Trans(lift) import Language.Haskell.Parser(parseModule) fuseDefinitions :: String -> Either FusionError String fuseDefinitions sourceCode = runFusionState newVarGen$ -- Parse input with a Haskell parser. parseResult2FusionState (Language.Haskell.Parser.parseModule sourceCode) -- Convert the haskell AST to the AST used by HFusion. >>= hsModule2HsSyn -- Derive hylomorphisms for the definitions in the program. >>= lift . fmap snd . deriveHylos -- Fuse functions "zip" and "filter", which are expected -- to be defined in the sourceCode parameter, composing -- "filter" on the second argument of "zip" and naming "zf" -- the resulting recursive definition. >>= fuse "zip" 2 "filter" ["zf"] -- Translate the result from HFusion AST to Haskell source code. >>= return . hsSyn2HsSourceCode main = do cs <- readFile "examples.hs" putStr$ either (("There was an error: "++) . show) id$ fuseDefinitions cs
For more information on HFusion please visit http://www.fing.edu.uy/inco/proyectos/fusion.
- hsModule2HsSyn :: HsModule -> FusionState [Def]
- deriveHylos :: [Def] -> VarGenState ([([Def], FusionError)], [HyloT])
- fuse :: String -> Int -> String -> [String] -> [HyloT] -> FusionState [Def]
- fuse' :: String -> Int -> String -> [String] -> [HyloT] -> FusionState ([Def], String)
- hsSyn2HsSourceCode :: [Def] -> String
- runFusionState :: VarGen -> FusionState a -> Either FusionError a
- data FusionError
- type FusionState a = ErrorT FusionError (State VarGen) a
- type VarGen = Map String Int
- newVarGen :: Map k a
- parseResult2FusionState :: ParseResult HsModule -> FusionState HsModule
- data Def = Defvalue Variable Term
- data Term
- data Pattern
- data Variable
- type Constructor = String
- data Literal
- data Boundvar
HsModule into the abstract syntax tree used by HFusion.
The HsModule can be obtained by parsing a Haskell program with
Obtains hylomorphisms representing functions in the original program.
The hylomorphisms are returned in the second component of the output. If a hylomorphism cannot be derived for some (possibly) mutually recursive function definitions, then they are returned in the first component of the output together with the error obtained when attempting derivation.
Fuses the composition of two recursive functions producing an equivalent new recursive function.
fuse but returns also a string resembling the hylomorphism which represents
the result of fusion.
Pretty prints a set of definitions into Haskell source code.
Errors that the algorithms in HFusion can produce.
Thrown when hylomorphism derivation fails due to the existence of a non-saturated application of the recursive function in its definition.
Thrown when fusion fails due to the inability of the implementation to derive an unfold from the definition at the right of the composition.
Thrown when fusion fails due to the inability of the implementation to derive a fold from the definition at the left of the composition.
Thrown when fusion fails due to the inability of the implementation to derive a tau transformer from the algebra of the definition at the right of the composition.
Thrown when fusion fails due to the inability of the implementation to derive a sigma transformer from the coalgebra of the definition at the left of the composition.
When a definition which was requested to be fused is not found among the derived hylomorphisms.
A generic error message.
|ParserError SrcLoc String|
Thrown when translation of a program to a
An error monad with
FusionError errors and a state
monad carrying a generator of fresh variables.
Data used to generate variables. The map stores for each variable name generated so far which was the index last used to generate a fresh variable with such a name as prefix.
Abstract syntax tree
Representation for terms in programs handled by HFusion.
|Ttuple Bool [Term]|
Tuples. The boolean argument tells if the tuple must be flattened when nested with others under an hylo application.
|Tlamb Boundvar Term|
|Tlet Variable Term Term|
|Tcase Term [Pattern] [Term]|
|Tfapp Variable [Term]|
Function application (saturated)
|Tcapp Constructor [Term]|
|Tapp Term Term|
General term application
|Tif Term Term Term|
If expressions, only used for pretty printing
|Thyloapp Variable Int [Term] (Maybe [Int]) Term|
Hylo application, only used for inlining Thyloapp name recargsCount non-recargs recarg recarg may be a tuple
Representation of patterns
|Pcons Constructor [Pattern]|
Constructor application patterns
|Pas Variable Pattern|
Representation of variables.
Name found in the original program.
|Vgen String Int|
Generated identifier containing a prefix and an index.
Representation for Literals.
Representation of bound variables in lambda expressions.
|Bvtuple Bool [Boundvar]|
Bound variable tuples. Uses the boolean value like in