Showing posts with label Haskell. Show all posts
Showing posts with label Haskell. Show all posts

Sunday, June 5, 2016

Should you use Haskell for a new project?

What are the pros and cons of trying to do a new project in Haskell, as opposed to some more mundane imperative language like Python or Java? Let's assume for the sake of argument that you are doing this for an employer, rather than for yourself as a side project. And let's also assume that you have a bit of Haskell experience, but like most programmers most of your work has been in mundane imperative languages.


To begin with, there are a couple of concerns that might kill an attempt to use Haskell.

  1. You might not be able to get management approval. Haskell is an obscure language with a reputation for difficulty. The bosses might well say no. 
  2. You might need to work with an existing codebase in something like Java or Python. Not possible from Haskell.

If those don't kill the project, there's the cost-benefit tradeoff. On the benefits side:

  1. Haskell code is very concise. (definitely) And greater concision means faster development. (possibly) 
  2. Haskell code is less likely to contain errors, because of very strict typing. (probably) 
  3. Haskell coders are disproportionately capable, because the language is obscure and difficult. (probably)

On the costs side:

  1. You have much more experience in other languages. It would take at least a year, maybe two before you'd be up to pro standards in Haskell. 
  2. The community of Haskell programmers is small. It might be difficult to hire anyone if the project grew; you might be faced with training someone from scratch, not just in a new language, but in a new programming paradigm.

So, this isn't anything like a slam dunk. Quite the opposite, actually. There are a couple of issues that might nix the project right up front, and then a daunting cost-benefit calculation.

Saturday, November 17, 2012

Three functional programming languages

Scala is a functional programming language that is designed to work well with Java. That doesn't come free, of course. The language makes some compromises to play well with legacy Java code and the JVM, but it does make Scala a very good Java 2.0. If you are interested in functional programming and want a language that you may actually get to use professionally, Scala is the safe bet. But it will not cure your cynicism.

Programming in Scala

Lisp was shot in the head a generation ago by Algol-style syntax, but like Lisbeth Salander, it never quite died. A tenacious band of enthusiasts keeps insisting the language is special, and has never been proved wrong. If you want to learn a timeless classic of a language with a reputation for changing the way you look at programming, Lisp is a good choice. Also, Paul Graham will send you a mash note.

Practical Common Lisp



Haskell is a pure functional programming language known for extreme expressivity. SkyNet would be 300 lines in Haskell, tops. Its relentlessly orthodox functional nature will force you to confront, interrogate, and ultimately deconstruct the imperative paradigm you have been trained in. You will see imperative coding for the fire-lit cave that it is and depart for a sun-bright world of functional programming. (Actual results may vary -- Platonic enlightenment not guaranteed.)

Learn You a Haskell for Great Good

Friday, July 27, 2012

FP languages are expressive

I've spent this week learning functional programming using two languages from opposite ends of the FP space: Haskell, an uncompromisingly functional language, and Scala, which mixes in some OO concepts with an eye to inter-operation with Java.

The central argument for FP is expressivity. Because of the power of the tools FP languages offer, you are supposed to be able to get a lot done with only a few lines of code.

To test this claim, I used both languages to implement a program from The Practice of Programming by Kernighan and Pike. The program reads in a file of text, generates a Markov-chain transition map from it, and then uses the map to produce random text. The authors implemented this program in several major languages, and found that the amount of code needed varied significantly: the C program was 150 lines, the Java was 105, and C++ clocked in at 70 lines.

Both Haskell and Scala did better than this. The Haskell program was 45 lines, and Scala did even better, at 41(!).

As far as I can tell, the FP enthusiasts' claim of greater expressivity is right on the money.