In an attempt to get a deeper understanding of several monads (State, ST, IO, ...) I skimmed over some of the research papers (but didn&#39;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 the following:<div>
<br></div><div><div><font class="Apple-style-span" face="&#39;courier new&#39;, monospace"><span class="Apple-style-span" style="font-size: large;">main = do</span></font></div><div><font class="Apple-style-span" face="&#39;courier new&#39;, monospace"><span class="Apple-style-span" style="font-size: large;">  putStrLn &quot;Enter your name:&quot;</span></font></div>
<div><font class="Apple-style-span" face="&#39;courier new&#39;, monospace"><span class="Apple-style-span" style="font-size: large;">  x &lt;- getLine</span></font></div><div><font class="Apple-style-span" face="&#39;courier new&#39;, monospace"><span class="Apple-style-span" style="font-size: large;">  putStr &quot;Welcome &quot;</span></font></div>
<div><font class="Apple-style-span" face="&#39;courier new&#39;, monospace"><span class="Apple-style-span" style="font-size: large;">  putStrLn x</span></font></div><div><font class="Apple-style-span" face="&#39;courier new&#39;, monospace"><span class="Apple-style-span" style="font-size: large;">  putStrLn &quot;Goodbye!&quot;</span></font></div>
<div><div><font class="Apple-style-span" face="&#39;courier new&#39;" size="4"><span class="Apple-style-span" style="font-size: 16px;"><br></span></font></div><div><font class="Apple-style-span" face="&#39;courier new&#39;" size="4"><span class="Apple-style-span" style="font-size: 16px;"><span class="Apple-style-span" style="font-family: arial; font-size: 13px; ">But instead of using IO, I wanted to make my own pure monad that gets evaluated with interact, and does the same.</span></span></font></div>
<div><br></div><div>However, I get the following output:</div><div><br></div><div>Enter your name:</div><div>Welcome ......</div><div><br></div><div>So the Welcome is printed too soon.</div><div><br></div><div>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&#39;t print anything and asks input first, or it still prints too much output.</div>
<div><br></div><div>Of course I could just use ST, State, transformers, etc, but this is purely an exercise I&#39;m doing.</div><div><br></div><div>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 :-)</div>
<div><br></div><div>The code is at <a href="http://hpaste.org/fastcgi/hpaste.fcgi/view?id=8316">http://hpaste.org/fastcgi/hpaste.fcgi/view?id=8316</a></div><div><br></div><div>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 ;-)</div>
<div><br></div><div>Thanks a lot,</div><div>Peter Verswyvelen</div><div><br></div></div></div>