[Haskell-cafe] Instances that shouldn't overlap
oleg at okmij.org
oleg at okmij.org
Thu Nov 27 02:51:50 EST 2008
Paul Johnson wrote:
> class (Eq a) => AppEq f a where
> instance (Applicative f, Eq a) => AppEq f a where
> instance (Ord a) => AppEq Interval a where
In Haskell, instances are selected based solely on the types in the
head. Constraints like `Applicative f' are not consulted when the
instance is being selected. Rather, constraints are checked after the
instance has been selected. The above two instances are overlapping
since Interval is a particular case of `f'.
That said, it is possible to select an instance based on
constraints. The approach is described at
http://haskell.org/haskellwiki/GHC/AdvancedOverlap
More information about the Haskell-Cafe
mailing list