Pattern Match Failure in List in Haskell -
i have 1 problem pattern matching. when give input (x:y:ys) list containing 3 elements, hugs complain there is: pattern match failure. guess problem here
takenearestones agent (y:ys) (x:nearestones)
because fails match 3 elements list containing 2 elements
this full code:
takenearestones agent (x:y:ys) nearestones | first == second = takenearestones agent (y:ys) (x:nearestones) | otherwise = (x:nearestones) first=(manhattandistance x (agentcoord agent)) second=(manhattandistance y (agentcoord agent)
how can overcome this? in advance
since function recursive , decreasing list, going work you're way down list of 1 element, in case match fail. can fix adding case of function handles feel appropriate
something like
takenearestones agent [x] nearestones = dosomething takenearestones agent [] nearestones = dosomethingelse
Comments
Post a Comment