This is my definition of GroceryItem
:
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
from a [String]
in the format ["Apple","15.00","5"]
(from the words
function).
createGroceryItem :: [String] -> GroceryItem
createGroceryItem (a:b:c) = makeGroceryItem a b c
I get the following error which seems to happen because makeGroceryItem
expects Float
and 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*
But how do I make b
and c
of type Float
and Int
, respectively?