[Haskell-cafe] questions on lazy pattern, StateT monad
zednenem at psualum.com
Wed Nov 23 20:08:50 EST 2005
Wolfgang Jeltsch writes:
> If we use an implementation of State *without lazy patterns*, it
> becomes something like this:
> \s -> case next s of
> (x,s') -> case everyting s' of
> (xs,s'') -> ((x : xs),s'')
> Note that I used case expressions to realize strict patterns because
> pattern binding in let expressions is implicitely lazy.
> Now lets apply the function denoted by the last code fragment to some
> initial state and try to extract just the first element of the
> output. In order to do so we have to take the result of the function
> and match it against ((x : _),_). Especially, we have to reduce the
> pair, i.e., we have to make sure that it's really an application of
> (,) and not _|_.
Would the lazy pattern match be equivalent to using fst and snd?
\s -> case next s of
p1 -> case everything (snd p1) of
p2 -> (fst p1 : fst p2, snd p2)
David Menendez <zednenem at psualum.com> | "In this house, we obey the laws
<http://www.eyrie.org/~zednenem> | of thermodynamics!"
More information about the Haskell-Cafe