Haskell is challenging! What I figured out so far is that I can do the following to simulate a for-loop in Haskell to get a list of numbers from the user:
myList <- sequence [putStr "Enter an integer: " >> (
\s -> read s :: Int) <$> getLine | t <- [1..5]]
Great! So myList contains five integers that I have entered. Great! But here's the catch. Instead of a for-loop that iterates five times (or any finite number of times) how can I convert the above to the equivalent while-loop?
So what I'm thinking of is this, but it won't work, unfortunately. Is there some "magic" way to make it work?
takeWhile (\x -> x > 0) $ sequence [putStr "Enter an integer: " >> (
\s -> read s :: Int) <$> getLine | t <- [1..]]
The problem is that (\x -> x > 0) works with Ints. (Or any Num type.) But what's coming from that list is really a bunch of IO Ints. x > 0 returns a Bool. I need a function that returns an IO Bool? I'm a little lost. Can someone point the way to Haskell enlightenment for me?! Studying this on my own isn't exactly easy!!! Thank you so much!!!