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

Jonathan Cast jonathanccast at fastmail.fm
Thu Jan 1 17:11:45 EST 2009


On Thu, 2009-01-01 at 17:03 -0500, David Menendez wrote:
> On Thu, Jan 1, 2009 at 4:30 PM, Jonathan Cast <jonathanccast at fastmail.fm> wrote:
> > On Thu, 2009-01-01 at 13:44 -0700, Luke Palmer wrote:
> >>
> >> 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",
> >
> > Is it?  By the second monad law, (>>= return) is required to be strict.
> > return must not be strict, as observed above.  Are there monads which
> > satisfy both laws, but have undefined >>= f /= undefined, for some f?  I
> > suspect (although I don't seem to have the source on my computer atm)
> > that Control.Monad.State.{Lazy,Strict} both cheat on the second monad
> > law anyway, though...
> 
> How about the Identity monad?
> 
> ghci> (return undefined :: Identity Char) `seq` ()
> *** Exception: Prelude.undefined
> ghci> runIdentity $ undefined >>= \_ -> return ()
> ()
> 
> "return" is strict and (>>=) is non-strict.

Sure, that works.

jcc




More information about the Haskell-Cafe mailing list