So I need to work with a list of coordinates, I already made a type like this:
type Pont = (Float, Float)
And I need to return a list of Floats calculated from the points I got. What I did so far:
szamol :: Pont -> Float
szamol 0.0 = 0.0
szamol (x,y) = 10^(1/2)*((x^2)+(y^2))
ossz :: [Pont] -> [Pont]
ossz [] = []
ossz (h,t) = szamol h ++ ossz t
it gives me this error:
ERROR "Hazi.hs":6 - Cannot justify constraints in explicitly typed binding
*** Expression : szamol
*** Type : Pont -> Float
*** Given context : ()
*** Constraints : (Integral a, Fractional a)
The pattern
0.0in:makes no sense. A
PontPointis a 2-tuple ofFloats, not a singleFloat, so you can define this as:Using
10^(1/2)will fail, since the^operator expects the second operand to be of a type that is a member of theIntegraltypeclass. You can use10**(1/2).Using
10**(1/2)will give you the square root of10(so ≈ 3.16), and will not calculate the square root of the sum of squares.You thus likely want to use:
In your
osszfunction, you make three mistakes:Floathere;(+), not with(++)and(:), not(,):Here it might be better to use a combination of
sum :: (Foldable t, Num a) => t a -> aandmap :: (a -> b) -> [a] -> [b]:EDIT: if you want to return a list of
Floats, then you can map:or with explicit recursion: