Reputation: 63359
Let's say I have two types:
t1 <- [t| (Functor f) => (a -> b) -> f a -> f b |]
t2 <- [t| (Int -> Char) -> [Int] -> [Char] |]
Is it possible to determine in Template Haskell that an expression of t1
can also be of t2
? (Without implementing type unification myself.)
Upvotes: 16
Views: 367
Reputation: 38893
As jberryman says in the comments, you can generate code that will force the typechecker to unify the two types. However, you can't latch into the typechecker to actually check that yourself and branch on the result. You simply don't have the proper access to the full typechecker environment at the TH expansion stage.
Upvotes: 1