[Haskell-cafe] Conditional IO ?
maydwell at gmail.com
Mon Jun 20 10:14:02 CEST 2011
Your errors branch has the type
writeFile "parse-errors.txt" (show errors) :: IO ()
This means that your otherwise branch should have the same type.
You can use the return function that has the type
return :: Monad m => a -> m a
specialised to m = IO
in conjunction with the value
() :: ()
return () :: IO ()
There is also the when function that eliminates the else case for
On Mon, Jun 20, 2011 at 4:00 PM, Dmitri O.Kondratiev <dokondr at gmail.com> wrote:
> What is right way to do conditional IO?
> For example, I need to write to file errors only in case they exist,
> otherwise my function should do nothing:
> handleParseErrors errors
> | (not . null) errors = writeFile "parse-errors.txt" (show errors)
> | otherwise = ?
> What should be an 'otherwise' case ?
> Haskell-Cafe mailing list
> Haskell-Cafe at haskell.org
More information about the Haskell-Cafe