The reason is that you change the type of Left a , even if you do not change the values ββinside it. Note that for Left 1 :: Either Int String , fmap length (Left 1) is of type Either Int Int . Although only one integer is displayed in the Left 1 value, its type has changed because another parameter has changed.
This is similar to the following case:
> let x = [] :: [String] > x == fmap length x Couldn't match type 'Int' with '[Char]' Expected type: [Char] -> String Actual type: [Char] -> Int In the first argument of 'fmap', namely 'length' In the second argument of '(==)', namely 'fmap length x'
Although both values ββare an empty list, lists have different types. x is of type [String] and fmap length x is of type [Int] . Since equality is of type (==) :: Eq a => a -> a -> Bool , you see that you cannot compare the values ββof two different types for equality, since it is the same a .
source share