So i'm following a course on Haskell, and came across defining the length function with the foldr function
so, as the length is not a primitive recursive function, we have to be more specific with the "operator" we're passing to it and, in the course, the end result is this:
len :: [a] -> Int
len = foldr (\_ n -> n + 1) 0
I think i understand the end result, but i really need clarification on the signature of the lambda function:
- the underscore argument is supposed to be the value, which we don't care for
- the n argument is the return of the previous call
am i right to think of it this way? or something different is happening?