diff options
author | tzlil <tzlils@protonmail.com> | 2023-04-15 04:11:02 +0300 |
---|---|---|
committer | tzlil <tzlils@protonmail.com> | 2023-04-15 04:11:02 +0300 |
commit | 13c980689fa9f0b4f1adb32a8b46b31ac3a19903 (patch) | |
tree | 97b2030325823c34f49580efa9c4c8eb43091662 | |
parent | 8ee7f4d20a27cf7d53f67a5f9b1960048ef07328 (diff) |
problem 3
-rw-r--r-- | src/HW.hs | 17 |
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. |