From b9075b1adce4c0a059ac4b51970e9c35872f1ae9 Mon Sep 17 00:00:00 2001 From: Joscha Date: Sun, 5 Nov 2017 18:43:20 +0000 Subject: [PATCH] Add evaluate --- lambda.hs | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/lambda.hs b/lambda.hs index 38117de..5435e3f 100644 --- a/lambda.hs +++ b/lambda.hs @@ -1,3 +1,4 @@ +-- I removed the line at the bottom, now we can also remove this line. ~G import Data.List import Data.Maybe @@ -103,6 +104,12 @@ apply e = e step :: (Symbol s) => Expression s -> Expression s step = simplify . apply +takeWhileUnique :: (Eq a) => [a] -> [a] +takeWhileUnique l = map fst $ takeWhile (\a -> not $ fst a `elem` snd a) $ zip l (inits l) + +evaluate :: (Symbol s) => Expression s -> [Expression s] +evaluate = takeWhileUnique . iterate apply + _sa = flip SymApostrophe 0 _sl = SymLetter _ea s = ESymbol $ _sa s @@ -179,3 +186,7 @@ main = do printTopLevel . step . step $ (EExpr nl tl) printTopLevel . step . step . step $ (EExpr nl tl) putStrLn "" + + putStrLn "-----" + mapM_ printTopLevel $ evaluate (EExpr nl tl) + putStrLn "-----"