I'm trying to make sense of one of the examples presented at the pipes tutorial concerning ListT
:
import Pipes
import qualified Pipes.Prelude as P
input :: Producer String IO ()
input = P.stdinLn >-> P.takeWhile (/= "quit")
name :: ListT IO String
name = do
firstName <- Select input
lastName <- Select input
return (firstName ++ " " ++ lastName)
If the example above is run, we get output like the following:
>>> runEffect $ every name >-> P.stdoutLn
Daniel<Enter>
Fischer<Enter>
Daniel Fischer
Wagner<Enter>
Daniel Wagner
quit<Enter>
Donald<Enter>
Stewart<Enter>
Donald Stewart
Duck<Enter>
Donald Duck
quit<Enter>
quit<Enter>
>>>
It seems that:
- When you run this (on ghci), the first name you input will get bound and only the second will change. I would expect that both producers (defined by
Select input
) will take turns (maybe non-deterministically) at reading the input. - Entering
quit
one time will allow to re-bind the first name. Again, I fail to see whyfirstName
will get bound to the first value entered by the user. - Entering
quit
twice in a row will terminate the program. However, I would expect thatquit
only has to be entered twice to quit the program (possibly alternating with other input).
I'm missing something fundamental about the way the example above works, but I cannot see what.