chapter3/calc/Eval.hs: avoid recomputation of normal form in eval

This commit is contained in:
Christian Sievers 2015-01-30 20:23:57 +01:00
parent 11709255c3
commit 7d2ecc4b9a

View File

@ -34,6 +34,6 @@ nf :: Expr -> Expr
nf x = fromMaybe x (nf <$> eval' x)
eval :: Expr -> Maybe Expr
eval t = case isVal (nf t) of
True -> Just (nf t)
False -> Nothing -- term is "stuck"
eval t = case nf t of
nft | isVal nft -> Just nft
| otherwise -> Nothing -- term is "stuck"