# GroteTrap

### From HaskellWiki

(Difference between revisions)

m (fixed error) |
m (improved example) |
||

Line 30: | Line 30: | ||

<haskell> |
<haskell> |
||

− | > readExpression logicLanguage "p && q" |
+ | > readExpression logicLanguage "p && q -> r" |

− | And [Var "p",Var "q"] |
+ | Impl (And [Var "p",Var "q"]) (Var "r") |

</haskell> |
</haskell> |

## Revision as of 12:38, 24 June 2008

**GroteTrap** allows you to quickly define expression languages. It is available for download on Hackage.

An example:

data Logic = Var String | Or [Logic] | And [Logic] | Impl Logic Logic | Not Logic deriving (Show, Eq) logicLanguage :: Language Logic logicLanguage = language { variable = Var , operators = [ Unary Not Prefix 0 "!" , Nary And True 1 "&&" , Nary Or True 2 "||" , Binary Impl InfixR 3 "->" ] }

With this, we can do:

> readExpression logicLanguage "p && q -> r" Impl (And [Var "p",Var "q"]) (Var "r")