Opened 3 years ago

Closed 3 years ago

#12767 closed feature request (invalid)

Pattern synonyms for Cont, Writer, Reader, State, ...

Reported by: Iceland_jack Owned by:
Priority: normal Milestone:
Component: Core Libraries Version: 8.0.1
Keywords: PatternSynonyms Cc: ekmett
Operating System: Unknown/Multiple Architecture: Unknown/Multiple
Type of failure: None/Unknown Test Case:
Blocked By: Blocking:
Related Tickets: #12001 Differential Rev(s):
Wiki Page:

Description (last modified by Iceland_jack)

Made this its own ticket, rather than using #12001. Are these worth adding?

import qualified Control.Monad.Cont   as C
import           Control.Monad.Cont   hiding (runCont)
import qualified Control.Monad.Writer as W
import           Control.Monad.Writer hiding (runWriter)
import qualified Control.Monad.Reader as R
import           Control.Monad.Reader hiding (runReader)
import qualified Control.Monad.State  as S
import           Control.Monad.State  hiding (runState)

pattern Cont :: ((a -> r) -> r) -> Cont r a
pattern Cont {runCont} <- (C.runCont -> runCont)
  where Cont a          = cont a

pattern Writer :: (a, w) -> Writer w a
pattern Writer {runWriter} <- (W.runWriter -> runWriter)
  where Writer a            = WriterT (Identity a)

pattern Reader :: (r -> a) -> Reader r a
pattern Reader {runReader} <- (R.runReader -> runReader)
  where Reader a            = reader a

pattern State :: (s -> (a, s)) -> State s a
pattern State {runState} <- (S.runState -> runState)
  where State a           = state a

The mtl API was changed way back when (before advent of pattern synonyms) which caused some confusion, LYAH still uses Writer, State in their examples.

Change History (10)

comment:1 Changed 3 years ago by ekmett

These types live in transformers so a more appropriate venue is a libraries@ request or just an email to Ross Paterson, the transformers maintainer.

I personally think they'd be rather nice to have, as they'd fix one of the main problems users have coming in to modern Haskell from old tutorials at least based on the chatter on #haskell over the years.

comment:2 in reply to:  1 Changed 3 years ago by Iceland_jack

Replying to ekmett:

[...] email to Ross Paterson, the transformers maintainer.

I directed him to this ticket

comment:3 Changed 3 years ago by Iceland_jack

Description: modified (diff)

comment:4 Changed 3 years ago by Iceland_jack

Started a discussion on the library mailing list.

See #12857 for associating pattern synonyms with a type synonym:

module State ( State (State, runState) ) where


type State s = StateT s Identity

pattern State { runState } <- ((runIdentity .) . runStateT -> runState)
  where State runState      = StateT (Identity . runState)

comment:5 Changed 3 years ago by Iceland_jack

There wasn't much of a response but what little it got was positive, how should I proceed

comment:6 Changed 3 years ago by ekmett

I for one am enthusiastic about the idea.

You may want to concoct a patch and see if you can get Ross to merge it as a next step.

As he is the maintainer of transformers, it is ultimately up to him to decide what to do here.

comment:7 Changed 3 years ago by ekmett

FWIW- I'd be happy to merge a pull request to add similar pattern synonyms to on the comonad side.

comment:8 Changed 3 years ago by RyanGlScott

I too would like to see this! Iceland_jack, do you mind opening the pull request for transformers?

The transformers repo is located here. It uses darcs, which can be a bit tricky to navigate if you haven't used it before. If you have any difficulties, feel free to ping me for help.

comment:9 Changed 3 years ago by rwbarton

Can this be closed as Not GHC then?

comment:10 Changed 3 years ago by RyanGlScott

Resolution: invalid
Status: newclosed

Yes, I'd say so.

Note: See TracTickets for help on using tickets.