Use guards instead of if
This commit is contained in:
parent
37f974ef02
commit
86dd293001
@ -18,7 +18,8 @@ io f = interact (unlines . map f . filter (not . null) . lines)
|
||||
result :: Either String Double -> String
|
||||
result (Left err) = "Ꞥ∘ " ++ err
|
||||
result (Right x) = printf ("ꟼ∘ " ++ format) x where
|
||||
format = if ceiling x == floor x then "%.0f" else "%.10f"
|
||||
format | ceiling x == floor x = "%.0f"
|
||||
| otherwise = "%.10f"
|
||||
|
||||
|
||||
-- Solve a RPN expression
|
||||
@ -28,7 +29,7 @@ rpn = foldM parse [] . words >=> return . head where
|
||||
parse (x:xs) (flip lookup monad -> Just f) = Right (f x : xs)
|
||||
parse xs (flip lookup nilad -> Just k) = Right (k : xs)
|
||||
parse xs (readMaybe -> Just x) = Right (x : xs)
|
||||
parse xs _ = Left "syntax error"
|
||||
parse _ _ = Left "syntax error"
|
||||
|
||||
|
||||
-- dyadic functions
|
||||
|
Loading…
Reference in New Issue
Block a user