I'm looking to take a user input and store it as a list, which I would later be able to search. At the moment I have an empty list called "sales" and this function to take an input and store it in this list.
sales = []
recordPurchase :: IO ()
recordPurchase = do
putStrLn "Manufacturer"
manufacturer <- getLine
putStrLn "Product Name"
product <- getLine
let sales = sales ++ [manufacturer, product]
print sales
At the moment I get an
"*** Exception: <<loop>>"
error. This particular error is solved now, it was due to the line
let sales = sales ++ [manufacturer, product]
However I'm not sure how to combine two lists it seems. Even when it was "working" I was still getting an empty list when sales was printed. I don't know whether I'm even on track here, particularly with the function definition as "IO()".
The bonus part here is if I was able to populate a list, how would I then be able to search it and display certain elements, such as products by a specific manufacturer?
let sales = sales ++create an infinite list? Sales is defined in terms of itself.let sales = sales ++ [manufacturer, product]is the erroneous line. You're trying to change state. Haskell has no state. This is a recursive definition and therefore loops.