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
L'input sarà nel formato ["Apple","15.00","5"]
che ho interrotto utilizzando la funzione words
di Haskell.Converti stringa in intero/virgola mobile in Haskell?
Ottengo il seguente errore che penso sia perché makeGroceryItem
accetta uno Float
e uno 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*
Ma come faccio a fare b
e c
di tipo Float
e Int
rispettivamente?
hai un progetto interessante. cosa serve? –