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

Popular posts from this blog

Delphi XE2 Indy10 udp client-server interchange using SendBuffer-ReceiveBuffer -

Qt ActiveX WMI QAxBase::dynamicCallHelper: ItemIndex(int): No such property in -

Enable autocomplete or intellisense in Atom editor for PHP -