Skip to content

associate pattern synonyms with a type synonym

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.)

Trac metadata
Trac field Value
Version 8.0.1
Type FeatureRequest
TypeOfFailure OtherFailure
Priority normal
Resolution Unresolved
Component Compiler
Test case
Differential revisions
BlockedBy
Related
Blocking
CC
Operating system
Architecture
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information