Ticket #1835 (closed feature request: fixed)
Provide information of the instance environment
|Reported by:||guest||Owned by:||igloo|
|Type of failure:||None/Unknown||Difficulty:||Unknown|
|Test Case:||th/T1835||Blocked By:|
This feature request was brought up in .
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.