[Haskell-cafe] questions on lazy pattern, StateT monad

Fan Wu wufan9418 at gmail.com
Thu Nov 24 15:37:01 EST 2005

> They are useful not only in conjunction with infinite data structures.  Take
> my example state transformer "everything" and modify it so that it calls next
> exactly two times, not infinitely many times, and outputs a pair of the
> outputs of the two next invocations.
> Now let's assume you use this pair in a context where only its first component
> is used.  Without lazy patterns, next would be invoked two times although it
> need to be invoked only one time.  So you might have unnecessary evaluation.
> And you might have something even worse.  Let's assume that when we apply the
> function making up next on the output state of the first next invocation then
> we get _|_.  Without lazy patterns, just using the output of the first next
> invocation would result in your program aborting.  Of course, it shouldn't do
> so.

This is a good example! But now I got the impression that pattern
match failure could happen in many places, so unless you want it to
fail loudly, you shall always use lazy pattern?


More information about the Haskell-Cafe mailing list