[Haskell-cafe] Where do I put the seq?
bugfact at gmail.com
Wed Aug 19 07:07:34 EDT 2009
In an attempt to get a deeper understanding of several monads (State, ST,
IO, ...) I skimmed over some of the research papers (but didn't understand
all of it, I lack the required education) and decided to write a little
program myself without using any prefab monad instances that should mimic
main = do
putStrLn "Enter your name:"
x <- getLine
putStr "Welcome "
But instead of using IO, I wanted to make my own pure monad that gets
evaluated with interact, and does the same.
However, I get the following output:
Enter your name:
So the Welcome is printed too soon.
This is obvious since my monad is lazy, so I tried to put a seq at some
strategic places to get the same behavior as IO. But I completely failed
doing so, either the program doesn't print anything and asks input first, or
it still prints too much output.
Of course I could just use ST, State, transformers, etc, but this is purely
an exercise I'm doing.
So, I could re-read all papers and look in detail at all the code, but maybe
someone could help me out where to put the seq or what to do :-)
The code is at http://hpaste.org/fastcgi/hpaste.fcgi/view?id=8316
Oh btw, the usage of DList here might not be needed; intuitively it felt
like the correct thing to do, but when it comes to Haskell, my intuition is
usually wrong ;-)
Thanks a lot,
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Haskell-Cafe