5 ms·
Pure functional languages such as Haskell have some facilities to do things that are not 100% pure, such as I/O. Similarly, OCaml has effects, but functional pr
by flowerlad 6y ago
Pure functional languages such as Haskell have some facilities to do things that are not 100% pure, such as I/O. Similarly, OCaml has effects, but functional programmers minimize their use of such impure facilities.
Effects in OCaml are impure: "However, the effect system also allows for tracking side-effects more generally. It distinguishes impure functions, which perform side-effects, from pure functions, which do not." See: https://www.janestreet.com/tech-talks/effective-programming/ https://www.janestreet.com/tech-talks/effective-programming/
In Haskell impure functions are fenced off from pure functions. So for example, pure functions are not allowed to call impure ones.
If nearly all of the functions in your app are impure (and use React hooks) then you are definitely not doing functional programming.
- galaxyLogic 6y ago> In Haskell impure functions are fenced off from pure functions That's a great way of explaining it. But at the same time how can we say that Haskell is a "pure functional language" when Haskell programs consist of both pure and impure functions? Yes they are separated which in other words means you do have both of them. Is that really "pure" then? Or is that more like 'as pure as possible"?
- mejutoco 6y agoAccording to this definition a pure programming language could not have any side effect (Not very useful). Maybe as pure as possible is the only interpretation that makes sense, then.
- whimsicalism 6y agoAgreed - I do not think purity should be core to the definition of what a functional language is.
- flowerlad 6y agoPure functions (with no side effects or state mutation) is pretty core to functional programming.
- whimsicalism 6y agohttps://en.wikipedia.org/wiki/Functional_programming https://en.wikipedia.org/wiki/Functional_programming > Functional programming is sometimes treated as synonymous with purely functional programming, a subset of functional programming which treats all functions as deterministic mathematical functions, or pure functions. When a pure function is called with some given arguments, it will always return the same result, and cannot be affected by any mutable state or other side effects. It is a closely associated idea, but it is not necessarily "core" to what FP is.
- whimsicalism 6y ago> Effects in OCaml are impure: I didn't think that OCaml had a way of distinguishing functions with side effects... the link you sent seems to describe a prospective extension/system, not a built-in of the language.
- ernst_klim 6y ago> prospective extension/system, not a built-in of the language Yes, that would be merged into the language as typed algebraic effects branch.