Haversine formula: Difference between revisions

m
Line 1,600:
 
=={{header|Haskell}}==
<lang Haskell>import DataControl.BifunctorMonad (bimapjoin)
import Data.Bifunctor (bimap)
import Text.Printf (printf)
 
-------------------- HAVERSINE FORMULA -------------------
 
-- The haversine of an angle.
Line 1,610 ⟶ 1,613:
-- between two points on Earth.
-- The latitude and longtitude are assumed to be in degrees.
greatCircleDistance ::
earthDist :: (Float, Float) -> (Float, Float) -> Float
(Float, Float) ->
earthDist = distDeg 6371
(Float, Float) ->
Float
earthDistgreatCircleDistance = distDeg 6371
where
distDeg radius p1 p2 =
Line 1,630 ⟶ 1,636:
)
)
deg2rad = join bimap d2r((/ 180) . (pi d2r*))
where
d2r = (/ 180) . (pi *)
 
--------------------------- TEST -------------------------
main :: IO ()
main =
printf
"The distance between BNA and LAX is about %0.f km.\n"
(earthDistgreatCircleDistance bna lax)
where
bna = (36.12, -86.67)
9,655

edits