From 13c980689fa9f0b4f1adb32a8b46b31ac3a19903 Mon Sep 17 00:00:00 2001 From: tzlil Date: Sat, 15 Apr 2023 04:11:02 +0300 Subject: problem 3 --- src/HW.hs | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) (limited to 'src/HW.hs') 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. -- cgit 1.4.1