Skip to content

Provide information of the instance environment

This feature request was brought up in [1].

Right now TH doesn't have access to the instance environment of the typechecker. Thus, it's impossible to check whether a class instance exists for certain type, making impossible to guarantee the generation of correct code in some cases.

For example, that happens when, for a justified reason, the function to be spliced takes a variable Name as argument and not a value. There is no way to force a class constraint on names nor a way to check whether the variable type (obtained with reify) is an instance of a certain class. If the generated code makes use of any class function, its possible to generate incorrect code.

I suggest adding a function similar to this one:

isClassInstance :: Name   -- ^ Class name
                -> Type   -- ^ Type to check
                -> Q Bool

Another option would be extending ClassI to provide the list of instances of a class and code 'isClassInstance' using that information.

[1] http://www.haskell.org/pipermail/template-haskell/2007-November/000645.html

Trac metadata
Trac field Value
Version 6.8.1
Type FeatureRequest
TypeOfFailure OtherFailure
Priority normal
Resolution Unresolved
Component Template Haskell
Test case
Differential revisions
BlockedBy
Related
Blocking
CC alfonso.acosta@gmail.com
Operating system Unknown
Architecture Unknown
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information