mirror of
https://github.com/sdiehl/write-you-a-haskell.git
synced 2024-10-26 19:28:33 +03:00
chapter3/calc/Eval.hs: avoid recomputation of normal form in eval
This commit is contained in:
parent
11709255c3
commit
7d2ecc4b9a
@ -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"
|
||||
|
Loading…
Reference in New Issue
Block a user