Deprecated: The each() function is deprecated. This message will be suppressed on further calls in /home/zhenxiangba/zhenxiangba.com/public_html/phproxy-improved-master/index.php on line 456
Neil Mitchell - Uniplate
[go: Go Back, main page]

Uniplate

This library (formerly known as 'Play') provides a framework for generic traversals, and is intended to be used in a similar manner to the original Scrap Your Boilerplate paper.

An example of how Uniplate can reduce boilerplate:

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

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

The code for variables is not very nice, however, using Uniplate we can rewrite this as:

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

Downloads

Tags: haskell library phd popular released