GHC-8.0 introduced warn-redundant-constraints. But what does it mean at all to have a redundant constraint? If you can remove a constraint and the function is still type-correct then you might call the constraint redundant. E.g. in

singleton :: (Ord a) => a -> Set a

the compiler should warn about the redundant Ord a. The programmer still might want that constraint in order to be more flexible at later internal refactorings.

But what about this:

asTypeOf1 :: (a ~ b) => a -> b -> a
asTypeOf1 x _ = x

? ghci- -fwarn-redundant-constraints warns about the equality constraint.

However, you might write it the Haskell 98 way:

asTypeOf :: a -> a -> a
asTypeOf x _ = x

There is no constraint to complain about, but the function has not the most general type. Is this a redundant constraint, too?

Last modified 4 years ago Last modified on Feb 16, 2016 12:32:03 PM