Author: Frank Kruchio
frank.kruchio (AT) paradise.net.nz
Lecturer: Dr Neil Leslie
April 26, 5PM, 2002
Programming languages have fundamental differences.
These differences are especially evident between the functional and imperative classes of languages.
While computationally they are equivalent, the roots of functional programming languages are in
calculus.
A good programmer should have the ability to choose a particular language from a class of programming languages, that is most suitable
for the current job.
It makes one think and ask if this or a similar experiment were conducted again today; how would the outcome change. If Haskell could displace commonly used languages nearly a decade ago, then it is necessary to consider the reasons for withholding widespread use. The ability to recognise the potential in Haskell and functional programming appears to require a change in the mind-set of the main stream programmer. This review will consider these issues and highlight the key points in the Hudak/Jones paper.
Some would argue that, the order of productivity may not be 20:1 as the ratio of lines suggests; but the productivity gain is obvious. No other language in the experiment can even come close to this conciseness in code length. In general the conciseness of a Haskell solution is due to the following points:
If programming experts failed in an attempt to solve a real world problem and a college graduate succeeded, questions would be raised concerning the programming language. The first of these would relate to the specific language used. We learned, that Haskell is a programming language that appears to be better suited to solve a large subset of the real world problems.
There is more evidence that Haskell is a good prototyping language.
Bagley [1] compared 30 programming languages: in his experiment, Haskell consistently beaten other languages in code brevity.
In a large project, complexity grows exponentially and good modularity is an important issue.
As Hugh [4] pointed out conventional languages place limits on the way problems can be modularised.
Haskell seems to provide the right sort of `glue', in the form of higher-order functions and laziness that supports modularity.
People and organisations are reluctant to change programming languages [7].
However, once Haskell's strengths as a prototyping language are realised, it is only a short step from there to gain widespread acceptance as a
replacement for common imperative languages.
Haskell's higher-order, polymorphic type system offers benefits for the programmer. Typing provides information to both, the programmer and the compiler. Type errors are one of the most difficult to find errors. The static type system in Haskell provides several benefits:
The clear, concise, expressive Haskell code indicates the ability of the language to scale better and higher on more complex projects
than conventional languages.
Scalability is not just a technical issue.
The average person has the ability to concentrate on at most seven things at any given time.
It is obviously easier and faster to read and understand 85 lines of Haskell code than the 1100 lines of C++ code.
Haskell's approach and `toolkit' of higher-order functions, parametric polymorphism, the usual ad-hoc polymorphism and lazy evaluation
provides a powerful way of reusing code.
This powerful code reuse provides significant gains in productivity compared to any imperative language today.
The benefit of Haskell is the ability to handle the complexity, in a far more convenient way.
It could be argued that, if the experiment were conducted today the end result would be the same.
Haskell has further matured, refined in the last few years and no ground-breaking new languages has been introduced since.
Ironically, all the competing programming languages had an expert writing the attempted solution except Haskell; where a college
graduate had 8 days to `catch up' with the years of experience of the experts [3] (p 4).
The code to document ratio was also notably better in the Haskell version.
The functional programming community has a good understanding of what imperative programming languages are.
They are aware of the advantages and disadvantages of both, the functional and imperative programming languages.
However, this observation does not hold for the majority of the imperative programming community.
Programming in Haskell requires a very different mind-set.
It is difficult to explain a functional programming language to an imperative programmer, that has no variables, no assignments and no statements
only expressions.
In general, programmers get the impression that Haskell is restricted as they have no control over program execution.
This is not the case.
This is an issue when imperative programmers label higher-order functions as a `trick', simply because they do not understand the concept that
underlies higher-order functions.
It is clear that since the implementation details were left up to the participants, the other programming languages did not have the same tricks
available.
I have no doubt that expert programmers would be aware of those if they existed.
As Thompson expressed [8](p 3) ``A functional programmer will concentrate on the relationships between values''.
This is a very different notion from Alan Kay's ``everything is an object'' approach.
The paper concludes that ``sociological and psychological barriers must be overcome''.
Programming in Haskell and indeed in any functional programming language requires an approach that can be best described as
thinking functionally.
The table on page
shows the progress of abstraction in programming in the last 50 years.
The available language constructs in Haskell are unique when one compares them to languages such as C++ or Java.
There is no need to worry about execution path and side effects of changing variables as we do not need to declare variables in the first place.
These all add up when productivity is an obvious concern.
Schach [7] points out that when 4-th generation languages were introduced, companies reported a ``10-fold increase in productivity''.
Looking at the difference between the conciseness and expressivity of Haskell in the experiment suggests that the same claim could be made when one
compares Haskell to current fourth generation languages (4GL) and 5GL languages.
|
-- Quicksort in Haskell, using list comprehensions
-- Choose the head as the pivot, divide & conquer
qsort [] = []
qsort (pivot:t) = qsort[ y | y <- t, y < pivot]
++ [pivot] ++ qsort[ y | y <- t, y >= pivot]
Verifying a functional program is far easier, because of their mathematical, recursive (inductive) nature.
Furthermore, Haskell encourages a modular programming style, which is considered a positive approach in both, programming and proofs.
The Haskell definition of quick-sort is the most elegant, clear and concise implementation there is.
While the list comprehension construct is a syntactic sugar, it is here where its benefit is clearly shown.
List comprehension provides a powerful way to express complex constructs with minimum coding.
Haskell's clean semantics makes for much easier proofs of program correctness.
Since the geo-server is just one part of a much larger system, implementing the whole system would be a more complex issue than just implementing the geo-server. If the whole system is implemented in Haskell, the overall system maintenance, code readability and understandability is improved due to the Haskell syntax. Further modifications to the whole system can be implemented in a fraction of the time than it requires in, say, C++. According to Jarvis [5](p 35) ``One of the benefits of functional languages is the ease with which programs can be analysed.'' Another testament of the flexibility of the Haskell language is that Haskell can represent the region several different ways. They simply chose not to, as the use of higher-order functions provided them with a more powerful concept to solve this particular problem. [3](p13)
type Region = Point -> Bool
Lazy evaluation is another way how Haskell can work on infinite lists, trees and bring a new powerful aspect to programming that
is not available in imperative languages.
Lazy evaluation has many benefits.
While it is not obvious, Hughes [4] pointed out that laziness supports modularity.
Haskell only evaluates an expression once, it has no side-effects like imperative languages do.
The underlying implementation uses graphs [8](pp. 339-340) in the evaluation of expressions.
There is research currently in progress that experiments with functional languages in a semi-lazy evaluation environment.
The theoretical benefits would include the current benefits of lazy evaluation and improved performance over lazy evaluation.
When one speaks of modularity the ability of the language to allow the creation of modular structures is not enough by itself.
The language also must support the ability to easily combine these parts.
Haskell stands out when this point is examined with its exceedingly good modularity support.
One could argue that Haskell redefined the concept of reusability with flawless elegance.
Personally, functional programming in Haskell certainly was an eye opener for me after several years of object-oriented programming.
Other languages follow the pattern of the convenient Haskell layout. Python is one example where a similar layout rule used. This is an indication that the imperative programming community is taking functional languages seriously and is ready to adapt good ideas. The adaption of the positive ideas from functional programming will eventually lead to widespread acceptance of Haskell. I would have liked to have seen how the authors think about changing the mind-set of the imperative world to harness the power of Haskell.
This document was generated using the LaTeX2HTML translator Version 99.2beta8 (1.43)
Copyright © 1993, 1994, 1995, 1996,
Nikos Drakos,
Computer Based Learning Unit, University of Leeds.
Copyright © 1997, 1998, 1999,
Ross Moore,
Mathematics Department, Macquarie University, Sydney.
The command line arguments were:
latex2html -antialias_text -scalable_fonts -split 1 review1.tex
The translation was initiated by frank on 2002-05-21