In the 2003 Scrap Your Boilerplate paper by Laemmel and SPJ there is a code snippet on page 3
mkT :: (Typeable a, Typeable b) => (b -> b) -> a -> a
mkT f = case cast f of
Just g -> g
Nothing -> id
and then the paper explains
That is, mkT f x applies f to x if x's type is the same as f's argument type
Following in the pattern of the preceding examples in the paper, I would think the type of cast f
would have to be compared with the type Maybe (b -> b)
for the above to evaluate to Just g
, but this seems incorrect.
What is going on here with the signature of cast f
?