Allow visible type application in patterns
EDIT: Though this ticket predates the proposal, it is a good place to track its development: https://github.com/ghc-proposals/ghc-proposals/blob/master/proposals/0126-type-applications-in-patterns.rst
Constructors (and pattern synonyms) when treated as expressions may be applied to types:
{-# LANGUAGE TypeApplications #-}
Nothing :: Maybe a
Nothing @() :: Maybe ()
pattern Pair :: a -> a -> (a, a)
pattern Pair x y = (x, y)
Pair :: a -> a -> (a, a)
Pair @Int :: Int -> Int -> (Int, Int)
But using them in patterns won't parse:
-- parse error in pattern: @Int
maybeToList :: Maybe Int -> [Int]
maybeToList (Nothing @Int) = []
maybeToList (Just @Int x) = [x]
-- parse error in pattern: @Int
add :: (Int, Int) -> Int
add (Pair @Int x y) = x + y
Trac metadata
Trac field | Value |
---|---|
Version | 8.1 |
Type | FeatureRequest |
TypeOfFailure | OtherFailure |
Priority | normal |
Resolution | Unresolved |
Component | Compiler |
Test case | |
Differential revisions | |
BlockedBy | |
Related | |
Blocking | |
CC | |
Operating system | |
Architecture |