4 ms·
All of the real world examples you described above involve I/O. There are various approaches for this, the most popular being the IO monad. A function using th
by random314 6y ago
All of the real world examples you described above involve I/O. There are various approaches for this, the most popular being the IO monad.
A function using the IO Monad looks like regular imperative code except for the type signature of the function which indicates that the function side effects and thus can only be called by other functions that side effect. Pure functions cannot call a side effecting function. This helps in isolating side effects and capturing it in the type signature of functions.
Plenty of examples here
https://www.haskell.org/tutorial/io.html https://www.haskell.org/tutorial/io.html
Functional programming is not stateless programming. Rather it captures any state changes in the type signature. An explicit example of it would be the state monad.
- millstone 6y agoMany functional languages do not model effects in the type system, like the ML family. Many do not have static types at all, like Clojure/LISP.
- random314 6y agoThose languages wouldn't be considered pure/stateless as intended by the OP.
- roguas 6y agoHaskell would not be considered pure or stateless as well. What the OP is saying there are several qualities which indicate you are dealing with functional language and they are not super rigid. Typically first-class functions indicate that its possible to do things functionally. Immutable defaults takes it further. Higher kinded types usually indicate you can easily separate pure from effectful. Dependant types hint that you can have value level expectations etc. At which point you are happy with "functional" is up to you. Its not all or none.