I have run into a problem when trying to add 2 parts of a tuple together
Function Type:
close :: (Floating a, Ord a) => (a,a) -> (a,a) -> Float
Function definition:
close y x = sqrt (((fromIntegral(snd x) - fromIntegral(snd y))^2) + ((fromIntegral(fst x) - fromIntegral(fst y)^2)))
On feeding the function a y tuple of format ( , ) and a x tuple of format ( , ) it should calculate the distance between two coordinates. However on launch I get an error of:
Couldn't match expected type 'Float' with actual type 'a'
a is a rigid type variable bound by...
I do understand why the problem is arising, but I have no idea how to fix it
Floating a
in type definition and then feedfromIntegral
in the function with the samea
type which is supposed to belongIntegral
type class... which is a conflict. – ReduFloating a => a -> Float
to produce the result. I would expectclose :: Floating a => (a,a) -> (a,a) -> a
, orclose :: (Integral a, Floating b) => (a,a) -> (a,a) -> b
. Where doOrd
andFloat
come from? – molbdniloFloat
from the output? – Adam Smith