
#8583: Associated pattern synonyms -------------------------------------+------------------------------------- Reporter: cactus | Owner: Type: feature request | Status: new Priority: normal | Milestone: Component: Compiler | Version: Resolution: | Keywords: | PatternSynonyms Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: 5144 | Blocking: Related Tickets: | Differential Rev(s): -------------------------------------+------------------------------------- Comment (by goldfire): Yes yes yes. I want this! But it's tricky, even forgetting about implementation for the moment. Let's pretend that all types have to be explicit for a sec, and I'll continue the example from the original post: {{{#!hs headOfList :: forall a. [a] -> Maybe a headOfList (Nil @[] @a) = Nothing @a headOfList (Cons @[] @a x _) = Just x }}} There's something very strange going on here. It looks, in those patterns, that we're pattern-matching on a ''type''. This, of course, is not allowed, because types are erased. Upon further inspection, we're not really doing this. The first type parameter to `Nil` and `Cons` are ''inputs''. Contrast to the second type parameter and the term parameters (to `Cons`), which are ''outputs''. Another way to see this is to think about how `Nil @[] @a` and `Nil @Seq @a` are both valid patterns, but `Nil @l @Int` would be terrible, as it requires doing a type check at runtime. So I wonder if implementing this without terrible hacks might depend on PatternFamilies which (despite its name) allows for a mix of inputs and outputs in pattern synonyms. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/8583#comment:7 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler