Hi folks,
In Haskell Programming from First Principals, we are comparing the type signatures of the function composition operator and fmap:
(.) :: (b -> c) -> (a -> b) -> (a -> c)
fmap :: (a -> b) -> f a -> f b
The goal is to show that the type signatures are the same, and the exercise begins by changing the type variable names in fmap; 'a’s become 'b’s and 'b’s become 'c’s.
My problem with this approach is that, if we decompose the process into Step 1: Change the "a"s to "b"s, and then Step 2: change the "b"s to "c"s, you end up with a “wrong intermediate type”.
- fmap :: (a -> b) -> f a -> f b
- fmap :: (b -> b) -> f b -> f b
Now, you need to remember which "b"s are “original” and change only those to "c"s, and error-prone process.
My question is, is there a less error-prone process, one in which we don’t end up with a “wrong intermediate type”.