Type system and code generation fixes for typeclasses.