Mariano Guerra
Leonard Pauli
09/30/2020, 12:34 PMDuncan Cragg
09/30/2020, 12:35 PMMariano Guerra
Duncan Cragg
09/30/2020, 12:38 PMTudor Girba
09/30/2020, 1:24 PMDuncan Cragg
09/30/2020, 1:28 PMDuncan Cragg
09/30/2020, 1:30 PMMariano Guerra
Mariano Guerra
Mariano Guerra
Brent
09/30/2020, 2:07 PMChris Knott
09/30/2020, 2:58 PMMariano Guerra
Philipp KrĂźger
09/30/2020, 3:49 PMState
monad, you can resolve it at a higher level by running it, and you'll get back a pure value.
2. All the annotated side-effects your functions can generate are accumulated. So a function that needs an effect like readFile : FilePath -> String
will be composable with a function that needs an effect like openSocket : () -> SocketId
. The resulting expression will contain both effects.
3. Finally, all the effects don't actually refer to actual implementations, but rather, they refer to something like datatypes. At any point you can do something similar to what try-catch does to exceptions: You can handle effects. Thus, you can e.g. always return the same (mocked) string for readFile : FilePath -> String
. Or you can accumulate all files written with the writeFile : FilePath -> String -> ()
effect.
If you want to learn more about algebraic effects, I recommend looking at unisonweb.org. Other than that, there's the typescript-like language koka (microsoft research) and the paper for "Frank", horribly named "Do be do be do".Philipp KrĂźger
09/30/2020, 4:08 PMIt does annoy me that I can't actively mark something as pure and have it enforced.This is what motivated me to answer you: In haskell, if a function is annotated with
IO
, including this computation in the main :: IO ()
computation will run its side effects. If not, it's pure.
I feel like this is exactly fulfills your wish.
However, writing IO functions is not very common in haskell. In fact, you try to write as much pure logic as possible, before your call stack approaches the outermost layer of your application, which is written in IO. I feel like this is one big difference between haskell and python, and it's not about functionality, it's about conventions.
In terms of functionality, there's one big difference between haskell and python: Types. However, if your goal is annotating pure-ness and statically enforcing this, you'll probably need some form of type system (even if only two types exist "has side effect" and "doesn't have side effect").
So... yay types, yay haskell? đChris Knott
09/30/2020, 4:17 PMDon Abrams
09/30/2020, 4:40 PMEmmanuel Oga
09/30/2020, 4:51 PMAndrew F
09/30/2020, 5:08 PMGarth Goldwater
09/30/2020, 6:44 PMAndrew F
09/30/2020, 8:44 PMDoug Moen
09/30/2020, 10:22 PMI know some people say 'Haskell doesn't have side effects', and I know why they do: From the perspective of haskell's type system, haskell doesn't have side effects. However, in reality, you can write and read files in haskell, thus, it has side effects.A side effect is an effect that happens on the side. I/O actions are effects. Haskell has effects, but it does not have side effects.
Doug Moen
09/30/2020, 11:05 PMI don't like to write code full of side effects, hard to test, hard to reason about, hard to know all the edge cases. I also don't like mocks and doing dependency injection everywhere to be able to switch the side effect parts is a lot of work.One of my hobby projects is to make a practical programming language that is easy to use, easy to understand, has a low barrier to entry, and has simple semantics. In my language, all functions are pure (function calls do not have side effects), and there is no shared mutable state, because that leads to simpler semantics and less cognitive load. I think my goals are different from functional programming researchers, because there, the focus is on complex type systems. Eg, Haskell is a very complex language with a steep learning curve. Whereas my language is dynamically typed. As for "the future of side effects", I think there is a much larger design space for side-effect-free programming languages than what is currently explored by FP researchers focused on higher order type theory.
Doug Moen
10/01/2020, 2:53 AMNick Smith
10/01/2020, 11:34 AMDoug Moen
10/01/2020, 12:23 PMAndrew F
10/01/2020, 6:48 PMNick Smith
10/01/2020, 11:11 PMMarcel Weiher
08/03/2021, 12:07 PM