Karte angewendet, um mehrere Argumente in Haskell

Gibt es eine Möglichkeit, die Verwendung von Haskell ist "Karte" oder etwas ähnliches mit mehreren Argumenten?

d.h. der Abstand zwischen einem gegebenen Punkt (definiert als Tupel) und eine Liste von anderen Punkte:

map distance (-3,-3) buildings

Klar, das funktioniert nicht, weil es versucht, die Karte "Abstand" zu (-3,-3), wo die Entfernung erwartet zwei Tupel:

let distance pointA pointB = sqrt ( (frst pointB - frst pointA) * (frst pointB - frst pointA) + (scnd pointB - scnd pointA) * (scnd pointB - scnd pointA) )

Abstand nimmt zwei Punkte als Argumente: man (-3,-3) in diesem Beispiel, und man wird aus der Liste ausgewählt "Gebäude".

(-3,-3) ist nur ein Beispiel. Dieser muss eine variable sein; es kann nicht hardcoded in die Funktion.

Vielleicht wird dies ein bisschen mehr Sinn machen:

buildings = [(3,-2),(2,1),(5,3),(4,3),(4,-1)]

firstDiff pointA pointB = subtract ( fst pointA ) ( fst pointB )

secondDiff pointA pointB = subtract ( snd pointA ) ( snd pointB )

distance pointA pointB = sqrt ( (firstDiff pointA pointB) * (firstDiff pointA pointB) +     (secondDiff pointA pointB) * (secondDiff pointA pointB))

--- What I need to happen here is a list "score" to be created by taking all distances from a point in a list lPoints to a point in list buildings.
InformationsquelleAutor Jason B | 2010-03-01
Schreibe einen Kommentar