DEV Community

Discussion on: Explain Pure Functions Like I'm Five

Collapse
 
theodesp profile image
Theofanis Despoudis

Answer: You cheat by accepting that there are side-effects in order to run the program.

See wiki.haskell.org/Introduction_to_IO

Thread Thread
 
dfacastro profile image
Diogo Castro • Edited

Eh, IO String in Haskell is just as pure as String. Haskell only has a handful of escape hatches to break out of purity/referential transparency, like unsafePerformIO and unsafeInterleaveIO - but you don't need to (and shouldn't) use them at all. They're there for the runtime system to use and execute your code. See my other reply in this thread.

Thread Thread
 
theodesp profile image
Theofanis Despoudis

True. Thats why though Haskell is often considered the "most functional" out of others, but not Purely functional, because the type system allows for any side effects to be encapsulated within the context of a type.

Thread Thread
 
idanarye profile image
Idan Arye

That claim is as meaningful as the claim that no computer is Turing complete because they all have finite memory.

Thread Thread
 
theodesp profile image
Theofanis Despoudis

They are if you ignore any resource limitations and thats the point really. A Turing machine is more of a mathematical model than a real world implementation as you cannot possibly express the notion of infinity in computer systems. There has to be an upper limit somewhere.