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 <[email protected]> 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
> [email protected]
> http://www.haskell.org/mailman/listinfo/haskell-cafe
>
>

_______________________________________________
Haskell-Cafe mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/haskell-cafe

Reply via email to