Misconceptions about purely functional languages?

Posted by Giorgio on Programmers See other posts from Programmers or by Giorgio
Published on 2012-12-19T09:21:57Z Indexed on 2012/12/19 11:13 UTC
Read the original article Hit count: 252

I often encounter the following statements / arguments:

  1. Pure functional programming languages do not allow side effects (and are therefore of little use in practice because any useful program does have side effects, e.g. when it interacts with the external world).
  2. Pure functional programming languages do not allow to write a program that maintains state (which makes programming very awkward because in many application you do need state).

I am not an expert in functional languages but here is what I have understood about these topics until now.

Regarding point 1, you can interact with the environment in purely functional languages but you have to explicitly mark the code (functions) that introduces them (e.g. in Haskell by means of monadic types). Also, AFAIK computing by side effects (destructively updating data) should also be possible (using monadic types?) but is not the preferred way of working.

Regarding point 2, AFAIK you can represent state by threading values through several computation steps (in Haskell, again, using monadic types) but I have no practical experience doing this and my understanding is rather vague.

So, are the two statements above correct in any sense or are they just misconceptions about purely functional languages? If they are misconceptions, how did they come about? Could you write a (possibly small) code snippet illustrating the Haskell idiomatic way to (1) implement side effects and (2) implement a computation with state?

© Programmers or respective owner

Related posts about functional-programming

Related posts about haskell