Fix Trac #3245: memoising typeOf
The performance bug in #3245 was caused by computing the typeRep
once for each call of typeOf, rather than once for each dictionary
contruction. (Computing TypeReps is reasonably expensive, because
of the hash-consing machinery.)
This is readily fixed by putting the TypeRep construction outside
the lambda. (Arguably GHC might have worked that out itself,
but it involves floating something between a type lambda and a
value lambda, which GHC doesn't currently do. If it happens a lot
we could fix that.)