我有以下辅助方法
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)
我也无法抑制警告,正在寻找一种将其显式转换为类型的方法。
最佳答案
注释每个 2
,如
(bx-ax)^(2 :: Integer)
关于haskell - 如何修复默认以下约束以键入... Haskell,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/49786872/