Skip to content

Mistake at Exercise 3.3.2 #1

@JackBai0914

Description

@JackBai0914

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!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions