Functions exported by this module can be used to fuse programs as shown below. The following program reads some Haskell definitions from the standard input and prints the transformed definitions to the standard output.
import HFusion.HFusion import Control.Monad.Trans(lift) import Language.Haskell.Parser(parseModule)
fuseProgram :: String -> Either FusionError String fuseProgram 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 -- Fuse compositions in the program. >>= \dfs -> lift (fuseDefinitions dfs dfs) -- Pretty print the result. >>= return . hsSyn2HsSourceCode . uncurry (++) main = do cs <- getContents putStr$ either (("There was an error: "++) . show) id$ fuseProgram 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)], [([Def], HyloT)])
- fuseDefinitions :: [Def] -> [Def] -> VarGenState ([Def], [Def])
- 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 VarGenState a
- type VarGen = Map String Int
- newVarGen :: VarGen
- 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.
Definitions in scope. Hylomorphism will be derived from them.
Definitions containing compositions which must be eliminated.
|-> VarGenState ([Def], [Def])|
The transformed definitions without the compositions that were succesfully fused and the additional definitions introduced as a result of fusion.
Eliminates compositions of recursive functions from definitions.
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 function definitions.
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. In
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