I&#39;ve corrected it.  It still doesn&#39;t suffer looping.  :-)<br><br><div class="gmail_quote">On Wed, Aug 19, 2009 at 10:31 AM, David Leimbach <span dir="ltr">&lt;<a href="mailto:leimy2k@gmail.com">leimy2k@gmail.com</a>&gt;</span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">Doesn&#39;t seem to compile.<div><br></div><div>I nearly never use case statements in my code, so I&#39;m not really sure what&#39;s going on.  </div>
<div><br></div><div><div>neat2.hs:14:39: parse error on input `=&#39;</div>
<div><br></div><div>Dave</div></div><div><div></div><div class="h5"><div><br><div class="gmail_quote">On Wed, Aug 19, 2009 at 10:23 AM, Ryan Ingram <span dir="ltr">&lt;<a href="mailto:ryani.spam@gmail.com" target="_blank">ryani.spam@gmail.com</a>&gt;</span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
I posted a reply to your paste with a stricter version of S and some cleanup.<br>
<br>
Untested, though I believe it should work without &quot;seq&quot;.<br>
<br>
&quot;case&quot; provides all the strictness you need, I think!<br>
<font color="#888888"><br>
  -- ryan<br>
</font><div><div></div><div><br>
On Wed, Aug 19, 2009 at 9:28 AM, Peter Verswyvelen&lt;<a href="mailto:bugfact@gmail.com" target="_blank">bugfact@gmail.com</a>&gt; wrote:<br>
&gt; Expect more bugs with this though :-) Just found out that looping does not<br>
&gt; work, it hangs, e.g.<br>
&gt;<br>
&gt; test = do<br>
&gt;   out &quot;Enter your first name:&quot;<br>
&gt;   fstName &lt;- inp<br>
&gt;   out &quot;Enter your second name:&quot;<br>
&gt;   sndName &lt;- inp<br>
&gt;   out (&quot;Welcome &quot;++fstName++&quot; &quot;++sndName)<br>
&gt;   out &quot;Goodbye!&quot;<br>
&gt;   test<br>
&gt;<br>
&gt; Doesn&#39;t seem to work :-) Back to the drawing board.<br>
&gt;<br>
&gt; On Wed, Aug 19, 2009 at 5:55 PM, Peter Verswyvelen &lt;<a href="mailto:bugfact@gmail.com" target="_blank">bugfact@gmail.com</a>&gt;<br>
&gt; wrote:<br>
&gt;&gt;<br>
&gt;&gt; Not at all, use it for whatever you want to :-)<br>
&gt;&gt; I&#39;m writing this code because I&#39;m preparing to write a bunch of tutorials<br>
&gt;&gt; on FRP, and I first wanted to start with simple console based FRP, e.g.<br>
&gt;&gt; making a little text adventure game, where the input/choices of the user<br>
&gt;&gt; might be parsed ala parsec, using monadic style, applicative style, and<br>
&gt;&gt; arrows, and then doing the same with FRP frameworks like Yampa, Elera,<br>
&gt;&gt; Reactive, etc...<br>
&gt;&gt; After that I would start writing tutorials that use OpenGL, making some<br>
&gt;&gt; very simple games, again with the above approaches, and ending with a<br>
&gt;&gt; conversion of a very old game of mine (Zarathrusta written in assembler from<br>
&gt;&gt; 1991, which was based on Thrust from 1986, converted by myself in C++ to<br>
&gt;&gt; PocketPC as G-Pod, and so I would like to make a version in Haskell that<br>
&gt;&gt; runs on the iPhone :-)<br>
&gt;&gt; This of course is a lot of work, and I would like to put this on the<br>
&gt;&gt; Haskell wiki or a blog or something, so others can contribute and comment. I<br>
&gt;&gt; would like to show real examples that explain the shortcomings of the FRP<br>
&gt;&gt; approaches, because now this is still a bit blurry to me.<br>
&gt;&gt;<br>
&gt;&gt; On Wed, Aug 19, 2009 at 5:43 PM, David Leimbach &lt;<a href="mailto:leimy2k@gmail.com" target="_blank">leimy2k@gmail.com</a>&gt; wrote:<br>
&gt;&gt;&gt;<br>
&gt;&gt;&gt; This Monad you&#39;ve created is quite excellent.  I was trying to do<br>
&gt;&gt;&gt; something like this about a year ago, to make the input and output handling<br>
&gt;&gt;&gt; of an interactive bowling score card work nicely.  I kept running into<br>
&gt;&gt;&gt; issues, and did not believe that seq was going to do the trick.  Nice work!<br>
&gt;&gt;&gt; This is a very useful monad I think, it could be called &quot;Prompter&quot; or<br>
&gt;&gt;&gt; something to that effect.<br>
&gt;&gt;&gt; Do you mind if I use it in some of my code?<br>
&gt;&gt;&gt; Dave<br>
&gt;&gt;&gt;<br>
&gt;&gt;&gt; On Wed, Aug 19, 2009 at 8:42 AM, Peter Verswyvelen &lt;<a href="mailto:bugfact@gmail.com" target="_blank">bugfact@gmail.com</a>&gt;<br>
&gt;&gt;&gt; wrote:<br>
&gt;&gt;&gt;&gt;<br>
&gt;&gt;&gt;&gt; LOL. Maybe we should have that coffee together ;-) at least virtually!<br>
&gt;&gt;&gt;&gt; On Wed, Aug 19, 2009 at 5:39 PM, David Leimbach &lt;<a href="mailto:leimy2k@gmail.com" target="_blank">leimy2k@gmail.com</a>&gt;<br>
&gt;&gt;&gt;&gt; wrote:<br>
&gt;&gt;&gt;&gt;&gt;<br>
&gt;&gt;&gt;&gt;&gt; Argh... I too have been up too late :-).  I edited THE WRONG FILE!  No<br>
&gt;&gt;&gt;&gt;&gt; wonder your change didn&#39;t take effect!  :-/<br>
&gt;&gt;&gt;&gt;&gt; Time for coffee I suppose.<br>
&gt;&gt;&gt;&gt;&gt;<br>
&gt;&gt;&gt;&gt;&gt; On Wed, Aug 19, 2009 at 8:38 AM, David Leimbach &lt;<a href="mailto:leimy2k@gmail.com" target="_blank">leimy2k@gmail.com</a>&gt;<br>
&gt;&gt;&gt;&gt;&gt; wrote:<br>
&gt;&gt;&gt;&gt;&gt;&gt;<br>
&gt;&gt;&gt;&gt;&gt;&gt; This doesn&#39;t seem to be working for me interactively though on a Mac.<br>
&gt;&gt;&gt;&gt;&gt;&gt;  I still get &quot;Welcome&quot; before I&#39;ve entered text.<br>
&gt;&gt;&gt;&gt;&gt;&gt;<br>
&gt;&gt;&gt;&gt;&gt;&gt; On Wed, Aug 19, 2009 at 8:25 AM, Peter Verswyvelen &lt;<a href="mailto:bugfact@gmail.com" target="_blank">bugfact@gmail.com</a>&gt;<br>
&gt;&gt;&gt;&gt;&gt;&gt; wrote:<br>
&gt;&gt;&gt;&gt;&gt;&gt;&gt;<br>
&gt;&gt;&gt;&gt;&gt;&gt;&gt; I fixed it myself but it&#39;s really tricky :-)<br>
&gt;&gt;&gt;&gt;&gt;&gt;&gt; <a href="http://hpaste.org/fastcgi/hpaste.fcgi/view?id=8316#a8330" target="_blank">http://hpaste.org/fastcgi/hpaste.fcgi/view?id=8316#a8330</a><br>
&gt;&gt;&gt;&gt;&gt;&gt;&gt; The idea is, that when the input is requested, the output that is<br>
&gt;&gt;&gt;&gt;&gt;&gt;&gt; then generated must be in sync with the input.<br>
&gt;&gt;&gt;&gt;&gt;&gt;&gt;<br>
&gt;&gt;&gt;&gt;&gt;&gt;&gt; inp = S $ \s i -&gt; let r = (s `D.append` (i `seq` D.empty), head i) in<br>
&gt;&gt;&gt;&gt;&gt;&gt;&gt; (tail i, r)<br>
&gt;&gt;&gt;&gt;&gt;&gt;&gt;<br>
&gt;&gt;&gt;&gt;&gt;&gt;&gt;<br>
&gt;&gt;&gt;&gt;&gt;&gt;&gt; I first had<br>
&gt;&gt;&gt;&gt;&gt;&gt;&gt;<br>
&gt;&gt;&gt;&gt;&gt;&gt;&gt; inp = S $ \s i -&gt; let r = (i `seq` s, head i) in (tail i, r)<br>
&gt;&gt;&gt;&gt;&gt;&gt;&gt;<br>
&gt;&gt;&gt;&gt;&gt;&gt;&gt; But that was too eager, since i syncs the input not with the output,<br>
&gt;&gt;&gt;&gt;&gt;&gt;&gt; but with the function that will generate the output.<br>
&gt;&gt;&gt;&gt;&gt;&gt;&gt;<br>
&gt;&gt;&gt;&gt;&gt;&gt;&gt;<br>
&gt;&gt;&gt;&gt;&gt;&gt;&gt;<br>
&gt;&gt;&gt;&gt;&gt;&gt;&gt;<br>
&gt;&gt;&gt;&gt;&gt;&gt;&gt;<br>
&gt;&gt;&gt;&gt;&gt;&gt;&gt;<br>
&gt;&gt;&gt;&gt;&gt;&gt;&gt;<br>
&gt;&gt;&gt;&gt;&gt;&gt;&gt; Okay, now I can sleep again :-)<br>
&gt;&gt;&gt;&gt;&gt;&gt;&gt;<br>
&gt;&gt;&gt;&gt;&gt;&gt;&gt;<br>
&gt;&gt;&gt;&gt;&gt;&gt;&gt;<br>
&gt;&gt;&gt;&gt;&gt;&gt;&gt;<br>
&gt;&gt;&gt;&gt;&gt;&gt;&gt;<br>
&gt;&gt;&gt;&gt;&gt;&gt;&gt;<br>
&gt;&gt;&gt;&gt;&gt;&gt;&gt;<br>
&gt;&gt;&gt;&gt;&gt;&gt;&gt;<br>
&gt;&gt;&gt;&gt;&gt;&gt;&gt;<br>
&gt;&gt;&gt;&gt;&gt;&gt;&gt;<br>
&gt;&gt;&gt;&gt;&gt;&gt;&gt; On Wed, Aug 19, 2009 at 5:12 PM, Peter Verswyvelen<br>
&gt;&gt;&gt;&gt;&gt;&gt;&gt; &lt;<a href="mailto:bugfact@gmail.com" target="_blank">bugfact@gmail.com</a>&gt; wrote:<br>
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;<br>
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; Thanks, but that doesn&#39;t really matter in my example, my code is<br>
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; just buggy, and I&#39;m not sure why. For example if I change my test function<br>
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; so that it outputs lines only, then it still prints Welcome first before<br>
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; asking for input.<br>
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; See e.g. <a href="http://hpaste.org/fastcgi/hpaste.fcgi/view?id=8316#a8328" target="_blank">http://hpaste.org/fastcgi/hpaste.fcgi/view?id=8316#a8328</a><br>
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; On Wed, Aug 19, 2009 at 5:00 PM, David Leimbach &lt;<a href="mailto:leimy2k@gmail.com" target="_blank">leimy2k@gmail.com</a>&gt;<br>
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; wrote:<br>
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;<br>
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; Try LineBuffering.<br>
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; I do linewise stuff with interact a lot.  You&#39;ll find stuff like<br>
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; unlines . lines<br>
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; may help too.  In fact I just wrote a blog post about this.<br>
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; <a href="http://leimy9.blogspot.com" target="_blank">http://leimy9.blogspot.com</a><br>
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; I&#39;m trying to write some interactive code to automate working with<br>
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; serial console controlled power strips, so I need to either use Expect<br>
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; (yuck) or do my own thing.<br>
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; Dave<br>
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;<br>
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; On Wed, Aug 19, 2009 at 7:35 AM, Peter Verswyvelen<br>
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; &lt;<a href="mailto:bugfact@gmail.com" target="_blank">bugfact@gmail.com</a>&gt; wrote:<br>
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;<br>
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; Apparently this particular example happens to work on Mac and<br>
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; Linux because of different buffering (thanks Martijn for the help!)<br>
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; To make sure we have no buffering at all, the main function should<br>
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; be:<br>
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;<br>
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; main = do<br>
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;   hSetBuffering stdout NoBuffering<br>
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;   hSetBuffering stdin NoBuffering<br>
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;   test<br>
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;<br>
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; Now I think it should also be incorrect on Unix systems.<br>
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; I guess the way I&#39;m concatenating the strings is not correct, not<br>
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; sure.<br>
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; I would like to use a graphical tool to show the graph reduction<br>
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; step by step, to get a better understanding of the laziness &amp; strictness.<br>
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; Does such a tool exist? I know people often say this is not usable because<br>
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; the amount of information is too much, but I used to be an assembly language<br>
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; programmer so I still would like to give it a try :-)<br>
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;<br>
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;<br>
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; On Wed, Aug 19, 2009 at 1:07 PM, Peter Verswyvelen<br>
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; &lt;<a href="mailto:bugfact@gmail.com" target="_blank">bugfact@gmail.com</a>&gt; wrote:<br>
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;<br>
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; In an attempt to get a deeper understanding of several monads<br>
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; (State, ST, IO, ...) I skimmed over some of the research papers (but didn&#39;t<br>
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; understand all of it, I lack the required education) and decided to write a<br>
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; little program myself without using any prefab monad instances that should<br>
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; mimic the following:<br>
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; main = do<br>
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;   putStrLn &quot;Enter your name:&quot;<br>
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;   x &lt;- getLine<br>
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;   putStr &quot;Welcome &quot;<br>
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;   putStrLn x<br>
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;   putStrLn &quot;Goodbye!&quot;<br>
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; But instead of using IO, I wanted to make my own pure monad that<br>
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; gets evaluated with interact, and does the same.<br>
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; However, I get the following output:<br>
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; Enter your name:<br>
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; Welcome ......<br>
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; So the Welcome is printed too soon.<br>
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; This is obvious since my monad is lazy, so I tried to put a seq<br>
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; at some strategic places to get the same behavior as IO. But I completely<br>
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; failed doing so, either the program doesn&#39;t print anything and asks input<br>
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; first, or it still prints too much output.<br>
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; Of course I could just use ST, State, transformers, etc, but this<br>
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; is purely an exercise I&#39;m doing.<br>
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; So, I could re-read all papers and look in detail at all the<br>
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; code, but maybe someone could help me out where to put the seq or what to do<br>
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; :-)<br>
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; The code is at <a href="http://hpaste.org/fastcgi/hpaste.fcgi/view?id=8316" target="_blank">http://hpaste.org/fastcgi/hpaste.fcgi/view?id=8316</a><br>
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; Oh btw, the usage of DList here might not be needed; intuitively<br>
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; it felt like the correct thing to do, but when it comes to Haskell, my<br>
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; intuition is usually wrong ;-)<br>
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; Thanks a lot,<br>
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; Peter Verswyvelen<br>
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;<br>
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;<br>
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; _______________________________________________<br>
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; Haskell-Cafe mailing list<br>
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; <a href="mailto:Haskell-Cafe@haskell.org" target="_blank">Haskell-Cafe@haskell.org</a><br>
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; <a href="http://www.haskell.org/mailman/listinfo/haskell-cafe" target="_blank">http://www.haskell.org/mailman/listinfo/haskell-cafe</a><br>
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;<br>
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;<br>
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;<br>
&gt;&gt;&gt;&gt;&gt;&gt;&gt;<br>
&gt;&gt;&gt;&gt;&gt;&gt;<br>
&gt;&gt;&gt;&gt;&gt;<br>
&gt;&gt;&gt;&gt;<br>
&gt;&gt;&gt;<br>
&gt;&gt;<br>
&gt;<br>
&gt;<br>
&gt; _______________________________________________<br>
&gt; Haskell-Cafe mailing list<br>
&gt; <a href="mailto:Haskell-Cafe@haskell.org" target="_blank">Haskell-Cafe@haskell.org</a><br>
&gt; <a href="http://www.haskell.org/mailman/listinfo/haskell-cafe" target="_blank">http://www.haskell.org/mailman/listinfo/haskell-cafe</a><br>
&gt;<br>
&gt;<br>
</div></div></blockquote></div><br></div>
</div></div></blockquote></div><br>