[GHC] #8679: Extend FunD data constructor with information about type signature

#8679: Extend FunD data constructor with information about type signature ------------------------------------+------------------------------------- Reporter: jstolarek | Owner: Type: feature request | Status: new Priority: normal | Milestone: Component: Template Haskell | Version: 7.7 Keywords: | Operating System: Unknown/Multiple Architecture: Unknown/Multiple | Type of failure: Other Difficulty: Unknown | Test Case: Blocked By: | Blocking: Related Tickets: | ------------------------------------+------------------------------------- I want to propose that `FunD` data constructor in Template Haskell is extended with a field that contains that function's type signature (if present). Currently the type signature is a separate declaration represented with `SigD`. I motivate my proposal with the fact that function and its type signature are not independent and it might be the case that processing one requires knowledge of the other. Here's a concrete example. Recently I've been working together with Richard Eisenberg on promoting higher-order functions to the type level. To promote a higher order function I need to replace applications of a function passed as a parameter with usage of a special `Apply` type family. For example the definition of `map`: {{{ map :: (a -> b) -> [a] -> [b] map _ [] = [] map f (x:xs) = f x : map f xs }}} will be promoted to: {{{ type family Map (f :: (TyFun k1 k2) -> *) (list :: [k1]) :: [k2] where Map f '[] = '[] Map f (x ': xs) = Apply f x ': Map f xs }}} To generate equations in the `Map` type family from declarations stored by a `FunD` data constructor I need to know that `f` is a function. The only way for me to know this is by promoting type signature stored in `SigD` and checking the type of `f`. But to promote type signature to a type family I need to know the number of patterns in a function clause, which again is stored in `FunD`. In other words my algorithm looks like this: 1. Recover number of patterns in a function clause 2. Based on number of paterns in function's clause promote the type signature to a type family 3. Based on promoted type signature and definitions in `FunD` generate equations in the type family. Since `FunD` and `SigD` are independent I need to do three separate passes (or two passes + some hacking). If `FunD` contained informatuon about type signature I could achieve the same in one pass. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/8679 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler
participants (1)
-
GHC