Higher rank types look like great fun. From the Haskell wikibook comes this example:
foo :: (forall a. a -> a) -> (Char,Bool)
foo f = (f 'c', f True)
Now we can evaluate foo id
without the compiler exploding. This example is quickly followed in the book by the real-world example I have seen in a few other places: the ST monad and runST
. That's pretty cool.
But I have yet to come across a situation where I solve a problem by writing my own function with an argument of higher-rank. Have you? What examples do you have of rank-2 or rank-n polymorphism in the wild?