0

I made this function in order to calculate the total distance of a list of point

distancia :: [(Float,Float)] -> Float
distancia [] = 0
distancia [x] = 0
distancia (x:y:xs) = aux + distancia (y:xs)
      where aux = sqrt ((fst y - fst x)^2 + (snd y - snd x)^2)

ghci> distancia [(0,0), (0,0), (1,0), (1,10)] 
11.0 
ghci> distancia [(1,1), (3,4)] 
3.6055512

I made with recursion, but now I need to make this exact one but using higher order functions, map, filter or fold, im new to haskell and dont really know how to start. Any help? Thanks

John
  • 45
  • 5

0 Answers0