On Wed, Jun 16, 2010 at 9:11 AM, Sebastian Fischer <span dir="ltr"><<a href="mailto:sebf@informatik.uni-kiel.de">sebf@informatik.uni-kiel.de</a>></span> wrote:<br><div class="gmail_quote"><blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">
<br>
Heinrich Apfelmus wrote:<div class="im"><br>
<blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">
Sebastian Fischer wrote:<br>
<blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">
I still don't understand why it is impossible to provide `orElse` with<br>
the original type. I will think more about the reason you gave.<br>
</blockquote>
<br>
The reason is that you have chosen the "wrong" type for your<br>
continuation monad; it should be<br>
<br>
newtype CMaybe a = CMaybe (forall r. (a -> Maybe r) -> Maybe r)<br>
</blockquote>
<br></div>
Yes, with this type `orElse` has the same type as `mplus`, which is very nice.<br></blockquote><div><br>This type is the same as "Codensity Maybe" using category-extras which is a 'bit bigger than Maybe'. (To see why, figure out how Codensity Reader is isomorphic to State!) This is the wiggle room you're using to get the distributive operator.<br>
<br>Another encoding of Maybe is through Yoneda Endo<br><br>newtype YEMaybe a = YEMaybe (forall r. (a -> r) -> r -> r)<br><br>and it is isomorphic to the original Maybe type, with its same limitations. A definition that is equivalent to this is in my monad-ran package, along with definitions CPS/right-kan-extension-based definitions for other common monads, including the MTL, IO, ST s, and STM.<br>
<br>-Edward Kmett<br></div></div>