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.
On Fri, Aug 21, 2009 at 3:29 PM, Peter Verswyvelen<bugfact@gmail.com> wrote:
> On Fri, Aug 21, 2009 at 6:53 PM, David Menendez <dave@zednenem.com> wrote:
>>
>> Some people dislike seq because it lets you force strictnessYou can make a pretty good argument that programs which rely on
>> 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!
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.