This was actually something I wanted to understand with my previous question, but I misworded it by giving for granted the solution would somehow have to build on sequence
and repeat
, so I got an intersting answer, which is definitely useful to solve the problem at hand, but I didn't actually solve my curiosity as well, so I'm rephrasing the quesition as in the title.
As you can see from the linked question, I initially wrote
main :: IO ()main = do x <- takeWhile (/= 'q') <$> sequence (repeat getChar) print "you pressed q"
thinking x
would be a finite-length [Char]
.
But I'm now under the impression that I've not "just" used the wrong tool above (takeWhile
, a pure function), but that there's actually no (orthodox) tool at all to bail out of that IO [Char]
that is sequence (repeat getChar)
.
Am I correct?
If not, then how do you bail out of that?
Beware, I'm not asking now the same question as before. I'm looking for a solution that does make use of sequence (repeat getChar)
and still manages to get to the print "you pressed q"
action, or the explanatin of why such a solution doesn't exist.