I am writing the haversine formula in haskell. In one version of my function, the definition and declarations are as follows:
haversine :: Double -> Double -> Double -> Double -> Double
haversine lat1 lon1 lat2 lon2 = let dlon = (toRad lon2) - (toRad lon1)
dlat = (toRad lat2) - (toRad lat1)
a = sin(dlat/2)^2 + cos(lat1)*cos(lat2)*sin(dlon/2)^2
c = 2 * asin(sqrt(a))
in c*r
This function compiles fine. When I change the declaration to:
haversine :: (Double a) => a -> a -> a -> a -> a
I get the following error:
• Expecting one fewer argument to ‘Double’
Expected kind ‘* -> *’, but ‘Double’ has kind ‘*’
• In the type signature:
haversine :: (Double a) -> a -> a -> a -> a -> a
To my knowledge, by writing (Double a), I am subjecting the rest of the parameters labeled 'a' to the Double type class constraint. Why does the latter declaration result in this error?
Double ->toDouble =>when you changed the second from(Double a) ->to(Double a) =>. This can't possibly be correct so I have taken the liberty of editing it back toDouble ->.Doubleis "constant" type constructor. It takes no argument. You can check it with:k Doubleinghci.