# [Haskell-cafe] Stupid question #852: Strict monad

David Menendez dave at zednenem.com
Thu Jan 1 16:19:02 EST 2009

```On Thu, Jan 1, 2009 at 3:44 PM, Luke Palmer <lrpalmer at gmail.com> wrote:
> On Thu, Jan 1, 2009 at 1:31 PM, David Menendez <dave at zednenem.com> wrote:
>>
>> 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.

Interesting. I hadn't heard that name for it before.

In my own monad library, I called it CPS, since it transforms a monad
into continuation-passing style. It's handy for monads with an
expensive (>>=), as discussed in Janis Voigtlander's "Asymptotic
Improvement of Computations over Free Monads".

> 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?

That's my understanding.

As a consequence, strict monads in Haskell also have the property that
"return undefined" never equals "undefined". Otherwise, they wouldn't
satisfy the monad laws.

>> 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.

I made that mistake myself, once. It doesn't help that the
documentation just says "Lazy state monads" and "Strict state monads"
without any further explanation.

--
Dave Menendez <dave at zednenem.com>
<http://www.eyrie.org/~zednenem/>
```

More information about the Haskell-Cafe mailing list