main :: IO ()
main = interact solveRPN

solveRPN :: String -> String -- TODO: Deal with the warning if have time
solveRPN = show . head . foldl foldingFunction [] . words
  where foldingFunction (x:y:ys) "*"   = (y * x):ys
        foldingFunction (x:y:ys) "+"   = (y + x):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
