... | ... | @@ -4,6 +4,7 @@ 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
|
|
|
```
|
... | ... | @@ -13,8 +14,10 @@ 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
|
... | ... | @@ -24,8 +27,10 @@ asTypeOf1 x _= x |
|
|
? `ghci-8.0.0.20160214 -fwarn-redundant-constraints` warns about the equality constraint.
|
|
|
|
|
|
|
|
|
|
|
|
However, you might write it the Haskell 98 way:
|
|
|
|
|
|
|
|
|
```
|
|
|
asTypeOf :: a -> a -> a
|
|
|
asTypeOf x _ = x
|
... | ... | |