[Haskell-cafe] IO is a bad example for Monads [was: do]

Lennart Augustsson lennart at augustsson.net
Sun Dec 9 15:02:25 EST 2007


Conal,

It's true that you can avoid using IO (except for a wrapper) for certain
kinds of programs.
For instance, if all you want is a String->String function, or some GUI
program (you forgot to mention fudgets, which was the first wrapper of this
kind) then you can ignore IO and just use a nice wrapper.

But if someone asks me how to traverse a directory tree, invoking the 'file'
program for each ',o' file and then renaming it if it's a text file, then
what should I answer?  "Sorry, you can't do that in Haskell."  or "You need
to use the IO monad."?
I prefer the latter answer, and I think people who learn Haskell need to
learn something about how you do some of the things that are easy in other
languages.

It's also important to teach people to stay away from IO whenever possible,
but it's simply not always possible.

  -- Lennart

On Dec 9, 2007 5:31 PM, Conal Elliott <conal at conal.net> wrote:

> > IO is important because you can't write any real program without using
> it.
>
> Ouch!  I get awfully discouraged when I read statements like this one.
> The more people who believe it, the more true it becomes.  If you want to do
> functional programming, instead of imperative programming in a functional
> language, you can.  For instance, write real, interactive programs in FRP,
> phooey, or TV.  And if you do, you'll get semantic simplicity, powerful &
> simpler reasoning, safety and composability.
>
>   - Conal
>
> On Dec 8, 2007 1:26 AM, Lennart Augustsson <lennart at augustsson.net> wrote:
>
> > I agree with Dan here.
> >
> > IO is important because you can't write any real program without using
> > it.
> > So why not teach enough of it to get people off the ground straight
> > away?
> >
> > People who hang around long enough to do some more Haskell programming
> > will run into the other monads sooner or later.  But IO is an
> > unavoidable step to
> > writing Haskell programs.
> >
> >
> >
> >
> > On Dec 4, 2007 5:11 AM, Dan Piponi < dpiponi at gmail.com> wrote:
> >
> > > On Dec 3, 2007 6:36 PM, Ben Franksen < ben.franksen at online.de> wrote:
> > > > then the special features of IO
> > > > will remain associated with monads in general, leading to a whole
> > > jumble of
> > > > completely wrong ideas about them.
> > >
> > > As I only learnt about monads a couple of years ago, the process is
> > > still fresh in my mind. I wasted quite a bit of time labouring under
> > > the impression that monads were primarily about sequencing. But that
> > > wasn't because I incorrectly generalised from IO. It was because
> > > countless people out there explicitly said they were about sequencing.
> > > I suspect that if courses started with the List monad there'd be
> > > countless blogs telling people that monads are a way to eliminate
> > > loops from your code like the way list comprehensions are used in
> > > Python.
> > >
> > > > This is yet another problem with IO as the standard example for
> > > monads: its
> > > > effect base is huge and poorly structured.
> > >
> > > You don't teach *all* of IO to students in one go!
> > >
> > > > This again makes it difficult to
> > > > see exactly which intuitions about IO can be generalized to
> > > arbitrary
> > > > monads and which not.
> > >
> > > That's true of any monad. IO is unique. [] is unique. Cont is unique.
> > > All of them can lead you down the garden path. You need to see
> > > multiple monads, and it helps if you can sneak an example under a
> > > student's nose so they can already reason about monads before they
> > > even know what a monad is.
> > >
> > > > What is pointless about failure and how to handle it?
> > >
> > > It's pointless when you're still trying to make your first tweaks to
> > > "Hello, World!" work.
> > > --
> > > Dan
> > > _______________________________________________
> > > Haskell-Cafe mailing list
> > > Haskell-Cafe at haskell.org
> > > http://www.haskell.org/mailman/listinfo/haskell-cafe
> > >
> >
> >
> > _______________________________________________
> > Haskell-Cafe mailing list
> > Haskell-Cafe at haskell.org
> > http://www.haskell.org/mailman/listinfo/haskell-cafe
> >
> >
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20071209/19e93272/attachment-0001.htm


More information about the Haskell-Cafe mailing list