about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authortzlil <tzlils@protonmail.com>2023-04-15 23:34:11 +0300
committertzlil <tzlils@protonmail.com>2023-04-15 23:34:11 +0300
commitea3a08a8b2c201ffa9d23c21ef0df46c588706d7 (patch)
tree724411bb14ca828011177a8b1df0f3d93c9d85d7 /src
parentbc8ca82ea5432adbe80527ba23fb1ff8b37009c0 (diff)
improve normalstep HEAD master
Diffstat (limited to 'src')
-rw-r--r--src/HW.hs17
1 files changed, 8 insertions, 9 deletions
diff --git a/src/HW.hs b/src/HW.hs
index a2678ca..6f4a8fc 100644
--- a/src/HW.hs
+++ b/src/HW.hs
@@ -34,20 +34,19 @@ subst n x (Lam y m)
 
 -- | Take a single step in normal order reduction or return Nothing
 normalstep :: Expr -> Maybe Expr
+
 -- beta
 normalstep (App (Lam x m) n) = Just (subst n x m)
+
 -- body
-normalstep (Lam x m) = case normalstep m of
-    Just m' -> Just (Lam x m')
-    Nothing -> Nothing
+normalstep (Lam x m) = normalstep m >>= return . Lam x
+
 -- arg
-normalstep (App m n) | normalstep m == Nothing = case normalstep n of
-    Just n' -> Just (App m n')
-    Nothing -> Nothing
+normalstep (App m n) | normalstep m == Nothing = normalstep n >>= return . App m
+
 -- func
-normalstep (App m n) = case normalstep m of
-    Just m' -> Just (App m' n)
-    Nothing -> Nothing
+normalstep (App m n) = normalstep m >>= return . (`App` n)
+
 -- No further reductions
 normalstep _ = Nothing