Add evaluate
This commit is contained in:
parent
d5bc202681
commit
b9075b1adc
1 changed files with 11 additions and 0 deletions
11
lambda.hs
11
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.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 "-----"
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue