Skip empty lines

This commit is contained in:
Rnhmjoj 2015-02-26 23:51:05 +01:00
parent 516a0173f7
commit e2278ad892

4
RPN.hs
View File

@ -8,10 +8,10 @@ main :: IO ()
main = io (show . rpn) main = io (show . rpn)
io :: (String -> String) -> IO () io :: (String -> String) -> IO ()
io f = interact (unlines . map f . lines) io f = interact (unlines . map f . filter (not . null) . lines)
rpn :: String -> Either String Double rpn :: String -> Either String Double
rpn = return . head <=< foldM parse [] . words rpn = foldM parse [] . words >=> return . head
parse :: [Double] -> String -> Either String [Double] parse :: [Double] -> String -> Either String [Double]
parse (y:x:xs) (flip lookup dyad -> Just f) = Right (f x y : xs) parse (y:x:xs) (flip lookup dyad -> Just f) = Right (f x y : xs)