Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import Data.List
- solveRPN :: String -> Float
- solveRPN = head . foldl foldingFunction [] . words
- where foldingFunction (x:y:ys) "*" = (x * y):ys
- foldingFunction (x:y:ys) "+" = (x + y):ys
- foldingFunction (x:y:ys) "-" = (y - x):ys
- foldingFunction (x:y:ys) "/" = (y / x):ys
- foldingFunction (x:y:ys) "^" = (y ** x):ys
- foldingFunction (x:xs) "ln" = log x:xs
- foldingFunction xs "sum" = [sum xs]
- foldingFunction xs numberString = read numberString:xs
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement