GroteTrap

From HaskellWiki
Revision as of 12:30, 24 June 2008 by MartijnVanSteenbergen (talk | contribs) (fixed error)
Jump to navigation Jump to search
The printable version is no longer supported and may have rendering errors. Please update your browser bookmarks and please use the default browser print function instead.

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"]