[Haskell-cafe] Re: Tutorial uploaded
benjamin.franksen at bessy.de
Wed Dec 21 16:20:24 EST 2005
On Wednesday 21 December 2005 12:17, Daniel Carrera wrote:
> Robin Green wrote:
> > Whilst localising IO to a small part of the program is generally a
> > good idea, beginners should not be scared off by the thought that
> > IO in Haskell is so hard it has to be covered on page 94. This is
> > not the case. It should be introduced on page 1.
> As a newbie... I'll agree with Robin. I /did/ think that IO in
> Haskell was probably very difficult because it's covered in page 94.
> I skimmed through YAHT and IO is covered waaaayyy deep into the
> document. I haven't read that section yet, but there is a lot of
> content and to me it looked like it must be something difficult. I
> guess/hope that when I get around to reading it I'll find out that
> it's not as scary as it looks.
Rest assured it is dead simple. Really. I would even argue that it is a
lot simpler than in many other languages.
The only thing that is strange for beginners is that you cannot /do/ IO
from inside a function (because functions in Haskell are pure, period).
However you can easily /construct IO-performing actions/ inside
functions, since such actions are ordinary (first-class) /data values/.
That's what monadic IO is about. IO-actions (=procedures?) are data and
can be manipulated like other ordinary data. However, since IO is
necessarily an /abstract/ data type, data construction is limited to
what's offered by the public interface (which is essentially the type
class 'Monad', plus all the 'primitive' actions, i.e. putChar, getChar,
One of the funny aspects of IO in Haskell is that it tends to look like
perfectly ordinary imperative programming. That is what the do-Notation
(including <- 'assignment') is about.
More information about the Haskell-Cafe