Skip to content

Instantly share code, notes, and snippets.

@oropon
Last active January 3, 2016 05:49
Show Gist options
  • Save oropon/8418274 to your computer and use it in GitHub Desktop.
Save oropon/8418274 to your computer and use it in GitHub Desktop.
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