IO behaves oddly if used nested

Antti-Juhani Kaijanaho antkaij at
Tue Oct 14 20:25:43 EDT 2003

On 20031004T181216+0100, Alastair Reid wrote:
> be careful to distinguish 'a value of type t' from 'a computation
> which returns a value of type t'i

I always found the idea of a "computation" as a value a little hard to
grasp.  Therefore, when I introduced monadic transput in my functional
programming course [1], I took the following approach: IO a is the type
of a program with an exit value of type a; return, fail, putChar and
getChar are primitive programs, and monadic transput is about combining
programs using (>>=).  The idea of denoting programs without executing
them seems natural (in contrast to denoting computations without
executing them).  Likewise, it seems natural that there is a special
mechanism for actually executing a program: either you give it to GHCi,
or you bind it to Main.main and compile the module (thus, the program
becomes synonymous with the expression that you bind to Main.main).

Up until now, nobody in my class seems to have had problems with this
mental model of monadic transput (of course, in grand tradition of
Finnish universities, a large subset of my students are not actually
attending sessions, so I wouldn't know about them until exam time).

[1] Advanced-level introduction to FP; students are advanced undergrads
or pre-master graduates.  They have a strong background in imperattive
programming, with the usual load of data structures and algorithms,
operating systems, automata and formal languages theory (and other stuff
depending on their tastes).

(Note that printing a program is also a natural idea, and likewise
natural is the idea that the output is unintelligible.)

Antti-Juhani Kaijanaho, FM (MSc),
ohjelmistotekniikan assistentti    * assistant in software engineering
Jyväskylän yliopisto               * University of Jyväskylä
Tietotekniikan laitos              * Dept. of Mathematical Inf. Tech.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: Digital signature
Url :

More information about the Haskell mailing list