我正在尝试计算行列式,我将det
函数定义如下:
det :: (Double,Double) -> (Double,Double) -> Double
det _ = 0.0
det [] = error "its Empty!"
det [x] = error "contains only one point!"
det (x1, y1) (x2, y2) = (x1*y2 + x2*y1)
我收到以下错误
Equations for ‘det’ have different numbers of arguments
PolygonArea.hs:11:1-11
PolygonArea.hs:14:1-39
Failed, modules loaded: none.
答案 0 :(得分:4)
首先,类型(Double, Double)
始终是一对两个Double
,从不是空列表或单个列表。其次,就像错误消息所说的那样,det
的案例需要具有相同数量的参数,但前三个中有一个,第四个中有两个。
修复所有这些,你得到
det :: (Double, Double) -> (Double, Double) -> Double
det (x1, y1) (x2, y2) = (x1 * y2 + x2 * y1)