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
函數分解。將字符串轉換爲整數/浮點在Haskell?
我收到以下錯誤,我認爲這是因爲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*
分別
但我怎麼做b
和Float
型c
和Int
,?
你有一個有趣的項目。它是爲了什麼? – 2015-12-09 14:39:46