The Artima Developer Community
Sponsored Link

Weblogs Forum
Language Purity and Dirty and Clean Functions

46 replies on 4 pages. Most recent reply: Jul 11, 2006 5:10 AM by Emil Cristian Alexandrescu

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 46 replies on 4 pages [ « | 1 2 3 4 ]
Christopher Diggins

Posts: 1215
Nickname: cdiggins
Registered: Feb, 2004

Re: Language Purity and Dirty and Clean Functions Posted: Jun 30, 2006 4:59 PM
Reply to this message Reply
> > I have attempted to clarify my thoughts on the
> > subject, and incorporate other people's contributions
> on
> > my latest blog entry on the topic of purity at:
> >
> This seems to be the wrong URL.

Thanks for pointing that out:

Emil Cristian Alexandrescu

Posts: 13
Nickname: mkcoos
Registered: Jul, 2006

Re: Language Purity and Dirty and Clean Functions Posted: Jul 11, 2006 5:10 AM
Reply to this message Reply
Don't worry, you aren't the only one who took FP all wrong. They do it all the time! Even so called developers.

In the first place FP is usually typeless and it's that what makes it so error prone - as in your example.

Pure FP, by disallowing assignments, keeps "states" ordered in time: thus FP works with one or many timelines.

By contrast, in imperative languages it's explicitely how one can handle time: once a state changed, there is no way to tell when (at what point in a programm) did that change occur. So, in case one wants to know that he must deal with time explicitely.

Now let's see wether the order of comutation counts or not.
f(x)=x**2 - 12

Compute g(f(2)).

An imperative approach:
... g(f(p))...
This makes:
Compute f(p) and pass the result to g.
Compute that g. (a.k.a. g(f(p))
The two computations yielded on runtime.

A functional approach:
This makes:
... f(p)+4 ...
... p**2-12+4 ...
... p**2-8 ...
These all took place on compile-time. As a result a new function took shape instead of the old "f" and "g". So, for the run-time, noone can talk about ordering "f" and "g" any longer. It's in this respect order doesn't count!

Of course, at run-time ((p**2)-8) is different than (p**(2-8)) - so in this respect order counts so much!.

The best part of pure FP consists in that the compiler can relate any result solely with te initial input, so it disjoints as many computations as possible. This way these computations could be distributed without the fear of interfearing.

It was that FP are so proud of.

Flat View: This topic has 46 replies on 4 pages [ « | 1  2  3  4 ]
Topic: Language Purity and Dirty and Clean Functions Previous Topic   Next Topic Topic: Recursion in a Stack Based Language

Sponsored Links


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