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
La entrada tendrá el formato ["Apple","15.00","5"]
que corté utilizando la función words
de Haskell.¿Convertir cadena a entero/flotar en Haskell?
Recibo el siguiente error que creo que es porque makeGroceryItem
acepta Float
y 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*
Pero cómo hago b
c
y de tipo Float
y Int
, respectivamente?
usted tiene un proyecto interesante. ¿Para qué sirve? –