Well basically, I’m having a problem, how to make a function in haskell to work like this:
to take the first element of a string, then take the second one and compare them, then the function should continue with taking the third element from the string and comparing the second and the third one.
If it would have to compare the first two then the next two it would be easy, but I just can’t figure it out in this particular situation.
I need to achieve this step in order to write a function which if finds two neighbor elements which are the same, returns True and if there aren’t any elements like that returns False.
Thanks for any help.
A higher-order way to accomplish this (i.e. no explicit recursion) is to use
zipWithto perform a point-wise comparison of the elements in the list, starting with the first, against the elements of the list, starting from the second (usingtail), and then usingorto collapse the point-wise results into a single result. You don’t even need to special case the empty list sincezipWithis non-strict in its third argument if its second argument is the empty list.EDIT: Solution (hover to reveal)