[Haskell-cafe] Different choice operations in a continuation monad

Sebastian Fischer sebf at informatik.uni-kiel.de
Tue Jun 15 12:11:30 EDT 2010


Hello Holger,

>> Can you define an associative operation
>>
>>   orElse :: CMaybe r a -> CMaybe r a -> CMaybe r a
>>
>> with identity `mzero` that satisfies the cancellation law?
>
> No, because that function would need to cancel values of type a, but  
> the arguments of type (CMaybe r a) can only compute values of type r.

I'm afraid, I don't understand.

> But you can define
>
> orElse :: CMaybe a a -> CMaybe a a -> CMaybe r a
> CMaybe ca `orElse` CMaybe cb = CMaybe (\k -> (ca return `mplus` cb  
> return) >>= k)

Good point.

But with this restricted type `orElse` is less useful. For example,  
one cannot compute

     fromCMaybe ((return False `orElse` return True) >>= guard)

because there, the arguments of `orElse` are of type `CMaybe () Bool`.

Cheers,
Sebastian

P.S.

  > fromCMaybe :: CMaybe a a -> Maybe a
  > fromCMaybe (CMaybe ca) = ca Just


-- 
Underestimating the novelty of the future is a time-honored tradition.
(D.G.)





More information about the Haskell-Cafe mailing list