[Haskell-cafe] Conditional IO ?
Dmitri O.Kondratiev
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
existing libraries)
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
>
> () :: ()
>
> 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
> >
> >
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/haskell-cafe/attachments/20110620/488ff59d/attachment.htm>
More information about the Haskell-Cafe
mailing list