[Haskell-cafe] Conditional IO ?
dokondr at gmail.com
Mon Jun 20 10:33:14 CEST 2011
Thanks! Everything works, and 'when' is really nice.
( I still have only basic monad knowledge, need more time to spend on
On Mon, Jun 20, 2011 at 12:14 PM, Lyndon Maydwell <maydwell at gmail.com>wrote:
> 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
> conditional IO:
> On Mon, Jun 20, 2011 at 4:00 PM, Dmitri O.Kondratiev <dokondr at gmail.com>
> > 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
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Haskell-Cafe