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.0
in:makes no sense. A
Pont
Point
is a 2-tuple ofFloat
s, 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 theIntegral
typeclass. 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
ossz
function, you make three mistakes:Float
here;(+)
, not with(++)
and(:)
, not(,)
:Here it might be better to use a combination of
sum :: (Foldable t, Num a) => t a -> a
andmap :: (a -> b) -> [a] -> [b]
:EDIT: if you want to return a list of
Float
s, then you can map:or with explicit recursion: