Haskell Side Effects & IO

The cluster discusses Haskell's handling of side effects, purity in functional programming, and the IO monad's role in explicitly managing I/O without violating referential transparency.

➡️ Stable 0.8x Programming Languages
2,500
Comments
20
Years Active
5
Top Authors
#8985
Topic ID

Activity Over Time

2007
1
2008
9
2009
25
2010
44
2011
55
2012
44
2013
138
2014
155
2015
309
2016
150
2017
100
2018
136
2019
140
2020
161
2021
238
2022
170
2023
178
2024
184
2025
258
2026
5

Keywords

e.g OP MTL FFI Error.html OK stackoverflow.com System.IO BTW JavaScript haskell io monad effects functions monads function effect pure imperative

Sample Comments

jerf Aug 6, 2022 View on HN

The reconciliation is simple: Monads don't allow side effects in pure functions (in Haskell). I know it's a very popular idea but it's also just wrong.(Yet another in the long list of Very Popular But Also Just Wrong ideas surrounding this not-that-complicated concept.)What the monadic interface to the IO type (very carefully phrased) in Haskell allows is building up a value to be interpreted at run time with a convenient API that looks very like it is an imper

j_baker Jun 12, 2011 View on HN

Haskell doesn't prevent side effects. Otherwise, you wouldn't be able to do I/O. Instead, Haskell requires you to be explicit about side effects through Monads.I think about it this way: imperative languages allow side effects by default, but allow you to write side-effect free code. Purely functional languages don't use side-effects by default, but allow you to write code with side-effects.

BasDirks May 13, 2013 View on HN

Haskell isn't non-side-effecting. It's just a bit more sane and structured about when and how.

Veedrac May 4, 2015 View on HN

That's only if you don't count the IO itself as a side-effect.Does a language like Haskell give you the choice? If so,would it be idiomatic?

pdpi Feb 14, 2016 View on HN

Same as Haskell and IO, really. Every interesting language has side-effects, Haskell just forces you to be explicit about where you're using them.

tinco Sep 10, 2021 View on HN

Not exactly. When using the I/O monad in a pure language like Haskell, your code doesn't directly have side effects, instead you're building a container (a monad) of instructions of what side effect having operations to do, and what should be done with the results. The Haskell runtime then takes this monad and unwraps it layer by layer, each layer executing the side effect having instruction and using the results of the side effects as input for unwrapping the next layer.You co

millstone Feb 9, 2013 View on HN

If Haskell I/O is pure, why can't it be intermingled with other pure functions?

tome Aug 8, 2015 View on HN

OK, I think there's a fundamental misunderstanding at play here, of what purity, effects and monads are.Koka's effects system is monadic! Crazy huh? Well look: function main() { bind(foo, bar) } function foo() { println("Returning 3") return 3 } function bar(x) { println("Adding 1 to my argument and printing") y = x + 1 println(y) } function bind(x : (

cryptonector Mar 17, 2023 View on HN

That's allowed in the IO monad, and, really, it's allowed. The idea in Haskell is to have many contexts where side effects are not allowed so that in those contexts your code must be pure, and pure code is easier to write tests for and reason about.

mightybyte Dec 30, 2015 View on HN

Haskell lets you do side effects. The difference is that the type system carefully controls them.