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.

TNat -> return TNat<br />

_ -> throwError $ TypeMismatch ta TNat<br />

IsZero a -> do<br />

ta return TBool<br />

_ -> throwError $ TypeMismatch ta TNat<br />

If a b c -> do<br />

ta return TNat<br />

Observations<br />

e pathological stuck terms that we encountered previously in our untyped language are now completely<br />

inexpressive and are rejected at compile-time.<br />

Arith> succ 0<br />

succ 0 : Nat<br />

Arith> succ (succ 0)<br />

succ (succ 0) : Nat<br />

Arith> if false then true else false<br />

false : Bool<br />

Arith> iszero (pred (succ (succ 0)))<br />

false : Bool<br />

Arith> pred (succ 0)<br />

0 : Nat<br />

Arith> iszero false<br />

61

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

Saved successfully!

Ooh no, something went wrong!