[Haskell-cafe] Irrefutable pattern love and new regex engine.

Ryan Ingram ryani.spam at gmail.com
Tue Jan 22 17:09:05 EST 2008

> > On Tue, 2008-01-22 at 11:55 -0500, Michael Speer wrote:
> > >       rexn ns pps = let ( ~( xs , rps ) ,
> > >                           ~( ~( nxs ) ,
> > >                              ~( rxs , rrps ) ) ) = ( exn nxs pps ,

> Not one of the lazy marks was required in the current version.

Pattern bindings via let are always irrefutable; the ~s here are all redundant.

This took me a little while to figure out; I was browsing
Control.Monad.State.Lazy and trying to figure out how it was different
than Control.Monad.State.Strict; they look almost exactly the same.
But then I noticed code that looked like the following:

m >>= f = State $ \s ->
    case runState m s of (a, s') -> runState (f a) s'

m >>= f = State $ \s ->
    let (a, s') = runState m s in runState (f a) s'

The strict code deconstructs the pair in a case expression, so
"runState m s" will always get evaluated at least enough to know that
it is going to return a pair and not _|_.

The lazy code immediately calls (f a) and m may not get evaluated at
all if f is lazy and doesn't access the state.

  -- ryan

More information about the Haskell-Cafe mailing list