IO and Cont as monads

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

IO and Cont as monads

Burak Ekici
Dear List,

I am quite new in Haskell's categorical manner of programming. However I have enough knowledge in Category Theory.
I want to ask a question, maybe very well-known one by some of you, about monads of Haskell.

For the type constructors like Maybe and [], I managed to prove that together with 2 natural transformations (bind + return), both of these triples construct a monad. But when I try to prove that IO and Cont type constructors with the same natural transformations (bind + return) are monads as well, it was failed.

Here my question is: Is there anyone who knows how to prove that IO and Cont are monads with satisfing following properties:

  1. join . fmap join = join . join
  2. join . fmap return = join . return = id
  3. return . f = fmap f . return
  4. join . fmap (fmap f) = fmap f . join

Thanks already now,
Burak Ekici.
_______________________________________________
Haskell-Cafe mailing list
[hidden email]
http://www.haskell.org/mailman/listinfo/haskell-cafe
Reply | Threaded
Open this post in threaded view
|

Re: IO and Cont as monads

MigMit
As for Cont, it can be proved easily, either by hand, or by observation that Cont is an obvious composition of two adjoint functors.

As for IO, it has to be taken for granted, since IO internals are hidden from the programmer.

Отправлено с iPhone

Apr 12, 2011, в 14:39, Burak Ekici <[hidden email]> написал(а):

Dear List,

I am quite new in Haskell's categorical manner of programming. However I have enough knowledge in Category Theory.
I want to ask a question, maybe very well-known one by some of you, about monads of Haskell.

For the type constructors like Maybe and [], I managed to prove that together with 2 natural transformations (bind + return), both of these triples construct a monad. But when I try to prove that IO and Cont type constructors with the same natural transformations (bind + return) are monads as well, it was failed.

Here my question is: Is there anyone who knows how to prove that IO and Cont are monads with satisfing following properties:

  1. join . fmap join = join . join
  2. join . fmap return = join . return = id
  3. return . f = fmap f . return
  4. join . fmap (fmap f) = fmap f . join

Thanks already now,
Burak Ekici.
_______________________________________________
Haskell-Cafe mailing list
[hidden email]
http://www.haskell.org/mailman/listinfo/haskell-cafe

_______________________________________________
Haskell-Cafe mailing list
[hidden email]
http://www.haskell.org/mailman/listinfo/haskell-cafe
Reply | Threaded
Open this post in threaded view
|

Re: IO and Cont as monads

Tim Chevalier
In reply to this post by Burak Ekici
2011/4/12 Burak Ekici <[hidden email]>:

> Dear List,
>
> I am quite new in Haskell's categorical manner of programming. However I
> have enough knowledge in Category Theory.
> I want to ask a question, maybe very well-known one by some of you, about
> monads of Haskell.
>
> For the type constructors like Maybe and [], I managed to prove that
> together with 2 natural transformations (bind + return), both of these
> triples construct a monad. But when I try to prove that IO and Cont type
> constructors with the same natural transformations (bind + return) are
> monads as well, it was failed.
>
> Here my question is: Is there anyone who knows how to prove that IO and Cont
> are monads with satisfing following properties:

IO doesn't obey the monad laws, due to the presence of seq in Haskell.
Sad but true...

Cheers,
Tim



--
Tim Chevalier * http://cs.pdx.edu/~tjc/ * Often in error, never in doubt
"an intelligent person fights for lost causes,realizing that others
are merely effects" -- E.E. Cummings

_______________________________________________
Haskell-Cafe mailing list
[hidden email]
http://www.haskell.org/mailman/listinfo/haskell-cafe
Reply | Threaded
Open this post in threaded view
|

Re: IO and Cont as monads

Roel van Dijk-3
On 13 April 2011 21:26, Tim Chevalier <[hidden email]> wrote:
> IO doesn't obey the monad laws, due to the presence of seq in Haskell.
> Sad but true...

See also a previous discussion about IO and the Monad laws:

http://www.haskell.org/pipermail/haskell-cafe/2010-March/074001.html

_______________________________________________
Haskell-Cafe mailing list
[hidden email]
http://www.haskell.org/mailman/listinfo/haskell-cafe