[dundee] Tiling Window Managers.... XMonad anyone?

Rick Moynihan rick.moynihan at gmail.com
Wed Jul 8 22:03:51 UTC 2009


2009/7/8 Iain Barnett <iainspeed at gmail.com>:
> 2009/7/8 Rick Moynihan <rick.moynihan at gmail.com>
>>
>> Perhaps I'm nitpicking but SQL/regexes are actually declarative
>> languages, likewise the definition you supplied is a great description
>> of declarative languages.
>>
>> Functional programming is a style of programming that encourages you
>> to write your code as 'pure functions', i.e. procedure's that given
>> the same inputs always return the same result without mutating state
>> or causing side effects.
>>
>> This said, there can be a lot of similarity between functional
>> langauges and declarative ones, as functional languages allow you to
>> easily raise the abstraction so as to provide a declarative
>> interpretation.
>>
>> I think the conflation of the two has probably come from your Haskell
>> exposure... The reason Haskell is sometimes described as declarative
>> comes more from its laziness i.e. leaving evaluation order up to the
>> language than anything else.
>
> I certainly don't mind a bit of nitpicking, I'm quite partial to it myself
> :)
>
> I agree with what you say, although I'd counter (in a way that actual agrees
> with you, but I'm not sure what the word for that is?) that you can't write
> in a functional style without being declarative. Essentially, pure functions
> are declarations, which is why they can be used lazily. But it's not the
> laziness that makes them declarative, that's a choice made by the compiler.
> Because they're pure, they don't alter program flow and are therefore
> declarative. To use them you'd have to build an impure function and call
> them from that, unless you want one of those progs that doesn't speak to the
> outside world, I forget the name.

In theoretical i.e. mathematical terms I think you're absoloutely
right, but in practice evaluation order *is* important and needs to be
tightly controlled.  This I think is one reason for your conflation of
declarative and functional programming styles.

For example Scheme is a functional language that is eagerly evaluated,
which means that there are many cases (even when writing pure
functions) where the programmer needs to worry about and control
evaluation.  It is the need for this explicit control of evaluation
that in some cases make purely functional scheme programs less
declarative than in a lazy language like Haskell.

In Haskell you can conjure up notions of infinite sequences without
worry where as doing so in Scheme isn't directly possible, as  eager
evaluation will force the program into non-termination, causing it to
spend all of its time/memory/cpu generating a sequence of values that
will never be consumed.

Anyway, the main issue I wanted to get across is that declarative and
functional programming are two different styles of programming and not
always equivalent...  For example the declarative language Prolog
which despite having some similarities to FP is very different, e.g.
predicates don't work like functions and return values, instead they
bind their arguments bidirectionally, blurring or removing the
distinction between input/output...

> You could take any of the languages, including Haskell (and certainly I've
> seen it done to SQL a lot), and force a procedural style onto them, but then
> they also wouldn't be (as) declarative anymore.

Yes, this is always possible... Even 'true' declarative languages like
Prolog allow you to blow away the declarative interpretation of the
program... Though doing so in such languages is almost always
considered bad style as you will no longer benefit from being able to
read both procedural and declarative interpretations of the code.


R.



More information about the dundee mailing list