Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.)

like image 594
Petr Avatar asked Jul 09 '14 10:07

Petr


1 Answers

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.

like image 136
sclv Avatar answered Oct 21 '22 12:10

sclv