[Haskell] standard monads and strictness
Wolfgang Jeltsch
wolfgang at jeltsch.net
Mon May 30 08:47:00 EDT 2005
Hello,
I looked at the implementation of Writer, WriterT, State, StateT, RWS and
RWST. They all use tuples to knit the result with the written value and/or
state.
Now, there seems to be an inconsistency between the transformer and
non-transformer variants concerning strictness. The non-transformer variants
(Writer, State and RWS) use let binding to extract the tuple components while
the transformer variants use pattern matching in do expressions. So the
expression
evalState (undefined >> return ()) ()
yields () while
evalStateT (undefined >> return ()) ()
yields _|_ for any inner monad. Is there any good reason for this behaviour?
Since the tuples are only used for knitting together several values, the most
logical solution would be to use unboxed tuples in all of the above cases, in
my opinion. If this is not feasible, we probably should use lazy pattern
matching with the transformer versions.
Best wishes,
Wolfgang
More information about the Haskell
mailing list