[GHC] #9588: Add `MonadPlus {IO, Either e}` and `Alternative (Either e)` instances
GHC
ghc-devs at haskell.org
Sat Sep 13 14:07:44 UTC 2014
#9588: Add `MonadPlus {IO,Either e}` and `Alternative (Either e)` instances
-------------------------------------+-------------------------------------
Reporter: hvr | Owner: hvr
Type: task | Status: new
Priority: normal | Milestone: 7.10.1
Component: | Version:
libraries/base | Keywords:
Resolution: | Architecture: Unknown/Multiple
Operating System: | Difficulty: Unknown
Unknown/Multiple | Blocked By:
Type of failure: | Related Tickets:
None/Unknown |
Test Case: |
Blocking: |
Differential Revisions: |
-------------------------------------+-------------------------------------
Comment (by hvr):
I'm hitting a problem while trying to implement this.
While the `IO` instances are rather straightforward
(and btw, there's also an `Alternative IO` instance defined in
`transformers`):
{{{#!hs
instance MonadPlus IO where
mzero = ioError (userError "mzero")
m `mplus` n = m `catchIOError` \ _ -> n
instance Alternative IO where
empty = mzero
(<|>) = mplus
}}}
The instances for `Either`, however, depend on an `Error` class in
`transformers` to produce an `empty`/`mzero` value:
{{{#!hs
instance (Error e) => Alternative (Either e) where
empty = Left noMsg
Left _ <|> n = n
m <|> _ = m
instance (Error e) => MonadPlus (Either e) where
mzero = Left noMsg
Left _ `mplus` n = n
m `mplus` _ = m
}}}
how shall this issue be resolved?
--
Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/9588#comment:1>
GHC <http://www.haskell.org/ghc/>
The Glasgow Haskell Compiler
More information about the ghc-tickets
mailing list