about summary refs log tree commit diff
path: root/src/HW.hs
diff options
context:
space:
mode:
Diffstat (limited to 'src/HW.hs')
-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