4 ms·
But is _just reading_ from a database a "side-effect"? It is non-deterministic, but it has no side-effects. So IO jumbles together the two notions.
by zvrba 6y ago
But is _just reading_ from a database a "side-effect"? It is non-deterministic, but it has no side-effects. So IO jumbles together the two notions.
- uryga 6y agopedantically, talking to the database will involve sending a request or some kind of IPC, all of which are usually considered side effects. [handwavy analogy alert] people often call it "side-effects" as a shorthand. in reality an expression being of type `IO Foo` mostly just tells the compiler that order of execution matters (which isn't the case with pure functions): do print "a" print "b" -- obviously not the same as do print "b" print "a" and also that it can't eliminate common expressions: do a <- readBytes file 100 b <- readBytes file 100 doStuff a b -- obviously not the same as do x <- readBytes file 100 doStuff x x it's a way of enforcing ordering in a lazy language where evaluation order isn't really defined.