Typing problems with polymorphic recursion and typeclasses