
On Fri, Jan 25, 2013 at 12:39 PM,
**
This has the code smell of trying to use typeclasses for OOP. That won't work. (Yes, really.)
I am not trying to use OOP, I am just writing some typecasting at all.
This would be correct. Constraints on an instance are applied *after* the instance is selected, so when Haskell is looking for an instance, these two are identical.
I didn't understand why these two instances are identical ? The constraints are different and OverlappingInstances should permit overlapping typeclasses in constraints and select more specific instance clause.
They are identical because constraints don't "count" for deciding that a type is in a class. For the purposes of deciding if a type is in a class, instance Foo (Bar a) instance Fizz a => Foo (Bar a) instance Fuzz a => Foo (Bar a) are exactly the same, and all three are therefore overlapping instances. None is more specific, because they all refer to the same type -- (Bar a). Also, you can just use Typeable instead of that downcasting stuff.