Saturday, 7 September 2013

What is the purpose of (const id) in this function?

What is the purpose of (const id) in this function?

I'm trying to get deeper into the functional mindset and looking through
solutions to exercises (99 problems).
The first problem is to create a function that returns the last element of
the list.
I see the solution:
myLast = foldr1 (const id)
I understand that foldr1 applies a function f to a list l
so if I plug it into an example:
myLast [1,2,3,4,5,6,7]
Which would be "translated to"
foldr1 (const id) [1,2,3,4,5,6,7]
Could someone explain to me what this (const id) is steppting through. I
tried researching (const id) in SO as well as Hoogle, but couldn't make
much sense of it. Would someone kindly step me through what is happening
here?

No comments:

Post a Comment