Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to fix Defaulting the following constraint(s) to type... Haskell

Tags:

haskell

I have the following helper method

distance :: Segment -> Length
distance ((ax, ay), (bx, by)) = sqrt ((bx-ax)^2 + (by-ay)^2)

And I get the warning

polycake.hs:115:46: Warning:
Defaulting the following constraint(s) to type ‘Integer’
  (Integral b0) arising from a use of ‘^’ at polycake.hs:115:46
  (Num b0) arising from the literal ‘2’ at polycake.hs:115:47
In the first argument of ‘(+)’, namely ‘(bx - ax) ^ 2’
In the first argument of ‘sqrt’, namely
  ‘((bx - ax) ^ 2 + (by - ay) ^ 2)’
In the expression: sqrt ((bx - ax) ^ 2 + (by - ay) ^ 2)

I can't suppress the warning either, looking for a way to explicitly cast it to a type.

like image 218
jaMAN Avatar asked Jan 29 '23 07:01

jaMAN


1 Answers

Annotate each 2, as in

(bx-ax)^(2 :: Integer)
like image 186
Daniel Wagner Avatar answered Jan 30 '23 20:01

Daniel Wagner