[Haskell-cafe] Stupid question #852: Strict monad
Luke Palmer
lrpalmer at gmail.com
Thu Jan 1 15:44:02 EST 2009
On Thu, Jan 1, 2009 at 1:31 PM, David Menendez <dave at zednenem.com> wrote:
> 2009/1/1 Luke Palmer <lrpalmer at gmail.com>:
> >
> > So that's the answer: there already is a Strict monad. And an attempt to
> > make a lazier one strict just results in breaking the monad laws.
>
> There is at least one transformer that will make a strict monad out of
> a non-strict monad.
>
> newtype CPS m a = CPS { unCPS :: forall b. (a -> m b) -> m b }
I have heard this called the "codensity monad" (and it appears under that
name in category-extras). Good observation.
In my reply I missed the important consideration of the strictness of (>>=),
irrsepective of the values. While you can not force values to be strict in
a monad without breaking a law, (>>=) is "up for grabs", and that's what
people are referring to when they refer to strict and lazy monads.
So I guess "strict monad" means (>>= f) is strict for all f. Right?
Luke
> > There's another answer though, regarding your question for why we don't
> just
> > use StrictT State instead of a separate State.Strict. This message is
> > already too long, and I suspect this will be the popular reply anyway,
> but
> > the short answer is that Strict State is called that because it is strict
> in
> > its state, not in its value.
>
> No, Control.Monad.State.Strict and Control.Monad.State.Lazy never
> force evaluation of their states.
>
> Control.Monad.State.Strict> evalState (put undefined) '0'
> ()
My mistake.
Luke
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20090101/c603f48e/attachment.htm
More information about the Haskell-Cafe
mailing list