[Haskell] ANNOUNCE: HFusion

Facundo Domínguez facundominguez at gmail.com
Fri Apr 29 23:23:56 CEST 2011


I'm pleased to announce the first release of HFusion[1] as a library.

http://hackage.haskell.org/package/hfusion

HFusion is a tool which transforms a subset of Haskell programs by
applying fusion techniques based on hylomorphism, a program scheme by
means of which it is possible to express a wide class of recursive
functions. Hylomorphisms are automatically derived from user supplied
definitions [1]. Related work includes [2,3,4,5].

The HFusion implementation allows to handle some interesting cases like:

* primitive recursion
* mutual recursion
* recursion over multiple arguments
* recursion based on regular functors

The library is not particularly solid yet, but it may be of use to
people interested in program transformations and certainly it would
benefit from community feedback. Requests for fixes, explanations and
improvements are more than welcome.

======= Use example =======

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

---------

[1] http://www.fing.edu.uy/inco/proyectos/fusion
[2] P. Johann and E. Visser. Warm fusion in Stratego: A case study in
generation of program transformation systems. Annals of Mathematics
and A.I., 29(1-4):1–34, 2000.
[3] T. Yokoyama, Z. Hu, and M. Takeichi. Calculation rules for
warming-up in fusion transformation. In Trends in Func. Programming,
pages 399–41, 2005.
[4] O. Chitil. Type-Inference Based Deforestation of Functional
Programs. PhD thesis, RWTH Aachen, October 2000.
[5] L. Németh. Catamorphism-Based Program  Transformations for
Non-Strict Functional Languages. PhD thesis, Glasgow University, 2000.



More information about the Haskell mailing list