25.10.2015 Views

Write You a Haskell Stephen Diehl

1kEcQTb

1kEcQTb

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

false = reserved ”false” >> return Fl<br />

zero = reservedOp ”0” >> return Zero<br />

expr :: Parser Expr<br />

expr = Ex.buildExpressionParser table factor<br />

factor :: Parser Expr<br />

factor =<br />

true<br />

false<br />

zero<br />

ifthen<br />

parens expr<br />

contents :: Parser a -> Parser a<br />

contents p = do<br />

Tok.whiteSpace lexer<br />

r Bool<br />

isVal Tr = True<br />

isVal Fl = True<br />

isVal t | isNum t = True<br />

isVal _ = False<br />

e evaluation of our languages uses the Maybe applicative to accommodate the fact that our reduction<br />

may halt at any level with a Nothing if the expression being reduced has reached a normal form or<br />

40

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!