functional

bearophile bearophileHUGS at lycos.com
Wed Mar 10 15:15:49 PST 2010


Justin Johansson:
> There is no reason to think that D programming cannot also be approached with a functional mindset.

In practice to program well in functional style:
- syntax sugar here and there helps, with some functional-handy features. For example in Haskell some local type inference is not optional, you probably have to waste too much time if you want to specify all data types manually.
- a good type system helps;
- a GC tuned for immutables, that's able to digest a very frequent disposal of immutable data structures is very useful;
- A compiler able to perform some optimizations that are not usually done by compilers of imperative languages. They have added LLVM as possible backend for Haskell, but there is a middle end that performs complex transformations.
- a standard library with many immutable but efficient data structures (that use finger trees, etc).
- a community of programmers that know some functional programming, because programming in functional style along in a sea of imperative/oop programmers that write imperative mutable libraries is not good.
- For example in a functional language you usually don't modules in the standard library that use templates instead of delegates/function pointers.

So I think D2 is quite far from being a good&handy functional language, despite it has some features very useful for functional programming (pure, closures, transitive immutable/const).

----------------

Walter Bright:
>My experience with traditional FP languages is limited to reading about them, and writing some very small programs in Lisp.<

I think that having a bit of practice with FP languages can help you design D2/Phobos2 to be a little more functional-friendly.
Given that background I suggest you to write few small programs in Clojure:
http://clojure.org/
It's a modern Lisp dialect that's based on the JavaVM, that is mostly immutables-based and is nice with concurrency too. It has also uses the idea of "transients", that is functions that locally usually modify a newly created data structure, this allows the JVM to use such functions to build such data structures in a much more efficient way, then such data structures are returned as immutable.

Time ago I have suggested you to write few small programs in C#3.5 too using its IDE, because it has already solved some of the problems D2 has still (you can use C# with mono if you don't want to install dotnet).

Bye,
bearophile



More information about the Digitalmars-d mailing list