16

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

Petr
  • 62,528
  • 13
  • 153
  • 317
  • If it's possible you'd have to make use of the new typed template haskell stuff, but I don't know anything about that. You could probably make a sort of compile-time assertion by generating some dead code like: `a = (undefined :: (Functor f) => (a -> b) -> f a -> f b); b :: (Int -> Char) -> [Int] -> [Char]; b = a` – jberryman Jul 09 '14 at 15:22

1 Answers1

1

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.

sclv
  • 38,665
  • 7
  • 99
  • 204