How do i convert String to Integer/Float in Haskell

Posted by Ranhiru on Stack Overflow See other posts from Stack Overflow or by Ranhiru
Published on 2010-03-18T08:43:49Z Indexed on 2010/03/18 8:51 UTC
Read the original article Hit count: 472

Filed under:
|
|
|
|
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

The input will be in the format ["Apple","15.00","5"] which i broke up using words function in haskell. I get this error which i think is because the makeGroceryItem accepts a Float and an Int. But how do i make b and c Float and Int respectively?

*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*

Thanx a lot in advance :)

© Stack Overflow or respective owner

Related posts about haskell

Related posts about monads