views:

685

answers:

5

I was working with a Lisp dialect but also learning some Haskell as well. They share some similarities but the main difference in Common Lisp seems to be that you don't have to define a type for each function, argument, etc. whereas in Haskell you do. Also, Haskell is mostly a compiled language. Run the compiler to generate the executable.

My question is this, are there different applications or uses where a language like Haskell may make more sense than a more dynamic language like Common Lisp. For example, it seems that Lisp could be used for more bottom programming, like in building websites or GUIs, where Haskell could be used where compile time checks are more needed like in building TCP/IP servers or code parsers.

Popular Lisp applications: Emacs

Popular Haskell applications: PUGS Darcs

Do you agree, and are there any studies on this?

+4  A: 

You're opening multiple cans of very wriggly worms. First off, the whole strongly vs weakly typed languages can. Second, the functional vs imperative language can.

(Actually, I'm curious: by "lisp dialect" do you mean Clojure by any chance? Because it's largely functional and closer in some ways to Haskell.)

Okay, so. First off, you can write pretty much any program in pretty much any normal language, with more or less effort. The purported advantage to strong typing is that a large class of errors can be detected at compile time. On the other hand, less typeful languages can be easier to code in. Common Lisp is interesting because it's a dynamic language with the option of declaring and using stronger types, which gives the CL compiler hints on how to optimize. (Oh, and real Common Lisp is usually implemented with a compiler, giving you the option of compiling or sticking with interpreted code.)

There are a number of studies about comparing untyped, weakly typed, and strongly typed languages. These studies invariably either say one of them is better, or say there's no observable difference. There is, however, little agreement among the studies.

The biggest area in which there may be some clear advantage is in dealing with complicated specifications for mathematical problems. In those cases (cryptographic algorithms are one example) a functional language like Haskell has advantages because it is easier to verify the correspondence between the Haskell code and the underlying algorithm.

Charlie Martin
Common Lisp is also strongly typed, it just determines the type at runtime, i.e. it is dynamically typed (as opposed to static, like Haskell). Do not confuse "static" <-> "dynamic" with "weak" <-> "strong"!
Svante
Also, Common Lisp supports a wide variety of programming styles, including functional programming, so this controversy is also rather a side topic (in that Haskell is "pure" while CL also lends itself to other ways).
Svante
Harlequin, *C* supports a functional style if you want it to. Haskell has no imperative assignment, Clojure only allows it in a restricted special form. Common Lisp lets you write functionally, but doesn't enforce it, as do Ruby and Python.
Charlie Martin
No, C _allows_ a functional style, that is totally different from _supporting_ it. You can directly write everything in functional idioms in CL, just like you would in Scheme or Haskell. "Force" is no prerequisite for "support". Of course, you _can_ do anything in any Turing-complete language.
Svante
You're quibbling about what the meaning of "is" is. Common Lisp let's you write anything functionally, but the program stops being truly a functional program with the first misplaced `setf`. Clojure at least forces you to put imperative core in special blocks and enforces transactional memory.
Charlie Martin
+4  A: 

I come mostly from a Common Lisp perspective, and as far as I can see, Common Lisp is suited for any application.

Yes, the default is dynamic typing (i.e. type detection at runtime), but you can declare types anyway for optimization (as a side note for other readers: CL is strongly typed; don't confuse weak/strong with static/dynamic!).

I could imagine that Haskell could be a bit better suited as a replacement for Ada in the avionics sector, since it forces at least all type checks at compile time.

I do not see how CL should not be as useful as Haskell for TCP/IP servers or code parsers -- rather the opposite, but my contacts with Haskell have been brief so far.

Svante
Haskell is not useful as an Ada replacement. Haskell has often unpredictable performance due to lazy data structures and garbage collection. That's not desirable in flight software.
Rainer Joswig
+12  A: 

Programming languages are tools for thinking with. You can express any program in any language, if you're willing to work hard enough. The chief value provided by one programming language over another is how much support it gives you for thinking about problems in different ways.

For example, Haskell is a language that emphasizes thinking about your problem in terms of types. If there's a convenient way to express your problem in terms of Haskell's data types, you'll probably find that it's a convenient language to write your program in.

Common Lisp's strengths (which are numerous) lie in its dynamic nature and its homoiconicity (that is, Lisp programs are very easy to represent and manipulate as Lisp data) -- Lisp is a "programmable programming language". If your program is most easily expressed in a new domain-specific language, for example, Lisp makes it very easy to do that. Lisp (and other dynamic languages) are a good fit if your problem description deals with data whose type is poorly specified or might change as development progresses.

Language choice is often as much an aesthetic decision as anything. If your project requirements don't limit you to specific languages for compatibility, dependency, or performance reasons, you might as well pick the one you feel the best about.

Allen
+1  A: 

Haskell is a pure functional language. While it does allow imperative constructs (using monads), it generally forces the programmer to think the problem in a rather different way, using a more mathematical-oriented approach. You can't reassign another value to a variable, for example.

It is claimed that this reduces the probability of making some types of mistakes. Moreover, programs written in Haskell tend to be shorter and more concise than those written in typical programming languages. Haskell also makes heavy use of non-strict, lazy evaluation, which could theoretically allow the compiler to make optimizations not otherwise possible (along with the no-side-effects paradigm).

Since you asked about it, I believe Haskell's typing system is quite nice and useful. Not only it catches common errors, but it can also make code more concise (!) and can effectively replace object-oriented constructs from common OO languages.

Some Haskell development kits, like GHC, also feature interactive environments.

Eduard - Gabriel Munteanu
A: 

The best use for dynamic typing that I've found is when you depend on things that you have no control over so it could as well be used dynamically. For example getting information from XML document we could do something like this:

var volume = parseXML("mydoc.xml").speaker.volume()

Not using duck typing would lead to something like this:

var volume = parseXML("mydoc.xml").getAttrib["speaker"].getAttrib["volume"].ToString()

The benefit of Haskell on the other hand is in safety. You can for example make sure, using types, that degrees in Fahrenheit and Celsius are never mixed unintentionally. Besides that I find that statically typed languages have better IDEs.

Daniel W