Perl Internationalization and Haskell: An Interview with Autrijus Tang
by Edd Dumbill
|
Pages: 1, 2
On Haskell
ED: One of your other interests is Haskell, which you say is "faster than C++, more concise than Perl, more regular than Python, more flexible than Ruby, more typeful than C#, more robust than Java, and has absolutely nothing in common with PHP." Given this build-up, could you explain Haskell in one or two sentences?
AT: Haskell is a pure functional language optimised for conciseness and clarity. It handles infinite data structures natively, and offers rich types and function abstractions that give Haskell programs a strong declarative flavor--the entire Pugs compiler and runtime is under 3000 lines of code.
ED: Could you share a short Haskell program that might illustrate some of its good points?
AT: Sure. The program below prints the first 1000 Hamming numbers: i.e. positive integers whose factors are limited to powers of 2, 3, and 5.
main = print (take 1000 hamming)
hamming = 1 : map (2*) hamming ~~ map (3*) hamming ~~ map (5*) hamming
where
xxs@(x:xs) ~~ yys@(y:ys) -- To merge two streams:
| x==y = (x : xs~~ys) -- if the heads are common, take that
| x<y = (x : xs~~yys) -- otherwise, take the smaller one
| x>y = (y : xxs~~ys) -- and proceed to merge the rest
This program is strikingly compact; you can read the algorithm straight off it. Lazy evaluation allows us to define an infinite list with itself. A user-defined lexical operator "~~" makes it more readable.
Furthermore, it is all statically typed, but we don't need to write any types explicitly. The compiler correctly inferred "hamming" is a list of arbitrary-precision integers. If we add a line of type annotation:
hamming :: [Int]
hamming = ...
Then it will use platform-native "int" for faster calculation, yielding a performance comparable to C implementations.
ED: What makes Haskell competitive among modern programming languages?
AT: Most languages require you to pay a "language tax": code that does nothing with the main algorithm, placed there only to make the computer happy.
Thus there is a threshold of refactoring: if introducing a new class or a new function costs five lines, programmers are encouraged to copy-and-paste four lines over and over again instead of abstracting them out, even with help from a good refactoring browser.
On the other end of spectrum, we often shy away from abstracting huge legacy code because we are afraid of breaking the complex interplay of flow control and global and mutable variables. Besides, the paths leading to common targets of refactoring--those Design Patterns--are often non-obvious.
Because Haskell makes all side effects explicit, code can be refactored in a safe and automatic way. Indeed, you can ask a bot on #haskell to turn programs to its most abstracted form for you. Haskell also encourages you to shape the language to fit your problem domain, so the program often reads out like a runnable specification.
ED: How would people get started writing Haskell?
AT: Learning Haskell requires some brain rewiring, so the best way to learn it is by coding something in it for real. Yuval, a fellow "lambdacamel," learned Haskell from scratch by coding up a Forth parser, interpreter, and runtime all within a few days.
There are also some excellent online tutorials and books. We maintain a list of them in the Pugs source tree.
ED: Are there Haskell communities?
Yes. Haskell.org is the main site of Haskell communities. There is a community report published every six months, and an active wiki containing additional pointers. The #haskell channel on irc.freenode.net is particularly helpful.
ED: Are there any Haskell jobs?
AT: Lots of new programming language research is done with (and on) Haskell, so much that I joked that it's "Powered by Ph.D." Consequently, there are quite a few jobs available in the academic sector.
Outside universities, there are some places that look for Haskell programmers explictly. As with other agile technologies, it works best with a small team and a client base that cares about the results, instead of demanding a specific language.







