POV-Ray : Newsgroups : povray.off-topic : And today, C# : Re: And today, C# Server Time
14 Nov 2024 20:26:30 EST (-0500)
  Re: And today, C#  
From: Invisible
Date: 13 Feb 2008 09:08:17
Message: <47b2f9d1$1@news.povray.org>
Warp wrote:
> Invisible <voi### [at] devnull> wrote:
>> Tell me Warp, do you actually understand what "functional programming" 
>> means?
> 
>   A purely functional programming language doesn't have side-effects.

Indeed.

> If I'm not mistaken, for example assignment produces a side-effect.
> Even I/O causes side-effects.

Assignment and I/O are both side-effects. Accessing an indexed array 
does not. There is absolutely no reason why a pure functional language 
cannot have arrays.

>   Thus a purely functional language is mostly impractical.

Depends on your definition of "practical".

> Quoting wikipedia:
> 
> "Purely functional programs have no side effects. This makes it easier
> to reason about their behavior. However, almost no programmers bother
> to write purely functional programs, since, by definition, a program
> with no side effects is formally equivalent to a program that
> does nothing."

Indeed, a program with absolutely no side effects at all is rather 
pointless. (!) There are several approaches to this apparent problem.

One approach is to *allow* side-effects, but say "hey, don't use this 
unless you have to". This is the Lisp approach. (And Erlang. And a few 
others.)

The Haskell approach is different. A Haskell "program" just returns a 
list of instructions to the Haskell runtime, and the Haskell runtime 
actually "does" the instructions on the program's behalf.

Why is that different? Well, it means that the entire program remains 
referentially transparent. And *that* is the defining characteristic of 
functional programs.

In Haskell, *every* expression can be replaced by the value it returns 
without altering the result of the program. [Indeed, this is notionally 
how you execute a Haskell program.] The same statement does *not* apply 
to Lisp. Hence, Haskell is pure, and Lisp is not. QED.

Note that you *could* write referentially transparent code in just about 
any programming language, if you wanted to. It's just that in Haskell 
you can't write code that isn't. ;-)

-- 
http://blog.orphi.me.uk/
http://www.zazzle.com/MathematicalOrchid*


Post a reply to this message

Copyright 2003-2023 Persistence of Vision Raytracer Pty. Ltd.