Skip to content

Extend FunD data constructor with information about type signature

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.

Trac metadata
Trac field Value
Version 7.7
Type FeatureRequest
TypeOfFailure OtherFailure
Priority normal
Resolution Unresolved
Component Template Haskell
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