[Haskell-cafe] Re: Where do I put the seq?

Peter Verswyvelen bugfact at gmail.com
Fri Aug 21 16:32:36 EDT 2009


typo, "sees the input" => "must enter the input"
On Fri, Aug 21, 2009 at 10:28 PM, Peter Verswyvelen <bugfact at gmail.com>wrote:

> The question is, in this case when the user gets to see a bit too much of
> the output before he sees the input, if that really qualifies as an
> "incorrect" program. It's a bit in the gray zone I guess. You could even
> argue that it's a feature that input and output are not really synched, they
> are lazy, input is only read when evaluated; if you want to sync them, use a
> syncIO action ;-) no that's silly of course.
> Oh well, thanks for all the input, this was very informative for me hacker.
>
> On Fri, Aug 21, 2009 at 10:20 PM, David Menendez <dave at zednenem.com>wrote:
>
>> On Fri, Aug 21, 2009 at 3:29 PM, Peter Verswyvelen<bugfact at gmail.com>
>> wrote:
>> > On Fri, Aug 21, 2009 at 6:53 PM, David Menendez <dave at zednenem.com>
>> wrote:
>> >>
>> >> Some people dislike seq because it lets you force strictness
>> >> in cases where pattern matching cannot (like function arguments), but
>> >> hardly anyone objects to pattern matching.
>> >
>> > Ah so it's subjective. Okay, it's sometimes hard for a newbie to find
>> the
>> > "truth" when several experts contradict eachother. Because often when
>> people
>> > claim something here, they have very good reasons for it, reasons that
>> are
>> > not obvious at all to your average newbie!
>>
>> You can make a pretty good argument that programs which rely on
>> strictness for correctness (as opposed to space/time issues) are
>> risky, because it's easy to get things wrong by accident. Internally,
>> the IO monad may rely on strictness to make sure things happen in the
>> proper sequence, but all of that is hidden so we don't have to worry
>> about things like output happening too early because we haven't
>> examined some input yet.
>>
>> This is also why some people object to getContents.
>>
>>
>> For laughs, here's an example of IO code written using Haskell's old
>> stream-based IO system, taken from "A History of Haskell":
>>
>> main :: Behaviour
>> main ~(Success : ~((Str userInput) : ~(Success : ~(r4 : _))))
>>  = [ AppendChan stdout "enter filename\n",
>>    ReadChan stdin,
>>    AppendChan stdout name,
>>    ReadFile name,
>>    AppendChan stdout
>>    (case r4 of
>>      Str contents -> contents
>>      Failure ioerr -> "can’t open file")
>>    ] where (name : _) = lines userInput
>>
>>
>> It has a certain elegant purity, but I'm glad I don't have to use it.
>>
>> --
>> Dave Menendez <dave at zednenem.com>
>> <http://www.eyrie.org/~zednenem/>
>>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20090821/2a64b876/attachment.html


More information about the Haskell-Cafe mailing list