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

Heinrich Apfelmus apfelmus at quantentunnel.de
Tue Jun 15 16:17:22 EDT 2010


Sebastian Fischer wrote:
>> Holger Siegel wrote: 
>>
>>> orElse :: CMaybe a a -> CMaybe a a -> CMaybe r a
>>> CMaybe ca `orElse` CMaybe cb = CMaybe (\k -> (ca return `mplus` cb
>>> return) >>= k)
> 
> I still don't understand why it is impossible to provide `orElse` with
> the original type. I will think more about the reason you gave.

The reason is that you have chosen the "wrong" type for your
continuation monad; it should be

  newtype CMaybe a = CMaybe (forall r. (a -> Maybe r) -> Maybe r)


Personally, I recommend to stop thinking about continuations altogether
and instead use the approach I've outlined in "The Operational Monad
Tutorial"

  http://apfelmus.nfshost.com/articles/operational-monad.html

to define and think about monads. In particular, performing the
refunctionalization I mentioned in the subsection "Connection with the
Continuation Monad" shows that the "right" type should indeed contain a
 forall r .



Regards,
Heinrich Apfelmus

--
http://apfelmus.nfshost.com



More information about the Haskell-Cafe mailing list