
#11350: Allow visible type application in patterns -------------------------------------+------------------------------------- Reporter: Iceland_jack | Owner: Type: feature request | Status: new Priority: normal | Milestone: Component: Compiler | Version: 8.1 Resolution: | Keywords: | TypeApplications PatternSynonyms Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Comment (by Iceland_jack): This ''should'' make the code in [https://ghc.haskell.org/trac/ghc/ticket/8583#comment:7 Richard's comment] compile: {{{#!hs headOfList :: forall a. [a] -> Maybe a headOfList (Nil @[] @a) = Nothing @a headOfList (Cons @[] @a x _) = Just x }}} The rest of his comment applies to, this is not for dynamically branching on types although that could certainly be added as a feature! {{{#!hs doubleWhenInt :: forall a. Typeable a => a -> a doubleWhenInt a = case eqT @Int @a of Just Refl -> a + a Nothing -> a -- Becomes… doubleWhenInt :: forall a. Typeable a => a -> a doubleWhenInt @Int n = n + n doubleWhenInt @_ a = a }}} -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/11350#comment:2 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler