Re: Survey: What led you to functional programming?
  Home FAQ Contact Sign in
comp.lang.functional only
 
Advanced search
POPULAR GROUPS

more...

 Up
Re: Survey: What led you to functional programming?         

Group: comp.lang.functional · Group Profile
Author: Ertugrul Söylemez
Date: Sep 19, 2008 18:41

Slobodan Blazeski gmail.com> wrote:
>> I suspect that a similar correlation exists between experience both
>> procedural and object-oriented programming and speed in learning
>> non-strict, purely functional programming languages, such as Haskell
>> or Clean.
>
> Purely functional is a misnomer, the better name would be langauges
> who lack assignment.

I agree that "purely functional" is a misnomer. What would a 'purely
imperative' language be?

But what 'pure functionalness' conventionally means doesn't come from
whether a language allows assignment, if you consider what "assignment"
is. Almost all functional languages, including Haskell and Clean, allow
assignment. They assign values to names, these values can be functions,
and most of the time they are. In that sense, a language is 'purely'
functional, if it doesn't allow reassignment at run-time.

If a function can return different values at each call, then this is
such a reassignment, because then a name stands for a different value
(or function) each time. Not allowing that to happen is what we call
'referential transparency'.

So conventionally a purely functional language is one, which retains
referential transparency. Haskell and Clean do that. The former uses
monads to carry state implicitly, the latter uses what's called
'uniqueness types', to disallow threading of certain values like the
world state.

This is not the same as disallowing reassignments of values to memory
locations, because Haskell and Clean both allow that. Look at this
Haskell code, which calculates the greatest common divisor of two
numbers in an imperative manner:

while :: Monad m => (a -> Bool) -> a -> (a -> m a) -> m a
while p x c = if p x then c x >>= \y -> while p y c else return x

gcdST :: Integral i => i -> i -> ST s i
gcdST x y = do
(a,b) <- while (\(a,b) -> b /= 0) (x,y)
(\(a,b) -> return (b, a `mod` b))
return a

Using so-called STRefs, you could even mention memory locations
explicitly.

Greets,
Ertugrul.

--
nightmare = unsafePerformIO (getWrongWife >>= sex)
no comments
diggit! del.icio.us! reddit!

RELATED THREADS
SubjectArticles qty Group
Hypergeometric functions and beta functionssci.math ·