views:

1098

answers:

9

This is the situation : I mostly program C# and have written types in it I don't want to lose. At the same time I would like to learn functional programming. The obvious answer of course is F#.

But for everything apart from C# I use emacs as an editor, and I really would like to learn Lisp too. (Learn your editors/IDE's language you know, that's why I know a bit VB to write my VS-macro's in it) And it's not just emacs, Lisp is something I really want to learn.

As for F#, I could mingle it with C# without any interop problem, have a great GUI (WPF) and a lot of other .NET goodies. But it is, of course, not as mature as Lisp.

If I am realistic I know if I want to smuggle a functional language into my professional life it has to be F#. Since learning two whole languages seems a bit much, I was hoping that Lisp would be a great way to learn functional programming, and if I start out F# later, It would be very easy....

Is this true? Or are the two languages not comparable at all?

+3  A: 

They are both functional languages but syntactically they are very different. That means that a lot of the concepts will be similar and you (as a procedural developer) will have to do the same mind-bending to use either but they are very different languages.

F# is a derivative of ML (which is considered, with all its derivatives, to be an impure functional language) whereas Lisp is older and is considered to be a "pure" functional language.

The purity of a functional language is a fascinating topic and I would recommend that you read Language Purity and Dirty and Clean Functions to better understand the concept:

Many people talk about "pure" functional languages, where "pure" seems to be a synonym for "good". There are two traits commonly associated with the definition of a pure functional language:

  1. functions can not have side-effects
  2. a function called with any given arguments will always return the same value.
Andrew Hare
Modern implementations of Lisp aren't pure functional, although you can write pure functional programs easily.
David Thornley
Lisp dialects are usually not pure functional languages.
Rainer Joswig
+3  A: 

F# is most comparable to the ML family of languages, such as SML and CAML. The syntax and features are different from Lisp.

But I think learning at least one functional language is really important from a computer science perspective. Being able to think that way is good.

And, I would say, learning a more purely functional language before starting F# would be a way to pick up good functional programming habits because, if you don't, your F# code might end up being more OO and less functional, because that's where you're coming from.

Drew Hoskins
F# is not just comparable to ML - it is a derivative of it.
Andrew Hare
A: 

As a programming language Lisp is pretty special in it's own right however it's not similar to F# at all except that they both support functional programming. Not many language constructs carry over from Lisp to F#. If you want to learn lisp go for it. The idea of functional programming will carry over just not the syntax. Lisp is really old, late 50s. Many languages have been influenced by it and there are quite a few dialects.

If your just looking for a pure functional language to learn before F# i'd suggest Haskell. Haskell was heavily influenced by ML and is a good transition language to F# since F# is a derivative of ML. You can look at Haskell code and see similar patterns in F# code.

gradbot
Haskell is very different from any ML dialects.
Rainer Joswig
From dialects yes however "Many features of Haskell originate in ML, and the languages have quite similar "look-and-feel"." - taken from http://www.haskell.org/haskell-history.html
gradbot
Basically the FP community was divided which evaluation mechanism to sue by default. Haskell is non-strict and the ML family is strict. This makes huge difference. Haskell is THE standard non-strict language. Second Haskell is 'pure' (without side effects) and makes heavy use of constructs like monads. ML dialects usually non-pure. These differences at the core of these language families make them very different to use.
Rainer Joswig
+2  A: 

Two important things to consider is:

  • LISP is dynamically typed whereas F# is statically typed.
  • LISP has macro's built in. F# does not.

Although they are both considered functional and share many common features, they are also different. Learning LISP will certainly make you a better F# programmer and vice versa, but still you would have to learn the peculiarities of both to be able to be practical in them.

For being able to interop with .NET I would certainly choose F# but for the sake of programming beauty I would try LISP as well.

Michiel Borkent
+1  A: 

In my view, there are two approaches to learning functional programming:

  1. Use a more pure functional language like Lisp or Haskell that will force you to break out of a procedural mindset right away; or

  2. Use a pragmatic functional language like F# that also offers more familiar, but less functional, constructs to help you ease your way into it.

In either case, you'll get more out of the learning experience if you can do something useful with the language. It sounds like you have motivation for Lisp (Emacs) and F# (.NET interop), so I would be take a look at both and see what captures your attention.

Ultimately there's more value in understanding functional programming concepts (higher order functions, no side effects, tail recursion, etc) than any one language. And once you learn those concepts, it will be much easier to pick up new languages and apply the techniques in other languages (like the increasingly functional C#). Along those lines, you might be interested in Functional Programming for the Real World.

dahlbyk
you might be interested --> I am yes, tx. Further I think I go for the breakingout scenario and start out with Lisp
Peter
+8  A: 

I think there is only a small 'overlap' for what'd you'd learn via Common Lisp versus F#. The commonality is I think roughly

  • Programming with 'cons-lists' as a common fundamental data type, sometimes writing recursive (especially tail-recursive) functions rather than loops
  • Some basic uses of common higher-order functions (e.g. 'map' - apply a function to every value in a list)

Apart from some of that very core functional-programming stuff, I think Common Lisp and F# are about as far apart from each other as two mainstream 'functional' (non-Haskell) languages can be. Common Lisp is dynamic; F# is statically-typed. The syntactic forms are completely different. The runtimes are completely different. The libraries are very different. The object systems are completely different.

Regardless of which order you learn them, I think after learning one there will still be quite a bit more to learn in the other (modulo the small overlap I described above).

Brian
+10  A: 

Lisp is a large family of languages and implementations. Scheme for example is a Lisp dialect with probably more than one hundred implementations (about ten of them mildly popular). Common Lisp is another dialect with about ten currently maintained implementations. Scheme and Common Lisp both have written standards that implementations try to implement.

F# is both a language and implementation. From Microsoft. It was mostly derived from OCAML and belongs to the family of ML languages.

Lisp was a very early language supporting functional programming (Lisp 1.5 in the 60s). Lots of the early experiments with functional programming was done in Lisp. In the 70s in the Lisp community there was a movement to the roots of functional programming and the result was Scheme. Then especially in the 80s and 90s of the last century new functional languages appeared (ML, Miranda, FP, SML, Haskell, Clean, ...) that were/are quite different from the usual Lisp dialects. There is still some heritage, but mostly they developed in different directions (static typing, type inference, module systems, batch languages, algebraic data types, lazy evaluation, purity, and more). The Scheme community still has lots of contacts to the FP community. But that's mostly it.

There are some basic FP ideas that can be learned independent from a particular FP language, but generally F# is very different from most Lisp dialects. The other feature, that F# supports the .net ecosystem (especially since it is a Microsoft creation) is not that well supported by Lisp dialects.

I would also not expect much benefit from knowing a restricted Lisp dialect like Emacs Lisp for learning F#.

Rainer Joswig
Why the past tense of Lisp?
Thorbjørn Ravn Andersen
@Thorbjørn Ravn Andersen: 'Lisp' was very early a language, based on what the team around McCarthy designed. Later it was no longer a language, because it became a family of related languages and dialects. There was no longer the single 'Lisp' language anymore. The early Lisp is now history and we have different languages like Scheme, Common Lisp, Clojure, Logo, ...
Rainer Joswig
A: 

I am only new to F#, but I studied Lisp before F# and believe it was very helpful in contextualising F# within both the .NET framework and the gamut of programming languages.

I'd heartily recommend watching at least the first few videos here:

http://groups.csail.mit.edu/mac/classes/6.001/abelson-sussman-lectures/

These teach you the basics of Lisp within the first hour. The series builds upon that knowledge and instils the exciting principles that fall out from there.

Drew Noakes
+1  A: 

The semantics of F# and Scheme are very similar with the noted exception of strong typing.

Also, Scheme is so small, not to learn it!

leppie