[Haskell-cafe] Conditional IO ?
Lyndon Maydwell
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
() :: ()
giving
return () :: IO ()
There is also the when function that eliminates the else case for
conditional IO:
http://hackage.haskell.org/packages/archive/base/latest/doc/html/Control-Monad.html#v:when
On Mon, Jun 20, 2011 at 4:00 PM, Dmitri O.Kondratiev <dokondr at gmail.com> wrote:
> Hi,
> 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 ?
>
> Thanks!
>
> _______________________________________________
> Haskell-Cafe mailing list
> Haskell-Cafe at haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-cafe
>
>
More information about the Haskell-Cafe
mailing list