Understanding "manlen(0,0)p==n"

Asked 2 years ago, Updated 2 years ago, 121 views

manlen p1p2=abs(fst p1-fst p2)+abs(snd p1-snd p2)
points n = [(x,y)|x<-[-n..n], y<-[-n..n]]]
circle n = [p | p <-points n, manlen(0,0)p == n ]

I am not sure manlen(0,0)p==n in the last list inclusion notation.
Why do we take p==n for the manlen argument?

haskell

2022-09-30 16:50

1 Answers

In haskel, infix operators that take arguments on both sides, such as ==, have lower priority than normal function calls.Therefore, manlen(0,0)p==n is interpreted as (manlen(0,0)p)==n instead of manlen(0,0)(p==n).This will return the Bool, so it will be a filter.Hence

mancircle n=[p|p<-points n, manlen(0,0)p==n]

returns only the manlen(0,0)p element where manlen(0,0)p is n.


2022-09-30 16:50

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.