Lecture 8: Monads and I/O

Leading on from the slides by Peyton Jones, this lecture sets out how constructor classes and higher-order functions can help to treat effectful computation within a pure functional language; or potentially contain its influence within an imperative one.

Distinguishing between effectful and pure computation is important for powerful programming that can be compiled to efficient code; in particular with multilayered memory models and concurrent architectures.

Two ways to do this are to localise existing effects in imperative programs; or to extend functional programs to handle effectful commands.

Higher-order functions allow programming that treats code as data, including codes with particular kinds of side-effect. Datatypes for this are often monads which create and sequence computation.

Historically, input/output has been a challenge in purely functional languages. The use of monads revolutionised this, and Haskell puts all side-effects in its IO monad.

I have sent out individual feedback sheets on your preliminary reports by email. If you would like to ask questions about either your preliminary report or this feedback, please email one of the course lecturers to arrange a meeting.

Link: Slides


Find an online tutorial or other explanation of monads in programming, and post a link on the blog. Write a comment reviewing whether you found the explanation helpful, or otherwise. Bonus points if the language is not Haskell.

Next week

There are no lectures next week, and you should work on your coursework investigation. If you have questions please post them to the blog or by email either to the mailing list apl-students@inf.ed.ac.uk or to me Ian.Stark@ed.ac.uk.

The next lecture is on Monday 25 October and will be about making database queries using SQL from Java.

Comments are closed.