【发布时间】:2015-11-09 10:50:07
【问题描述】:
为什么我会在以下程序中出现“绑定”错误?
wheels :: Int
cars :: Int
carpark wheels cars
| wheels == odd = error wheels "is not even"
| cars <= 0 = error cars "is an invalid number"
| (2*cars) >= wheels = error "the number of wheels is invalid"
| wheels >= (4*cars) = error "the number of wheels is invalid"
| otherwise = "There are " (wheels-(2 * cars)) `div` 2 "cars and " (cars - ((wheels - (2 * cars)) div 2)) "motorcycles on the parking lot"
这是错误:
aufgabe1.lhs:6:3: “wheels”的类型签名缺少随附的绑定 aufgabe1.lhs:7:3: “汽车”的类型签名缺少随附的绑定
我怎样才能摆脱它?
【问题讨论】:
-
您不应该为函数参数编写单独的类型签名。您只需要
carPark :: Int -> Int -> String,这是carPark的类型签名。 -
当心 - 您需要“toString”方法
show将Int转换为String并使用连接运算符++来组合这些字符串
标签: haskell