[GHC] #9588: Add `MonadPlus {IO, Either e}` and `Alternative (Either e)` instances

#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: libraries/base | Version: Keywords: | Operating System: Architecture: Unknown/Multiple | Unknown/Multiple Difficulty: Unknown | Type of failure: Blocked By: | None/Unknown Related Tickets: | Test Case: | Blocking: | Differential Revisions: -------------------------------------+------------------------------------- The following 3 instances are currently Orphans in `transformers` but shall be defined in `base` instead: {{{#!hs instance MonadPlus IO instance MonadPlus (Either e) instance Alterantive (Either e) }}} This proposal by SPJ already passed the CLC back in April and only needs implementing. I'll submit a patch shortly to Phab -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/9588 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#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

#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 ekmett): The `IO` case is easy and should definitely go in. That one is a no- brainer. However, looking at it, I'm rather uncomfortable about the notion of moving the rather ad hoc `Error` class into `base`. Nobody likes it. Perhaps the fate of the `Either` instance should go back out to the libraries mailing list to try to round up ideas. We could a.) Leave it where it is b.) Bring `Error` into base. c.) Switch it to `Monoid`, which is sadly too big and may break some usecases where `noMsg /= mempty` holds now. d.) Bring `Default` into base, which IIRC was already rejected by the `libraries@` list, and use that instead. e.) Figure out something else. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/9588#comment:2 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#9588: Add `MonadPlus {IO,Either e}` and `Alternative (Either e)` instances -------------------------------------+------------------------------------- Reporter: hvr | Owner: hvr Type: task | Status: new Priority: normal | Milestone: 7.12.1 Component: Core Libraries | Version: Resolution: | Keywords: report- Operating System: Unknown/Multiple | impact Type of failure: None/Unknown | Architecture: Blocked By: | Unknown/Multiple Related Tickets: | Test Case: | Blocking: | Differential Revisions: -------------------------------------+------------------------------------- Changes (by hvr): * cc: core-libraries-committee@… (added) * keywords: => report-impact -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/9588#comment:5 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#9588: Add `MonadPlus {IO,Either e}` and `Alternative (Either e)` instances -------------------------------------+------------------------------------- Reporter: hvr | Owner: hvr Type: task | Status: new Priority: normal | Milestone: 7.12.1 Component: Core Libraries | Version: Resolution: | Keywords: report- Operating System: Unknown/Multiple | impact Type of failure: None/Unknown | Architecture: Blocked By: | Unknown/Multiple Related Tickets: | Test Case: | Blocking: | Differential Revisions: -------------------------------------+------------------------------------- Comment (by ekmett): We should at least split this up into the easy and the hard cases and bite off the `IO` instances for now, and we can explicitly punt on the `Either e` case until someone comes up with a better idea. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/9588#comment:6 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#9588: Add `MonadPlus (Either e)` and `Alternative (Either e)` instances -------------------------------------+------------------------------------- Reporter: hvr | Owner: hvr Type: task | Status: new Priority: normal | Milestone: ⊥ Component: Core Libraries | Version: Resolution: | Keywords: report- | impact Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: #10755 | Differential Revisions: -------------------------------------+------------------------------------- Changes (by hvr): * related: => #10755 * milestone: 7.12.1 => ⊥ Old description:
The following 3 instances are currently Orphans in `transformers` but shall be defined in `base` instead:
{{{#!hs instance MonadPlus IO instance MonadPlus (Either e) instance Alterantive (Either e) }}}
This proposal by SPJ already passed the CLC back in April and only needs implementing. I'll submit a patch shortly to Phab
New description: The following 2 instances are currently Orphans in `transformers` but shall be defined in `base` instead: {{{#!hs instance MonadPlus (Either e) instance Alterantive (Either e) }}} This proposal by SPJ already passed the CLC back in April and only needs implementing. I'll submit a patch shortly to Phab -- Comment: I've split off the easy doable part into #10755 -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/9588#comment:7 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#9588: Add `MonadPlus (Either e)` and `Alternative (Either e)` instances -------------------------------------+------------------------------------- Reporter: hvr | Owner: hvr Type: task | Status: new Priority: normal | Milestone: ⊥ Component: Core Libraries | Version: Resolution: | Keywords: report- | impact Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: #10755 | Differential Revisions: -------------------------------------+------------------------------------- Description changed by ekmett: Old description:
The following 2 instances are currently Orphans in `transformers` but shall be defined in `base` instead:
{{{#!hs instance MonadPlus (Either e) instance Alterantive (Either e) }}}
This proposal by SPJ already passed the CLC back in April and only needs implementing. I'll submit a patch shortly to Phab
New description: The following 2 instances are currently Orphans in `transformers` but could be defined in `base` without instead: {{{#!hs instance Error e => MonadPlus (Either e) instance Error e => Alterantive (Either e) }}} This would, however, require us to move `Error` from `transformers` into base, which may be a controversial move. -- -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/9588#comment:8 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#9588: Add `MonadPlus (Either e)` and `Alternative (Either e)` instances -------------------------------------+------------------------------------- Reporter: hvr | Owner: hvr Type: task | Status: new Priority: normal | Milestone: ⊥ Component: Core Libraries | Version: Resolution: | Keywords: report- | impact Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: #10755 | Differential Revisions: -------------------------------------+------------------------------------- Comment (by ekmett): I've updated the description to note that the CLC approved the IO instances unconditionally, but expressed reservations about the Either instances. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/9588#comment:9 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#9588: Add `MonadPlus (Either e)` and `Alternative (Either e)` instances -------------------------------------+------------------------------------- Reporter: hvr | Owner: hvr Type: task | Status: new Priority: normal | Milestone: ⊥ Component: Core Libraries | Version: Resolution: | Keywords: report-impact Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: #10755 #12160 | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Changes (by Iceland_jack): * related: #10755 => #10755 #12160 -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/9588#comment:10 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#9588: Add `MonadPlus (Either e)` and `Alternative (Either e)` instances -------------------------------------+------------------------------------- Reporter: hvr | Owner: hvr Type: task | Status: new Priority: normal | Milestone: ⊥ Component: Core Libraries | Version: Resolution: | Keywords: report-impact Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: #10755 #12160 | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Comment (by Iceland_jack): intended? {{{#!hs $ ghci-8.0.1 GHCi, version 8.0.1: http://www.haskell.org/ghc/ :? for help Loaded GHCi configuration from /apps/strats/.ghci
import Data.Foldable import Control.Applicative import Control.Monad.Trans.Error
<interactive>:1:1: warning: [-Wdeprecations] Module ‘Control.Monad.Trans.Error’ is deprecated: Use Control.Monad.Trans.Except instead
Left "A" <|> Left "B" Left "B" asum [Left "A", Left "B"] Left "" }}}
-- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/9588#comment:11 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#9588: Add `MonadPlus (Either e)` and `Alternative (Either e)` instances -------------------------------------+------------------------------------- Reporter: hvr | Owner: hvr Type: task | Status: new Priority: normal | Milestone: ⊥ Component: Core Libraries | Version: Resolution: | Keywords: report-impact Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: #10755 #12160 | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Comment (by ekmett): Sadly. The current Error based instance in transformers is somewhat lacking in this and other regards. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/9588#comment:12 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

Sadly.
The current Error based instance in transformers is somewhat lacking in
#9588: Add `MonadPlus (Either e)` and `Alternative (Either e)` instances -------------------------------------+------------------------------------- Reporter: hvr | Owner: hvr Type: task | Status: new Priority: normal | Milestone: ⊥ Component: Core Libraries | Version: Resolution: | Keywords: report-impact Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: #10755 #12160 | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Comment (by Iceland_jack): Replying to [comment:12 ekmett]: this and other regards. I mindlessly applied that and it broke a parser in our code :) -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/9588#comment:13 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler
participants (1)
-
GHC