Add evaluate

This commit is contained in:
Joscha 2017-11-05 18:43:20 +00:00
parent d5bc202681
commit b9075b1adc

View file

@ -1,3 +1,4 @@
-- I removed the line at the bottom, now we can also remove this line. ~G
import Data.List import Data.List
import Data.Maybe import Data.Maybe
@ -103,6 +104,12 @@ apply e = e
step :: (Symbol s) => Expression s -> Expression s step :: (Symbol s) => Expression s -> Expression s
step = simplify . apply 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 _sa = flip SymApostrophe 0
_sl = SymLetter _sl = SymLetter
_ea s = ESymbol $ _sa s _ea s = ESymbol $ _sa s
@ -179,3 +186,7 @@ main = do
printTopLevel . step . step $ (EExpr nl tl) printTopLevel . step . step $ (EExpr nl tl)
printTopLevel . step . step . step $ (EExpr nl tl) printTopLevel . step . step . step $ (EExpr nl tl)
putStrLn "" putStrLn ""
putStrLn "-----"
mapM_ printTopLevel $ evaluate (EExpr nl tl)
putStrLn "-----"