logo       

Re: Initial (term) algebra for a state monad: msg#00051

lang.haskell.cafe

Subject: Re: Initial (term) algebra for a state monad

In article <20050105201737.s24g48oo0w8w4occ@xxxxxxxxxxxxxxxxxxx>,
ajb@xxxxxxxxxxx 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


<Prev in Thread] Current Thread [Next in Thread>
Google Custom Search

News | FAQ | advertise