main = interact $ unlines.map (show.reversePolish) . lines

reversePolish :: String -> Double
reversePolish = solve [] .words

solve :: [Double] -> [String] -> Double
solve acc [] = head acc
solve acc (s:ss)
    | s `elem` ["+","-","*","/"] = solve (func (op s) acc) ss
    | otherwise = solve (read s:acc) ss

func :: Num a => (a -> a -> a) -> [a] -> [a]
func f (x:y:as) = f y x : as

op :: (Num a , Fractional a) => String -> (a -> a -> a)
op "+" = (+)
op "-" = (-)
op "*" = (*)
op "/" = (/)
