On Fri, Aug 21, 2009 at 3:29 PM, Peter Verswyvelen<bugf...@gmail.com> wrote:
> On Fri, Aug 21, 2009 at 6:53 PM, David Menendez <d...@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 <d...@zednenem.com>
<http://www.eyrie.org/~zednenem/>
_______________________________________________
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe

Reply via email to