4 ms·
Haskell doesn’t have side effects, but it does have effects. This is a subtle distinction that is a bit hard to explain but I’ll give it my best shot: One way
by chongli 4y ago
Haskell doesn’t have side effects, but it does have effects. This is a subtle distinction that is a bit hard to explain but I’ll give it my best shot:
One way to think of Haskell is like a pure functional C preprocessor that also happens to be lazy. When Haskell code is running, pure functional expressions are being evaluated and reduced to their simplest form. This simplest form is not a plain value but actually a program that when run has effects (reading input, printing to the screen) just like a C program.
The last piece of the puzzle is that, unlike the C preprocessor, Haskell doesn’t do all of the evaluation ahead of time. The evaluation of these pure functional expressions is interwoven with the execution of the program producing the desired effects. Haskell’s type system is used to express the dependencies between inputs and outputs so that the effects are performed in the correct sequence.
- aidenn0 4y agoThere was a somewhat tongue-in-cheek article a while back saying "C has no side effects" with the premise being That "when people say C, they really mean CPP, because nobody writes C with the preprocessor disabled" and since CPP is side-effect free, colloquially we can say that C is side-effect free...
- ackfoobar 4y agohttp://conal.net/blog/posts/the-c-language-is-purely-functional http://conal.net/blog/posts/the-c-language-is-purely-functio... "The C language is purely functional" and "Haskell is the world's finest imperative programming language" can blow some minds.
- aidenn0 4y agoThat's the one. There's also: > “Haskell is a dynamically-typed, interpreted language.” From https://aphyr.com/posts/342-typing-the-technical-interview https://aphyr.com/posts/342-typing-the-technical-interview
- deleted 4y ago[deleted]
- goto11 4y agoThe context is she is using Haskell type declarations as if it was a regular programming language. Arguable the type declarations are interpreted, and dynamically typed in the sense that there is no static type checking before the interpretation.
- marcosdumay 4y agoHum... You meant to say that the C compiler is pure. And well, yes, it is. Even when you include the compiler itself, instead of only the preprocessor. You can notice on the GP's description that Haskell will generate those programs at runtime. The Haskell code is running on the same level as the C compiler, but at a very different time.
- goto11 4y agoThis is a very convolution way of saying that Haskell can have side effects, but some parts of the code is pure. This is also similar to any other languages. Any code is side-effect free until it is executed. The actually interesting part of Haskell is that the type system is strong enough to indicate which sections of the code is pure and which are unpure.