Personal tools

GroteTrap

From HaskellWiki

Revision as of 12:21, 24 June 2008 by MartijnVanSteenbergen (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

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"
And [Var "p",Var "q"]