【发布时间】:2011-01-28 22:21:39
【问题描述】:
data GroceryItem = CartItem ItemName Price Quantity | StockItem ItemName Price Quantity
makeGroceryItem :: String -> Float -> Int -> GroceryItem
makeGroceryItem name price quantity = CartItem name price quantity
I want to create a `GroceryItem` when using a `String` or `[String]`
createGroceryItem :: [String] -> GroceryItem
createGroceryItem (a:b:c) = makeGroceryItem a b c
输入将采用 ["Apple","15.00","5"] 格式,我使用 Haskell 的 words 函数将其分解。
我收到以下错误,我认为这是因为 makeGroceryItem 接受 Float 和 Int。
*Type error in application
*** Expression : makeGroceryItem a read b read c
*** Term : makeGroceryItem
*** Type : String -> Float -> Int -> GroceryItem
*** Does not match : a -> b -> c -> d -> e -> f*
但是我如何分别制作Float 和Int 类型的b 和c?
【问题讨论】:
-
你有一个有趣的项目。它是干什么用的?
标签: haskell floating-point int