Opened 3 years ago

Last modified 3 years ago

#12857 new feature request

associate pattern synonyms with a type synonym

Reported by: int-e Owned by:
Priority: normal Milestone:
Component: Compiler Version: 8.0.1
Keywords: Cc:
Operating System: Unknown/Multiple Architecture: Unknown/Multiple
Type of failure: None/Unknown Test Case:
Blocked By: Blocking:
Related Tickets: Differential Rev(s):
Wiki Page:

Description

I believe it would be useful to bundle pattern synonyms with type synonyms, which is currently not supported. For example, the State type synonym from monad transformers could profit from such bundling, as it would allow users to use State (..) in an import list:

{-# LANGUAGE ViewPatterns #-}
{-# LANGUAGE PatternSynonyms #-}
{-# LANGUAGE ScopedTypeVariables #-}

module State (
    State (State, runState)
) where

import Control.Monad

newtype Identity a = Identity { runIdentity :: a }

newtype StateT s m a = StateT { runStateT :: s -> m (s, a) }

type State s a = StateT s Identity a

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

(I would have a use for this in haskell-src-exts-simple package, which, similar to the above example, uses type synonyms to instantiate a type parameter a few datatypes to a fixed type.)

Change History (4)

comment:1 Changed 3 years ago by mpickering

I think this is a good idea. Also see #11461 for the class variant of this idea.

comment:2 Changed 3 years ago by Iceland_jack

See #12767 about adding

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

et al to transformers.

comment:3 Changed 3 years ago by goldfire

I'm generally in favor of this idea. But I think this is a perfect candidate for the ghc-proposals process. Please write up a proposal there (mentioning this already-created ticket), and then we can see if this has the community support necessary behind it. Thanks!

Note: See TracTickets for help on using tickets.