Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Why use a functional language?

5 views
Skip to first unread message

Kevin Hostelley

unread,
Feb 17, 2000, 3:00:00 AM2/17/00
to

I'm not trying to start a war, but what are the reasons that someone
would choose to use a functional language. When I was doing
procedural programming, and OOP was coming into vogue, I heard all
sorts of reasons why you should switch (code reusability, easier to
maintain, etc.). Are there similar or additional benefits to
functional programming? If anyone could give me some insight, I would
appreciate it.

STARYNKEVITCH Basile

unread,
Feb 17, 2000, 3:00:00 AM2/17/00
to
>>>>> "Kevin" == Kevin Hostelley <hoste...@firstenergycorp.com> writes:

Kevin> When I was doing procedural programming, and OOP was coming
Kevin> into vogue, I heard all sorts of reasons why you should
Kevin> switch (code reusability, easier to maintain, etc.). Are
Kevin> there similar or additional benefits to functional
Kevin> programming?

I have some significant experience (and expertise) with Ocaml, but I
am still coding in C++ (this is going to change) because I am required
to do so. I did look into Haskell but didn't code in it.

First, as an important remark, object-oriented programming (be it C++,
Java, or Self or CLOS) is well suited for simulation of real objects
(e.g. in a MonteCarlo-like trafic jam simulation, it is natural to
code with car objects representing physical automobile cars). But not
all programming is isomorphic to simulating a world with objects
having each a mutable state (and in some domains OO style is the wrong
answer)

Functional programming (at least in Ocaml or SML, ie. staticly typed
eager functional langages) gives some benefit because:

0. An efficient garbage collector is very useful (and GC is not equal
to Java, many Java implementations have poor GCs, because of Java
languages pecularities (finalizers, etc)). Current GC technlogy is
quite mature.

1. coding in Ocaml is much more dense that the same code in C or Java,
because you combine a lot many small functions and types. I think
that a problem coded in Ocaml has at least 2 times less source code
lines than the same problem coded in C+. Of course, the programmer
has to master the language (Ocaml vs C++), the programming style
(functional+object oriented vs imperative+OO), and the library.

2. Current functional language compilers are quite good (performance
is at worse 2 or 3 times slower than C, and sometimes a bit faster
than C). I believe that new hardware archtecture will benefit even
more from functional style (and new chips are less and less suited
to C) but I am definitely not a hardware expert.a

3. Type inference is very powerful. The compiler -in practice- find a
lot of tiny stupid bugs that a C++ compiler can't find. And its
avoid being verbous. You don't have to tell things twice (eg
declare a variable with its type and initialize it [the
initialisation is enough for the compiler to infer the type]) or
declare a class interface and then implement it (although you do
give in Ocaml modules interfaces and implementations)

4. Ocaml and other functional languages have useful features (pattern
matching, anonymous functions) that are of great benifit to the
coder. In particular, extending a union (or sum or variant) type is
much more easy in Ocaml than in C.

5. Ocaml modules and functions are much more powerful than C++
templates, and are easily compiled.

6. When (and only when) inheritance, the Ocaml class system is
available and useful.

7. Compiler technlogy for functional language is a hot subject.

The current weaknesses of Ocaml and other functional languages are:

* lack of several competing implementations

* some (very often overestimated) inefficiency. It is still true that
some numerical loops are faster in C than in Ocaml. But the converse
may also be true (some programs run faster in Ocaml than in C). But
shorter time to market and smaller programmer costs should dwarf the
small performance loss.

* lack of libraries and 3rd parties tools.

* lack of well known software methodologies (although UML is very
oversold)

There may be some projects that are going into the wall because of
languages issues. Sometimes, choosing C++ or Java is the wrong way. I
assume of course availability of competent programmers (but learning
Ocaml when starting from C is a lot easier than learning C++ from C).


See also the Ocaml web pages (and mailing list archive)
"http://caml.inria.fr/ocaml/"

N.B. Any opinions expressed here are only mine, and not of my organization.
N.B. Les opinions exprimees ici me sont personnelles et n engagent pas le CEA.

---------------------------------------------------------------------
Basile STARYNKEVITCH ---- Commissariat à l Energie Atomique
DTA/LETI/DEIN/SLA * CEA/Saclay b.528 (p111f) * 91191 GIF/YVETTE CEDEX * France
phone: 1,69.08.60.55; fax: 1.69.08.83.95 home: 1,46.65.45.53
email: Basile point Starynkevitch at cea point fr


Michael Hudson

unread,
Feb 17, 2000, 3:00:00 AM2/17/00
to
STARYNKEVITCH Basile <Basile.Sta...@cea.fr> writes:

> [ ... interesting stuff ... ]


>
> See also the Ocaml web pages (and mailing list archive)
> "http://caml.inria.fr/ocaml/"

Thanks for that post. As a vaguely relavent followup question do you
know of any (paper) books describing ocaml? Are there any planned?
Searching on amazon.co.uk gets you lots of books about camels :-(.

Cheers,
Michael

Markus Mottl

unread,
Feb 17, 2000, 3:00:00 AM2/17/00
to
Michael Hudson <mw...@cam.ac.uk> wrote:

> STARYNKEVITCH Basile <Basile.Sta...@cea.fr> writes:
>> See also the Ocaml web pages (and mailing list archive)
>> "http://caml.inria.fr/ocaml/"

> Thanks for that post. As a vaguely relavent followup question do you
> know of any (paper) books describing ocaml? Are there any planned?
> Searching on amazon.co.uk gets you lots of books about camels :-(.

Yes, there are:

http://caml.inria.fr/books-eng.html

If you want to have online documentation and/or tutorials, you'd better start
at the "mother"-page of the Caml-dialect, which hosts the general information:

http://caml.inria.fr

The OCaml-page itself is rather spartanic in contents...

Regards,
Markus Mottl

--
Markus Mottl, mo...@miss.wu-wien.ac.at, http://miss.wu-wien.ac.at/~mottl

Remi VANICAT

unread,
Feb 17, 2000, 3:00:00 AM2/17/00
to
Michael Hudson <mw...@cam.ac.uk> writes:

> STARYNKEVITCH Basile <Basile.Sta...@cea.fr> writes:
>
> > [ ... interesting stuff ... ]
> >

> > See also the Ocaml web pages (and mailing list archive)
> > "http://caml.inria.fr/ocaml/"
>
> Thanks for that post. As a vaguely relavent followup question do you
> know of any (paper) books describing ocaml? Are there any planned?
> Searching on amazon.co.uk gets you lots of books about camels :-(.

there is :

THE FUNCTIONAL APPROACH TO PROGRAMMING

Guy Cousineau and Michel Mauny
Cambridge University Press, Cambridge, 1998, ISBN 0-521-57183-9
(hardcover), 0-521-57681-4 (paperback)

(it's seem to bee the only book in english
see http://pauillac.inria.fr/caml/books-eng.html)
--
MZ: Ouverture du marché de l'électricité à la concurrence, l'an prochain.
DG: Je pourrai choisir mon fournisseur en électricité ????
MZ: Oui: quand tu mettras thermostat 7, la Générale des Eaux chauffera le four.
-+- in: Guide du Cabaliste Usenet - Bien configurer son four -+-

Michael Hudson

unread,
Feb 17, 2000, 3:00:00 AM2/17/00
to
Remi VANICAT <van...@labri.u-bordeaux.fr> writes:

> Michael Hudson <mw...@cam.ac.uk> writes:
>
> > STARYNKEVITCH Basile <Basile.Sta...@cea.fr> writes:
> >
> > > [ ... interesting stuff ... ]
> > >
> > > See also the Ocaml web pages (and mailing list archive)
> > > "http://caml.inria.fr/ocaml/"
> >
> > Thanks for that post. As a vaguely relavent followup question do you
> > know of any (paper) books describing ocaml? Are there any planned?
> > Searching on amazon.co.uk gets you lots of books about camels :-(.
>
> there is :
>
> THE FUNCTIONAL APPROACH TO PROGRAMMING
>
> Guy Cousineau and Michel Mauny
> Cambridge University Press, Cambridge, 1998, ISBN 0-521-57183-9
> (hardcover), 0-521-57681-4 (paperback)
>
> (it's seem to bee the only book in english
> see http://pauillac.inria.fr/caml/books-eng.html)

Thanks! But: £65 on amazon. Ouch.

Maybe I'll wait for the paperback.

M.

Stefan Axelsson

unread,
Feb 17, 2000, 3:00:00 AM2/17/00
to
In article <uvh3nd...@firstenergycorp.com>,

Kevin Hostelley <hoste...@firstenergycorp.com> wrote:
>
>I'm not trying to start a war, but what are the reasons that someone
>would choose to use a functional language.

Well you could start with:

http://www.cs.chalmers.se/~rjmh/Papers/whyfp.html

http://www.eecs.harvard.edu/~nr/icfp/final.ps

http://haskell.org/papers/NSWC/jfp.ps

The two latter papers demand very little of the reader.

If you browse around on www.haskell.org, etc, you'll find lots of
interesting stuff.

Stefan,
--
Stefan Axelsson Chalmers University of Technology
s...@rmovt.rply.ce.chalmers.se Dept. of Computer Engineering
(Remove "rmovt.rply" to send mail.)

Remi VANICAT

unread,
Feb 17, 2000, 3:00:00 AM2/17/00
to
Michael Hudson <mw...@cam.ac.uk> writes:

> Remi VANICAT <van...@labri.u-bordeaux.fr> writes:
>

[...]

> > there is :
> >
> > THE FUNCTIONAL APPROACH TO PROGRAMMING
> >
> > Guy Cousineau and Michel Mauny
> > Cambridge University Press, Cambridge, 1998, ISBN 0-521-57183-9
> > (hardcover), 0-521-57681-4 (paperback)
> >
> > (it's seem to bee the only book in english
> > see http://pauillac.inria.fr/caml/books-eng.html)
>
> Thanks! But: £65 on amazon. Ouch.
>
> Maybe I'll wait for the paperback.

there is also the "An introduction to Objective Caml" at the beginning
of their refman, (I have learn a lot of thing from there) and some
material available from there :

http://pauillac.inria.fr/caml/hump.html#lectnotes

>
> M.

Brian Rogoff

unread,
Feb 17, 2000, 3:00:00 AM2/17/00
to
On 17 Feb 2000, Markus Mottl wrote:

> Michael Hudson <mw...@cam.ac.uk> wrote:
> > Thanks for that post. As a vaguely relavent followup question do you
> > know of any (paper) books describing ocaml? Are there any planned?
> > Searching on amazon.co.uk gets you lots of books about camels :-(.
>

Well, that's really a book which uses and teaches Caml Light, not OCaml.
There are lots of little differences that will annoy a beginner if they
don't realize that. (For instance, there are different lexical rules in
OCaml, and user defined infixes are treated differently, etc.).

Still, I really like that book, and the old Caml tutorial.

The single biggest problem with OCaml IMO is not that it doesn't compile
down to C/Fortran speed code for crypto-numerical-linear-algebra-DSP-bignum
-regex-... type programs but that the available documentation far lags
the state of the language. That's the price to be paid for working with an
evolving rather than a standardized language, but its a rather large
barrier to entry for working programmers who'd like to quickly determine
whether there is anything to be gained from learning the language.

Also IMO, its still worth the trouble. OCaml easily trounces its main
competitors in my current areas of interest.

-- Brian


Dominic Steinitz

unread,
Feb 17, 2000, 3:00:00 AM2/17/00
to
I would have thought Haskell would be a more natural choice for someone
coming from Cambridge. There's the book by Simon Thompson and the book by
Bird and Wadler.

Michael Hudson wrote in message ...


>STARYNKEVITCH Basile <Basile.Sta...@cea.fr> writes:
>
>> [ ... interesting stuff ... ]
>>
>> See also the Ocaml web pages (and mailing list archive)
>> "http://caml.inria.fr/ocaml/"
>

>Thanks for that post. As a vaguely relavent followup question do you
>know of any (paper) books describing ocaml? Are there any planned?
>Searching on amazon.co.uk gets you lots of books about camels :-(.
>

>Cheers,
>Michael

Hartmann Schaffer

unread,
Feb 17, 2000, 3:00:00 AM2/17/00
to
In article <ya3emab...@serveur3-1.labri.u-bordeaux.fr>,

Remi VANICAT <van...@labri.u-bordeaux.fr> writes:
> Michael Hudson <mw...@cam.ac.uk> writes:
>
>> STARYNKEVITCH Basile <Basile.Sta...@cea.fr> writes:
>>
>> > [ ... interesting stuff ... ]
>> >
>> > See also the Ocaml web pages (and mailing list archive)
>> > "http://caml.inria.fr/ocaml/"
>>
>> Thanks for that post. As a vaguely relavent followup question do you
>> know of any (paper) books describing ocaml? Are there any planned?
>> Searching on amazon.co.uk gets you lots of books about camels :-(.
>
> there is :
>
> THE FUNCTIONAL APPROACH TO PROGRAMMING
>
> Guy Cousineau and Michel Mauny
> Cambridge University Press, Cambridge, 1998, ISBN 0-521-57183-9
> (hardcover), 0-521-57681-4 (paperback)
>
> (it's seem to bee the only book in english
> see http://pauillac.inria.fr/caml/books-eng.html)

a word of warning: this book, though quite excellent, deals with cal
light, which isn't identical to Ocaml, even if you disregard the o in
ocaml

--

Hartmann Schaffer

It is better to fill your days with life than your life with days

Nick Williams

unread,
Feb 17, 2000, 3:00:00 AM2/17/00
to
In article <950816085.8449.0...@news.demon.co.uk>,
Dominic Steinitz <dom...@geneva.demon.co.uk> wrote:

>I would have thought Haskell would be a more natural choice for someone
>coming from Cambridge. There's the book by Simon Thompson and the book by
>Bird and Wadler.

But Simon Thompson is at UKC, Philip Wadler is at Bell
(previously Glasgow) and Richard Bird is at the Comlab here;
what's the Cambridge connection? :-)

As far as I remember, the functional programming course at
Cambridge is in ML, rather than Haskell... (maybe they changed
recently?)

Cheers,

Nick.

--

[ Nick Williams ]
[ MSc Computation Mobile - 07957-138179 ]
[ New College, Oxford http://www.new.ox.ac.uk/~nick/ ]

Jón Fairbairn

unread,
Feb 17, 2000, 3:00:00 AM2/17/00
to
ni...@thelonious.new.ox.ac.uk (Nick Williams) writes:

> But Simon Thompson is at UKC, Philip Wadler is at Bell
> (previously Glasgow) and Richard Bird is at the Comlab here;
> what's the Cambridge connection? :-)

I'm here. But I'm asleep.

There's also a bunch of folk in the market square who might constitute
a connexion betwen Cambridge and Haskell...

--
Jón Fairbairn Jon.Fa...@cl.cam.ac.uk

Michael Hudson

unread,
Feb 17, 2000, 3:00:00 AM2/17/00
to
j...@cl.cam.ac.uk (Jón Fairbairn) writes:

> ni...@thelonious.new.ox.ac.uk (Nick Williams) writes:
>
> > But Simon Thompson is at UKC, Philip Wadler is at Bell
> > (previously Glasgow) and Richard Bird is at the Comlab here;
> > what's the Cambridge connection? :-)
>
> I'm here. But I'm asleep.
>
> There's also a bunch of folk in the market square who might constitute
> a connexion betwen Cambridge and Haskell...

Yes, and what an unobtrusive entrance it is too. Maybe they're afraid
of looters, or something.

I've already got the Thompson book, anyway. Now I want to learn Ocaml
(I collect languages like some people collect stamps).

Cheers,
Michael

0 new messages