Petr
Petr

Reputation: 63359

Is it possible to compare two types, if one is assignable from the other?

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

Answers (1)

sclv
sclv

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

Related Questions