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

Daniel Fischer daniel.is.fischer at web.de
Mon Dec 10 07:51:26 EST 2007

Am Montag, 10. Dezember 2007 10:36 schrieb Ketil Malde:
> Daniel Fischer <daniel.is.fischer at web.de> writes:
> >> Well, I guess you could get pretty far using 'interact' - far enough
> >> in an educational setting to do lists and Maybe, and then monads,
> >> before introducing monadic IO.
> >
> > Pretty far, yes, and in an educational setting, at a university, it is
> > quite common, I believe, to use an interpreter for a while, not producing
> > executables (that's how I met Haskell, write pure functions and type
> > expressions at the Hugs prompt). But what about a tutorial for
> > programmers? How would you do
> Well, yes, some things do get complicated, and I'm not suggesting that
> "interact" will suffice for real programs.  I still agree with the
> faction that thinks monadic IO should be taught after non-IO
> monadics - which, especially for programmers, can be quite early in
> the curriculum.  After all, lists and algebraic data types are central
> and simple concepts.

I have no teaching experience, and I have not thought a great deal about how 
to teach monads, but I think it would be good to have some familiarity with a 
couple of monads - most notably lists - when the monad 'interface' is 
explained to give examples of how different data types share some concepts.
I think, having IO as one example among others isn't necessarily bad, but 
could be convinced otherwise.

> I don't think you *need* to teach input-print sequential programs,
> though.  This is functional programming after all, why not build a
> compiler instead?

By all means, building a compiler for a simple enough language would be an 
interesting task in the course of which many concepts can be introduced.
But would Joe Programmer, who heard about this exciting language called 
Haskell and then grabbed a tutorial to see whether it's something for him be 
content to type expressions to the interpreter prompt until the compiler is 
complete, monads have been explained and only after that he is told how to 
read/write files, stdin, stdout?
> > I doubt you could keep many interested without telling them how to create
> > standalone programmes, including reading input from stdin and printing
> > output to stdout.
> Well, my first "real", standalone haskell program was reading my
> telephone log from stdin, matching against an internal database, and
> outputting calls with time and name to stdout.  I used standard
> features like shell IO redirection in and 'tee' to integrate with the
> rest of the system.
> I then moved on to monadic IO, but wish I'd done monads in general
> first.  YMMV.
> -k

More information about the Haskell-Cafe mailing list