如何修复默认以下约束类型... Haskell

时间:2018-04-12 02:04:52

标签: haskell

我有以下帮助方法

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

我收到了警告

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)

我也无法抑制警告,寻找一种方法将其明确地转换为类型。

1 个答案:

答案 0 :(得分:6)

注释每个2,如

(bx-ax)^(2 :: Integer)