Reading the mailing lists from 1994 when this was being debated on the Haskell mailing list, I found a very interesting example from Mark Jones. He found that polymorphic recursion would break his implementation of type classes that didn't pass a dictionary at run time. Without PR, he could statically analyze the whole program and hard code the type class function calls. He points out with the following that it's no longer possible with PR:
f :: Eq a => a -> Bool
f x = x==x || f [x]
Note that if I write
data D = D
instance Show D where
_ == _ = False
then calling f D will require infinitely many instances of f.
I also found a good paper by Kfoury et al. showing lots of examples of polymorphic
recursion in action, and how many of the cases can be overcome using intersection
types (my friend William Lovas' specialty.)
No comments:
Post a Comment