The Artima Developer Community
Sponsored Link

Heron-Centric: Ruminations of a Language Designer
Language Purity and Dirty and Clean Functions
by Christopher Diggins
June 26, 2006
The myth of functional language "purity" and marking side-effects in a programming language.


Many people talk about "pure" functional languages, where "pure" seems to be a synonym for "good". There are two traits commonly associated with the definition of a pure functional language:

  1. functions can not have side-effects
  2. a function called with any given arguments will always return the same value.
The programming Haskell for example is often referred to as a pure language because a function call with side-effects must be done only in the context of a monad. I believe that this is simply semantic hand-waving.

The need of monads illustrates the simple fact that in order to have substantitve practical applications, a programming language must allow a program to interact with the environment during its execution (e.g. file-system, devices, clock, etc.). This implies that any non-trivial programming language must allow side-effects.

All of that said, it is much easier to reason about and manipulate (read: optimize) programs and sub-programs which don't have side-effects.

So the purity of a language is an impractical notion from a software development standpoint, however the idea of understanding and localizing side-effects (e.g. using monads) is nonetheless a very important and useful idea.

Where am I going with this? Well I believe that language designers can take a lesson from Haskell by isolating and labelling side-effects. Taking a far more simplistic approach than using monads, the approach I am exploring using later versions of Cat, is to label functions as "clean" and "dirty" depending on whether they have side-effects or not. This makes optimization much easier.

Any thoughts on the subject?

Talk Back!

Have an opinion? Readers have already posted 46 comments about this weblog entry. Why not add yours?

RSS Feed

If you'd like to be notified whenever Christopher Diggins adds a new entry to his weblog, subscribe to his RSS feed.

About the Blogger

Christopher Diggins is a software developer and freelance writer. Christopher loves programming, but is eternally frustrated by the shortcomings of modern programming languages. As would any reasonable person in his shoes, he decided to quit his day job to write his own ( ). Christopher is the co-author of the C++ Cookbook from O'Reilly. Christopher can be reached through his home page at

This weblog entry is Copyright © 2006 Christopher Diggins. All rights reserved.

Sponsored Links


Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use