[Haskell-cafe] Re: Initial (term) algebra for a state monad

Ashley Yakeley ashley at semantic.org
Thu Jan 6 01:53:59 EST 2005

In article <20050105201737.s24g48oo0w8w4occ at webmail.spamcop.net>,
 ajb at spamcop.net wrote:

> Logical if-then-else has this signature:
>     mif :: LogicT m a -> (a -> LogicT m b) -> LogicT m b -> LogicT m b
> Intuitively, this takes three arguments: the "condition", the "then"
> case and the "else" case.  This obeys the "obvious" laws of if-then-else:
>     mif (return a) t e = t a
>     mif (mzero) t e = e
>     mif (mif c t' e') t e = mif c (\x -> mif (t' x) t e) (mif e' t e)
> plus the "soft cut" law:
>     mif (return a `mplus` m) t e = t a `mplus` (m >>= t)
> The soft cut law is the one that stuffs up the more obvious candidates
> for the passed context, because of this non-identity:
>     mif (c1 `mplus` c2) t e /= mif c1 t e `mplus` mif c2 t e

Is mif reducible to some "melse" with

  mif c t e = do
    ma <- (c >>= return . Just) `melse` (return Nothing)
    case ma of
       Just a -> t a
       Nothing -> e


Ashley Yakeley, Seattle WA

More information about the Haskell-Cafe mailing list