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, 16 insertions, 1 deletions
diff --git a/src/HW.hs b/src/HW.hs
index ac06695..a2678ca 100644
--- a/src/HW.hs
+++ b/src/HW.hs
@@ -34,7 +34,22 @@ subst n x (Lam y m)
 
 -- | Take a single step in normal order reduction or return Nothing
 normalstep :: Expr -> Maybe Expr
-normalstep _ = Just (Var "UNIMPLEMENTED") -- Replace with your solution to problem 3
+-- 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
+-- arg
+normalstep (App m n) | normalstep m == Nothing = case normalstep n of
+    Just n' -> Just (App m n')
+    Nothing -> Nothing
+-- func
+normalstep (App m n) = case normalstep m of
+    Just m' -> Just (App m' n)
+    Nothing -> Nothing
+-- No further reductions
+normalstep _ = Nothing
 
 {- | Return a "fresh" name not already in the set.
  Tries x' then x'', etc.