Difference between revisions of "Uniplate"

From HaskellWiki
Jump to navigation Jump to search
(Adding notes from Neils June 15 email)
 
m (→‎Links: version linked)
(2 intermediate revisions by one other user not shown)
Line 1: Line 1:
 
I am pleased to announce Uniplate (formerly known as Play), a library for boilerplate removal requiring only Haskell 98 (for normal use) and optionally [[multi-parameter type classes]] (for more advanced features). This library has been tested with [[Yhc]], [[Hugs]] and [[GHC]].
 
I am pleased to announce Uniplate (formerly known as Play), a library for boilerplate removal requiring only Haskell 98 (for normal use) and optionally [[multi-parameter type classes]] (for more advanced features). This library has been tested with [[Yhc]], [[Hugs]] and [[GHC]].
   
The [[Uniplate]] library can do some of the same things as [[Scrap Your
+
The [[Uniplate]] library can do some of the same things as [[Scrap your boilerplate]] (SYB), and has functions that can be used in a similar
Boilerplate]] (SYB), and has functions that can be used in a similar
 
 
manner to everywhere and everything.
 
manner to everywhere and everything.
   
 
==Links==
 
==Links==
 
*Project home page: http://www-users.cs.york.ac.uk/~ndm/uniplate/
 
*Project home page: http://www-users.cs.york.ac.uk/~ndm/uniplate/
*Hackage release: http://hackage.haskell.org/cgi-bin/hackage-scripts/package/uniplate-1.0
+
*Hackage release: http://hackage.haskell.org/cgi-bin/hackage-scripts/package/uniplate
 
*Haddock docs: http://www.cs.york.ac.uk/fp/haddock/uniplate/
 
*Haddock docs: http://www.cs.york.ac.uk/fp/haddock/uniplate/
 
*Short Manual: http://www.cs.york.ac.uk/fp/darcs/uniplate/uniplate.htm
 
*Short Manual: http://www.cs.york.ac.uk/fp/darcs/uniplate/uniplate.htm

Revision as of 06:58, 24 December 2013

I am pleased to announce Uniplate (formerly known as Play), a library for boilerplate removal requiring only Haskell 98 (for normal use) and optionally multi-parameter type classes (for more advanced features). This library has been tested with Yhc, Hugs and GHC.

The Uniplate library can do some of the same things as Scrap your boilerplate (SYB), and has functions that can be used in a similar manner to everywhere and everything.

Links

The manual contains a basic overview of some bits of the library, the paper goes into more detail, but is intended to still be a readable introduction to the library.

Example

Given an Int expression data type:

data Expr  =  Add  Expr  Expr  | Val  Int
           |  Sub  Expr  Expr  | Var  String
           |  Mul  Expr  Expr  | Neg  Expr
           |  Div  Expr  Expr

We can extract all the variables using the function:

variables :: Expr -> [String]
variables (Var  x  ) = [x]
variables (Val  x  ) = []
variables (Neg  x  ) = variables x
variables (Add  x y) = variables x ++ variables y
variables (Sub  x y) = variables x ++ variables y
variables (Mul  x y) = variables x ++ variables y
variables (Div  x y) = variables x ++ variables y

Or we can use the Uniplate library:

variables :: Expr -> [String]
variables x = [y | Var y <- universe x]

Thanks to

Colin Runciman, Bjorn Bringert, Jules Bean, Eric Mertens, Tom Shackell and Stefan O'Rear for various help and feedback.

Trailer

The Uniplate library has been used in Yhc, Catch, Hoogle and other projects. Please direct any follow-up discussion to haskell-cafe.

Thanks Neil