Reputation: 770
I have a question about filter
. How can I make that my function (manhattanDistance
) will take each element in list and use it for itself? Can you explain how it can be implemented?
func :: [(Int,Int)] ->
(Int, Int, [Char], [Char], [Char], [Char],
[Char], [Char], [Char], [Char]) ->
[(Int,Int)]
func (x:xs) agent = filter ((manhattanDistance x agentCoord(agent)) == 1) (x:xs)
Upvotes: 1
Views: 100
Reputation: 43309
The problem was that you weren't using the filter's lambda parameter, and referring to a head of the outer function's list instead. Here's a corrected version:
func
:: [(Int, Int)]
-> (Int, Int, [Char], [Char], [Char], [Char], [Char], [Char], [Char], [Char])
-> [(Int, Int)]
func xs agent =
filter (\e -> manhattanDistance e (agentCoord agent) == 1) xs
By the way, that tuple you have should be normalized to ADTs. It's commonly considered a bad practice to use such huge tuples and by the readability of your function's signature you can kinda see why.
Upvotes: 4