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