Reputation: 315
I want use Haskell higher order function Foldr to calculate the length of a string
stringlength = foldr (\_n -> 1 + n) 0
it give following error.what is the problem with this code?
Unresolved top-level overloading
*** Binding : stringlength
*** Outstanding context : (Num b, Num (b -> b))
Upvotes: 1
Views: 820
Reputation: 69954
You need to add a space to your pattern matching
(\_ n -> ... )
^^here
currently you are matching against a single variable _n
instead of against _
and n
, as you probably want to.
Upvotes: 8