nd/bird

Mistake at Exercise 3.3.2

Opened this issue · 2 comments

On the solution of Exercise 3.3.2, you wrote:

-- prove that n + m = m + n

-- n + m == 
-- (n +) . foldn Succ Zero m == 
-- by fusion law 
-- foldn Succ n m
...
-- let's define + using first argument pattern mathing:

(+) :: Nat -> Nat -> Nat
Zero + n = n
(Succ m) + n = Succ(m + n)

A pre-requisite condition of applying fusion law on the equation is that (n+).Succ = Succ.(n+). However, if (+) is defined in the above-shown way, we can only get (+n).Succ = Succ. (+n). Thus, under this definition, the fusion law is not applicable.

Thanks for writing those solutions, they really helped me a lot in learning functional programming!

nd commented

Hey! I guess you are right. I was solving these exercises on my own, without anyone checking them. I was a total FP n00b and I still am. At this point I don't even remember what the fusion law is. Chances are there are plenty of mistakes in this repo. If I may, I'd suggest comparing my solutions with others available on the net. I bet there is higher quality stuff out there. E.g. check out https://eli.thegreenplace.net/tag/sicp - the author (works at Google at the moment) published his solutions to SICP (back in 2008 or so) and even got a signed SICP book from the authors.

Thanks a lot for your suggestion!

Haha, I guess it may feel a bit strange to get commented on somethings written 8 years ago. I am currently a fresher student and Bird's book is on my recommended reading list. Your solutions are mostly correct and all of them are very detailed and helpful. I usually read them to give myself new perspectives. : )

Anyways, thanks again for your sharing, and I wish you all the best!