[GHC] #12767: Pattern synonyms for Cont, Writer, Reader, State, ...

GHC ghc-devs at haskell.org
Sun Nov 20 17:37:10 UTC 2016


#12767: Pattern synonyms for Cont, Writer, Reader, State, ...
-------------------------------------+-------------------------------------
        Reporter:  Iceland_jack      |                Owner:
            Type:  feature request   |               Status:  new
        Priority:  normal            |            Milestone:
       Component:  Core Libraries    |              Version:  8.0.1
      Resolution:                    |             Keywords:
                                     |  PatternSynonyms
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 changed by Iceland_jack:

@@ -5,0 +5,9 @@
+ 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)
+
@@ -6,2 +15,2 @@
- pattern Cont a <- (runCont -> a)
-   where Cont a = cont a
+ pattern Cont {runCont} <- (C.runCont -> runCont)
+   where Cont a          = cont a
@@ -10,2 +19,2 @@
- pattern Writer a <- (runWriter -> a)
-   where Writer a = WriterT (Identity a)
+ pattern Writer {runWriter} <- (W.runWriter -> runWriter)
+   where Writer a            = WriterT (Identity a)
@@ -14,2 +23,2 @@
- pattern Reader a <- (runReader -> a)
-   where Reader a = reader a
+ pattern Reader {runReader} <- (R.runReader -> runReader)
+   where Reader a            = reader a
@@ -18,2 +27,2 @@
- pattern State a <- (runState -> a)
-   where State a = state a
+ pattern State {runState} <- (S.runState -> runState)
+   where State a           = state a

New description:

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

 {{{#!hs
 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 [http://stackoverflow.com/questions/14157090/has-the-
 control-monad-state-api-changed-recently confusion],
 [http://learnyouahaskell.com/for-a-few-monads-more LYAH] still uses
 `Writer`, `State` in their examples.

--

--
Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/12767#comment:3>
GHC <http://www.haskell.org/ghc/>
The Glasgow Haskell Compiler


More information about the ghc-tickets mailing list