haskell-cafe@haskell.org
[Top] [All Lists]

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

Subject: [Haskell-cafe] Re: Different choice operations in a continuation monad
From: Sebastian Fischer
Date: Fri, 18 Jun 2010 18:22:35 +0200
Edward Kmett wrote:
Sebastian Fischer wrote:
Heinrich Apfelmus wrote:
newtype CMaybe a = CMaybe (forall r. (a -> Maybe r) -> Maybe r)
Yes, with this type `orElse` has the same type as `mplus`, which is very nice.

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.

I encounter the Codensity type constructor every now and then. I used it to Reinvent Haskell Backtracking, learned about implementing a state monad with a reader monad wrapped in Codensity when implementing Lazy Nondeterministic Programming and Janis Voigtländer also used it to improve the asymptotics of free monads.

I wonder whether for every monad `m` and `a :: Codensity m a`

    getCodensity a f  =  getCodensity a return >>= f

Is this true? Why (not)?

Another encoding of Maybe is through Yoneda Endo

Interesting. I did not yet encounter Yoneda in my own code but will watch out in the future.

Sebastian

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



_______________________________________________
Haskell-Cafe mailing list
Haskell-Cafe@xxxxxxxxxxx
http://www.haskell.org/mailman/listinfo/haskell-cafe

<Prev in Thread] Current Thread [Next in Thread>