[Haskell-cafe] Type classes

Johannes Gerer kuerzn at gmail.com
Tue May 28 16:42:35 CEST 2013


Thank you for the comments on the first part. While one can argue
about
the different meanings of powerful and flexible here, that's not the
question. The question is, about showing "A => B" using wrappers like
Kleisli or Cokleisli:

I can use Kleisli to show that a Monad can do everything an
ArrowApply
can do:

Instance Monad m => ArrowApply (Kleisli m)

By the same argument, could'nt I say, that any type class (call it
AnyClass) can do everything a Monad can:

instance AnyClass m => Monad (Cokleilsi m ())




Another way to look at the question:

An Applicative lets you build static trees using the available
combinators. Arrows let you combine effectful computations into
networks
or graphs and monad even more complex things. But again Cokleilsi
crashes the party, as it gives you the Monad's combinators for any
type
and consequently you can build almost anything. I do not understand,
what this tells me!

Johannes

On Tue, May 28, 2013 at 3:04 PM, Anton Kholomiov
<anton.kholomiov at gmail.com> wrote:
> I don't understand the final part of the question but here are some comments
> for the first part.
>
> I don't like the phrase:
>
>
>> the more powerfull a class is, the more fleixblility you have for
>> combining them to complex programs
>
> powerfull, more flexibility, complex programs -- are not so precise terms.
>
> A => B
>
> means that B can do everything that A can do and more (methods that are
> specific to B). So if type is in B we can use all A's methods with it. Does
> it make B more powerful or more flexible? Is Applicative less powerful than
> a Monad? It depends on the program. If we don't ever need the B's specific
> operations they will confuse us all the time. We are going to end up with
> more complex program but not a better one. there are cases when Applicative
> code is much better than a monadic one.
>
> Anton
>
>
>
> 2013/5/28 Johannes Gerer <kuerzn at gmail.com>
>>
>> Dear Haskellers,
>>
>> While trying to understand the interconnection and hierarchy behind
>> the important typeclasses, I stumbled upon the following question that
>> I am not able to answer:
>>
>> There seems to be a hierachy of the type classes, in the sense, that
>> the more powerfull a class is, the more fleixblility you have for
>> combining them to complex programs. (Functor -> Applicative ->
>> Arrow[Choice,Plus,Apply,..] -> Monad). It was nice to read in the
>> Typeclassopedia, that ArrowApply and Monad are equivalent, which is
>> shown by deriving two instances from each other:
>>
>> instance Monad m => ArrowApply (Kleisli m)
>> instance ArrowApply a => Monad (a anyType)
>>
>> The logic seems to be, that if I can derive from every instance of
>> class A an instance of class B, then A is more powerfull than B and
>> (in general) it is easier to be of class B than of class A (e.g. more
>> types can be made Applicatives, than Monads)
>>
>> So far, I think I can follow. But what really hit me was the Cokleisli
>> type. Using it and the logic from above, I can show that ANY type
>> class is more (or equally) powerfull than the Monad:
>>
>> instance AnyClass m => Monad (Cokleilsi m anyType)
>>
>> I know this makes no sense, but where is the fallacy? Why even bother
>> with the above derivation, if any type class can be made into a monad?
>>
>> I can see, that the Monad instance from above does not really
>> transform the type "a", but instead simply fix its first argument. But
>> then on the other hand, the ArrowApply Instance does transform the "m"
>> type (in a way similar to Cokleisli). If attention needs to be paid to
>> the details, then what are they and why did they not matter above?
>>
>> Thanks,
>>
>> Johannes
>>
>> _______________________________________________
>> Haskell-Cafe mailing list
>> Haskell-Cafe at haskell.org
>> http://www.haskell.org/mailman/listinfo/haskell-cafe
>
>



More information about the Haskell-Cafe mailing list