Last active
January 3, 2016 05:49
-
-
Save oropon/8418274 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Main where | |
main = print $ calc cs | |
cs = "3 4 + 5 2 - * 4 2 / +" | |
calc :: String -> Float | |
calc = head . foldl calc' [] . words where | |
calc' :: [Float] -> String -> [Float] | |
calc' [x] [] = [x] | |
calc' (x':x:xs) y | |
| y == "+" = x + x' : xs | |
| y == "-" = x - x' : xs | |
| y == "*" = x * x' : xs | |
| y == "/" = x / x' : xs | |
calc' acc num = read num : acc |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment