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

2010-06-22 Thread Sebastian Fischer
On Jun 19, 2010, at 1:48 PM, Heinrich Apfelmus wrote: In my code, mzero is indeed an identity for orElse [...] The observation is any action can be brought into one of the forms mzero return a `mplus` return b `mplus` ... which corresponds to the list type [a] . Ok that makes sense

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

2010-06-22 Thread Heinrich Apfelmus
Sebastian Fischer wrote: Heinrich Apfelmus wrote: [...] you can implement your type as newtype CMaybe a = CMaybe { forall b . (a - [b]) - [b] } Yes. For me it was interesting to see how far we get by wrapping `Maybe` in `Codensity`: we get more than `Maybe` but not as much as `[]`.

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

2010-06-19 Thread Heinrich Apfelmus
Sebastian Fischer wrote: Consider the given Definitions of `CMaybe r a` with `fromCMaybe`, `mzero`, `mplus`, `orElse`, and additionally: toCMaybe :: Maybe a - CMaybe r a toCMaybe a = CMaybe (\k - a = k) getCMaybe :: CMaybe r a - (a - Maybe r) - Maybe r getCMaybe (CMaybe

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

2010-06-18 Thread Sebastian Fischer
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

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

2010-06-18 Thread Heinrich Apfelmus
Heinrich Apfelmus wrote: Sebastian Fischer wrote: For example, the implementation of `callCC` does not type check with your changed data type. [snip] As for the interaction: what should ((callCC ($ 0) mzero) `orElse` return 2) = return . (+3) be? If the scope of callCC should

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

2010-06-18 Thread Heinrich Apfelmus
Sebastian Fischer wrote: 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

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

2010-06-18 Thread David Menendez
On Fri, Jun 18, 2010 at 12:44 PM, Heinrich Apfelmus apfel...@quantentunnel.de wrote: Sebastian Fischer wrote: 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

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

2010-06-18 Thread Heinrich Apfelmus
David Menendez wrote: Heinrich Apfelmus wrote: Sebastian Fischer wrote: I wonder whether for every monad `m` and `a :: Codensity m a` getCodensity a f = getCodensity a return = f Is this true? Why (not)? It's not true. a = Codensity $ \x - Just 42 f = return . (+1)

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

2010-06-18 Thread Sebastian Fischer
On Jun 18, 2010, at 8:55 PM, Heinrich Apfelmus wrote: I wonder whether for every monad `m` and `a :: Codensity m a` getCodensity a f = getCodensity a return = f Is this true? Why (not)? It's not true. What a pity! An example that is not generic in the base monad m , i.e. that

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

2010-06-16 Thread Sebastian Fischer
Heinrich Apfelmus wrote: Sebastian Fischer wrote: 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

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

2010-06-16 Thread Heinrich Apfelmus
Sebastian Fischer wrote: Heinrich Apfelmus wrote: 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) Yes, with this type `orElse` has the same type as `mplus`, which is very nice.

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

2010-06-16 Thread Edward Kmett
On Wed, Jun 16, 2010 at 9:11 AM, Sebastian Fischer s...@informatik.uni-kiel.de wrote: Heinrich Apfelmus wrote: Sebastian Fischer wrote: 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

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

2010-06-15 Thread Heinrich Apfelmus
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