IO then abstraction: Difference between revisions

From HaskellWiki
mNo edit summary
mNo edit summary
 
(10 intermediate revisions by the same user not shown)
Line 1: Line 1:
<div style="border-left:1px solid lightgray; padding: 1em" alt="blockquote">
<blockquote>
A puzzlingly named, exceedingly technical device introduced to structure the
denotational semantics has by now achieved cult status. It has been married to
effects -- more than once. It is compulsively looked for in all manner of
things, including burritos. At least two ICFP papers brought it up without a
rhyme or reason (or understanding), as the authors later admitted. I am talking
about monads.
 
:<small>[https://web.archive.org/web/20170614163005/https://okmij.org/ftp/tagless-final/nondet-effect.html Non-determinism: a sublanguage rather than a monad], Oleg Kiselyov.</small>
</blockquote>
 
<blockquote>
Still, today, over 25 years after the introduction of the concept of monads to the world of functional programming, beginning functional programmers struggle to grasp the concept of monads. This struggle is exemplified by the numerous blog posts about the effort of trying to learn about monads. From our own experience we notice that even at university level, bachelor level students often struggle to comprehend monads and consistently score poorly on monad-related exam questions.
 
Considering that the concept of monads is not likely to disappear from the functional programming landscape any time soon, it is vital that we, as the functional programming community, somehow overcome the problems novices encounter when first studying monads.
 
:<small>[https://repository.ubn.ru.nl/bitstream/handle/2066/181576/181576.pdf Visual Support for Learning Monads], Tim Steenvoorden, Jurriën Stutterheim, Erik Barendsen and Rinus Plasmeijer (page 2 of 17).</small>
</blockquote>
 
<blockquote>
I still can’t fully wrap my head around what a <i>monad</i> is, even after apparently using it for years now. After reading many definitions, examples and having it explained to me by functional programming advocates, I feel like that understanding is about to dawn on me. It is, however, still very much night time for me when it comes to
monads, and category theory more generally.
 
:<small>[https://hatwd.com/p/an-imperative-programmer-tries-to Thane Thomson]</small>.
</blockquote>
 
<blockquote>
Even so, it is fair to object that the ‘monadified’ definition is ugly compared
Even so, it is fair to object that the ‘monadified’ definition is ugly compared
to its direct but not obviously terminating counterpart, with more intermediate
to its direct but not obviously terminating counterpart, with more intermediate
naming. Monadic programming is ugly in general [...] There is no need to consider monadic style a just punishment, whatever your impurity.
naming. Monadic programming is ugly in general [...] There is no need to consider
monadic style a just punishment, whatever your impurity.


<small>[https://personal.cis.strath.ac.uk/conor.mcbride/pub/Totality.pdf Totality versus Turing-Completeness?], Conor McBride (page 3 of 15).</small>
:<small>[https://personal.cis.strath.ac.uk/conor.mcbride/pub/Totality.pdf Totality versus Turing-Completeness?], Conor McBride (page 3 of 15).</small>
</div>
</blockquote>
<span> </span>
 
<div style="border-left:1px solid lightgray; padding: 1em" alt="blockquote">
<blockquote>
Still, today, over 25 years after the introduction of the concept of monads to the world of functional programming, beginning functional programmers struggle to grasp the concept of monads. This struggle is exemplified by the numerous blog posts about the effort of trying to learn about monads. From our own experience we notice that even at university level, bachelor level students often struggle to comprehend monads and consistently score poorly on monad-related exam questions.
[Prolog] is a real-world programming language that does not demand the programmer to twist herself into knots just to be able to perform ordinary tasks that are very simple to do in imperative languages (looking to you Haskell and your hare-brained puritan monads).


Considering that the concept of monads is not likely to disappear from the functional programming landscape any time soon, it is vital that we, as the functional programming community, somehow overcome the problems novices encounter when first studying monads.
:<small>[https://swi-prolog.discourse.group/t/the-limits-of-the-declarative-approach/1693/17 Stassa Patsantzis]</small>
</blockquote>


<small>[https://repository.ubn.ru.nl/bitstream/handle/2066/181576/181576.pdf Visual Support for Learning Monads], Tim Steenvoorden, Jurriën Stutterheim, Erik Barendsen and Rinus Plasmeijer (page 2 of 17).</small>
<blockquote>
</div>
<span> </span>
<div style="border-left:1px solid lightgray; padding: 1em" alt="blockquote">
If you put up a video about monads, the comments are fantastic [...] my personal favourite:
If you put up a video about monads, the comments are fantastic [...] my personal favourite:
* ''What is a Monad? A miserable pile of functions.''
* <i>What is a Monad? A miserable pile of functions.</i>
 
:<small>[https://web.archive.org/web/20191106113703/https://twitter.com/haskellhutt/status/1192039007716364288 Graham Hutton].</small>
</blockquote>
 
<blockquote>
Haskell is a modern purely functional programming language, which is easy
to learn, has a beautiful syntax and is very productive. However, one of the
greatest barriers for learning it are monads. Although they are quite simple,
they can be very confusing for a beginner.
 
:<small>[https://web.archive.org/web/20120626020258/http://ertes.de/articles/monads.html Ertugrul Söylemez]</small>.
</blockquote>
 
<blockquote>
Lava has been used to teach VLSI design
to electrical engineering students, and in the end, the struggle to
teach monadic Lava syntax to non-Haskell users became too much.
 
:<small>[https://www.iro.umontreal.ca/~monnier/2035/history.pdf A History of Haskell: Being Lazy With Class], Paul Hudak, John Hughes, Simon Peyton Jones and Philip Wadler (page 38 of 55).</small>
</blockquote>
 
<blockquote>
Although monads are simple to define, they are a very general concept
making them difficult to comprehend. Whether because of a lack of good teaching materials or
intrinsic complexity, monads are a stumbling block for most new Haskell programmers.
 
:<small>[https://web.archive.org/web/20160527210838/https://edsko.net/pubs/thesis.pdf Making Uniqueness Typing Less Unique], Edsko de Vries (page 77 of 264).</small>
</blockquote>
 
...so where are students of Haskell most likely to have their first encounter with this irksome interface?
 
<blockquote>
Unfortunately, for a beginning student wishing
to write his <i>hello world</i> example in Haskell, he will immediately be faced with monads. One
might claim that this is the wrong example to start with, but then again <i>I/O is the raison d’être of
every program</i>
[https://web.archive.org/web/20210415200634/https://citeseerx.ist.psu.edu/viewdoc/download?doi=10.1.1.13.9123&rep=rep1&type=pdf <span></span>].
 
:<small>[https://web.archive.org/web/20160527210838/https://edsko.net/pubs/thesis.pdf ...] Edsko de Vries (same page).</small>
</blockquote>
 
<blockquote>
The implementation of IO as a monad is the main reason you need to be comfortable with monads to be an effective Haskell programmer.
 
:<small>[https://blog.oliverbalfour.com/haskell/2020/08/08/understanding-monads-haskell.html Oliver Balfour].</small>
</blockquote>


<small>[https://twitter.com/haskellhutt/status/1192039007716364288 Graham Hutton].</small>
<blockquote>
</div>
<code>IO</code> is the monad you cannot avoid.


...so where are students of Haskell most likely to have their first encounter with this irksome interface?
:<small>[https://image.slidesharecdn.com/functionalconf2019-whyishaskellsohard2-191116135003/95/why-is-haskell-so-hard-and-how-to-deal-with-it-53-638.jpg Saurabh Nanda].</small>
</blockquote>


<div style="border-left:1px solid lightgray; padding: 1em" alt="blockquote">
<blockquote>
Haskell, for some the digital equivalent of a 'garden of eden'-esque waterfall under a beautiful sunset; for others a source of pain and stress. This pain and stress is for beginners often largest when they have learned a little bit about monads like <code>IO</code>.
Haskell, for some the digital equivalent of a 'garden of eden'-esque waterfall under a beautiful sunset; for others a source of pain and stress. This pain and stress is for beginners often largest when they have learned a little bit about monads like <code>IO</code>.


<small>[https://hugopeters.me/posts/13/ Hugo Peters].</small>
:<small>[https://hugopeters.me/posts/13/ Hugo Peters].</small>
</div>
</blockquote>
<span> </span>
 
<div style="border-left:1px solid lightgray; padding: 1em" alt="blockquote">
<blockquote>
<code>IO</code> is the monad you cannot avoid.
A very common question on the interwebz is: how to convert an IO string into a normal string?
 
:<small>[https://web.archive.org/web/20240410041919/https://www.linkedin.com/pulse/til-haskell-weird-newbies-when-comes-io-andr%C3%A9-e-veltstra André E. Veltstra]</small>
</blockquote>
 
If bachelor-level students are often struggling to comprehend the monadic interface, then it has <b>no place whatsoever</b> in any introductory Haskell course!
 
<blockquote>
In the whole process of teaching I/O to freshmen, it is imperative to avoid
the monad-based heritage of I/O in Haskell.
 
:<small>[https://www.cambridge.org/core/services/aop-cambridge-core/content/view/39F929A1793B67BCEF316DBDB717F273/S0956796803004805a.pdf/the-risks-and-benefits-of-teaching-purely-functional-programming-in-first-year.pdf The risks and benefits of teaching purely functional programming in first year], Manuel M. T. Chakravarty and Gabriele Keller (page 9 of 11).</small>
</blockquote>
 
<blockquote>
In the first iteration, I/O was covered toward the end of the course because it is connected with the advanced topic of monads. [...] we [subsequently] moved I/O to an earlier point in the course. We also dropped monads, since the majority [of students] had not grasped them.
 
:<small>[https://www21.in.tum.de/~blanchet/teaching_haskell2.pdf Experience Report: The Next 1100 Haskell Programmers], Jasmin Christian Blanchette, Lars Hupel, Tobias Nipkow, Lars Noschinski and Dmitriy Traytel (page 2 of 6).</small>
</blockquote>
 
<blockquote>
The [decision to split off I/O from monads and introduce it earlier] is done in an effort to convince students more quickly that pure functional languages can be practical and deal with side effects.
 
:<small>[https://arxiv.org/pdf/2207.12703.pdf Engaging, Large-Scale Functional Programming Education in Physical and Virtual Space], Kevin Kappelmann, Jonas Rädle, and Lukas Stevens (page 3 of 21).</small>
</blockquote>
 
<blockquote>
In order to keep the programming as simple as possible, we chose to use only a subset of Haskell without monads, higher-level categorical interfaces or IO.
 
:<small>[https://wiki.tfpie.science.ru.nl/images/3/32/Alegre.pdf Haskell in Middle and High School Mathematics], Fernando Alegre and Juana Moreno.</small>
</blockquote>
 
But that presumes I/O should be in an introductory course at all:
 
<blockquote>
[...] in most programming languages input and output are esoteric and the techniques for performing input and output must be learnt by the students at an early stage, precisely when they are trying to understand the basics of programming.
 
:<small>[https://www.cs.kent.ac.uk/pubs/1997/2176/content.pdf I/O Considered Harmful (At Least for the First Few Weeks)], John Rosenberg and Michael Kölling (first page).</small>
</blockquote>
 
<blockquote>
Learning how to do I/O should not be a prerequisite to learn the basics of programming nor to take your first steps into the world of Computer Science.


<small>[https://image.slidesharecdn.com/functionalconf2019-whyishaskellsohard2-191116135003/95/why-is-haskell-so-hard-and-how-to-deal-with-it-53-638.jpg Saurabh Nanda].</small>
:<small>[https://www.cs.tufts.edu/~nr/cs257/archive/marco-morazan/FunctionalVideoGamesInCS1.pdf Functional Video Games in the CS1 Classroom], Marco T. Morazán (page 7 of 19).</small>
</div>
</blockquote>


If bachelor-level students are often struggling to comprehend the monadic interface, then it has ''no place whatsoever'' in any introductory Haskell course! I/O in Haskell must therefore be totally independent of the monadic interface. The introduction of this interface, including its basic operations, should be deferred to an advanced course of study where it can join functors, applicatives, arrows and maybe even category theory itself: only then should students be introduced to monadic I/O.
I/O in Haskell must therefore be completely independent of the monadic interface. An advanced course of study is where that interface and its basic operations should be taught, alongside functors, applicatives, arrows and maybe even category theory itself: only then should <i>experienced</i> students be introduced to monadic I/O.


<div style="border-left:1px solid lightgray; padding: 1em" alt="blockquote">
<blockquote>
The most difficult construct for students to understand is the monad. I introduce <code>IO</code> without mentioning monads.
The most difficult construct for students to understand is the monad. I introduce <code>IO</code> without mentioning monads.


<small>[[Haskell in education|Olaf Chitil]].</small>
:<small>[[Haskell in education|Olaf Chitil]].</small>
</div>
</blockquote>
 
A [https://www.interaction-design.org/literature/article/kiss-keep-it-simple-stupid simple] general-purpose model of I/O for non-strict functional languages remains an [[Open research problems|open research problem]]...


A [https://www.interaction-design.org/literature/article/kiss-keep-it-simple-stupid-a-design-principle simple] general-purpose model of I/O for non-strict functional languages remains an [[Open research problems|open research problem]]...


[[Category:Rants and comments]]
[[Category:Rants and comments]]

Latest revision as of 22:02, 3 January 2025

A puzzlingly named, exceedingly technical device introduced to structure the denotational semantics has by now achieved cult status. It has been married to effects -- more than once. It is compulsively looked for in all manner of things, including burritos. At least two ICFP papers brought it up without a rhyme or reason (or understanding), as the authors later admitted. I am talking about monads.

Non-determinism: a sublanguage rather than a monad, Oleg Kiselyov.

Still, today, over 25 years after the introduction of the concept of monads to the world of functional programming, beginning functional programmers struggle to grasp the concept of monads. This struggle is exemplified by the numerous blog posts about the effort of trying to learn about monads. From our own experience we notice that even at university level, bachelor level students often struggle to comprehend monads and consistently score poorly on monad-related exam questions.

Considering that the concept of monads is not likely to disappear from the functional programming landscape any time soon, it is vital that we, as the functional programming community, somehow overcome the problems novices encounter when first studying monads.

Visual Support for Learning Monads, Tim Steenvoorden, Jurriën Stutterheim, Erik Barendsen and Rinus Plasmeijer (page 2 of 17).

I still can’t fully wrap my head around what a monad is, even after apparently using it for years now. After reading many definitions, examples and having it explained to me by functional programming advocates, I feel like that understanding is about to dawn on me. It is, however, still very much night time for me when it comes to monads, and category theory more generally.

Thane Thomson.

Even so, it is fair to object that the ‘monadified’ definition is ugly compared to its direct but not obviously terminating counterpart, with more intermediate naming. Monadic programming is ugly in general [...] There is no need to consider monadic style a just punishment, whatever your impurity.

Totality versus Turing-Completeness?, Conor McBride (page 3 of 15).

[Prolog] is a real-world programming language that does not demand the programmer to twist herself into knots just to be able to perform ordinary tasks that are very simple to do in imperative languages (looking to you Haskell and your hare-brained puritan monads).

Stassa Patsantzis

If you put up a video about monads, the comments are fantastic [...] my personal favourite:

  • What is a Monad? A miserable pile of functions.
Graham Hutton.

Haskell is a modern purely functional programming language, which is easy to learn, has a beautiful syntax and is very productive. However, one of the greatest barriers for learning it are monads. Although they are quite simple, they can be very confusing for a beginner.

Ertugrul Söylemez.

Lava has been used to teach VLSI design to electrical engineering students, and in the end, the struggle to teach monadic Lava syntax to non-Haskell users became too much.

A History of Haskell: Being Lazy With Class, Paul Hudak, John Hughes, Simon Peyton Jones and Philip Wadler (page 38 of 55).

Although monads are simple to define, they are a very general concept making them difficult to comprehend. Whether because of a lack of good teaching materials or intrinsic complexity, monads are a stumbling block for most new Haskell programmers.

Making Uniqueness Typing Less Unique, Edsko de Vries (page 77 of 264).

...so where are students of Haskell most likely to have their first encounter with this irksome interface?

Unfortunately, for a beginning student wishing to write his hello world example in Haskell, he will immediately be faced with monads. One might claim that this is the wrong example to start with, but then again I/O is the raison d’être of every program .

... Edsko de Vries (same page).

The implementation of IO as a monad is the main reason you need to be comfortable with monads to be an effective Haskell programmer.

Oliver Balfour.

IO is the monad you cannot avoid.

Saurabh Nanda.

Haskell, for some the digital equivalent of a 'garden of eden'-esque waterfall under a beautiful sunset; for others a source of pain and stress. This pain and stress is for beginners often largest when they have learned a little bit about monads like IO.

Hugo Peters.

A very common question on the interwebz is: how to convert an IO string into a normal string?

André E. Veltstra

If bachelor-level students are often struggling to comprehend the monadic interface, then it has no place whatsoever in any introductory Haskell course!

In the whole process of teaching I/O to freshmen, it is imperative to avoid the monad-based heritage of I/O in Haskell.

The risks and benefits of teaching purely functional programming in first year, Manuel M. T. Chakravarty and Gabriele Keller (page 9 of 11).

In the first iteration, I/O was covered toward the end of the course because it is connected with the advanced topic of monads. [...] we [subsequently] moved I/O to an earlier point in the course. We also dropped monads, since the majority [of students] had not grasped them.

Experience Report: The Next 1100 Haskell Programmers, Jasmin Christian Blanchette, Lars Hupel, Tobias Nipkow, Lars Noschinski and Dmitriy Traytel (page 2 of 6).

The [decision to split off I/O from monads and introduce it earlier] is done in an effort to convince students more quickly that pure functional languages can be practical and deal with side effects.

Engaging, Large-Scale Functional Programming Education in Physical and Virtual Space, Kevin Kappelmann, Jonas Rädle, and Lukas Stevens (page 3 of 21).

In order to keep the programming as simple as possible, we chose to use only a subset of Haskell without monads, higher-level categorical interfaces or IO.

Haskell in Middle and High School Mathematics, Fernando Alegre and Juana Moreno.

But that presumes I/O should be in an introductory course at all:

[...] in most programming languages input and output are esoteric and the techniques for performing input and output must be learnt by the students at an early stage, precisely when they are trying to understand the basics of programming.

I/O Considered Harmful (At Least for the First Few Weeks), John Rosenberg and Michael Kölling (first page).

Learning how to do I/O should not be a prerequisite to learn the basics of programming nor to take your first steps into the world of Computer Science.

Functional Video Games in the CS1 Classroom, Marco T. Morazán (page 7 of 19).

I/O in Haskell must therefore be completely independent of the monadic interface. An advanced course of study is where that interface and its basic operations should be taught, alongside functors, applicatives, arrows and maybe even category theory itself: only then should experienced students be introduced to monadic I/O.

The most difficult construct for students to understand is the monad. I introduce IO without mentioning monads.

Olaf Chitil.

A simple general-purpose model of I/O for non-strict functional languages remains an open research problem...