45

I've heard a lot about functional programming languages and I'm willing to learn one. I guess it will be mostly for fun, however, I hope it will improve my programming skills.

I have mostly C#/.NET background, so my first choice is to learn F# (because of .NET and familiarity with Visual Studio). On the on other hand, I wonder if F# has features like Lisp macros or Haskell higher order functions.

Could you compare F#, Haskell and Lisp? Which one will be the language of your choice?

Don Stewart
  • 137,316
  • 36
  • 365
  • 468
empi
  • 15,755
  • 8
  • 62
  • 78
  • 2
    Amazingly subjective question. But hell I'll bite. Lisp because its the godfather of functional languages. But in all seriousness if you can program in lisp you can work in scheme (I'd go with scheme over F#) and Haskel. – bdd Feb 10 '10 at 12:28
  • 2
    If you are considering Lisp, you would need to narrow it down to a particular dialect: http://stackoverflow.com/questions/2114819/why-is-the-lisp-community-so-fragmented – Justin Ethier Feb 10 '10 at 12:44
  • 2
    If you're considering F#, then you may be interested in my "Real World Functional programming" book (http://www.manning.com/petricek). It is written for C# developers and it also demonstrates how to use functional techniques in C# (in fact, you probably already use some of them!) Learning F# would be probably easier for you, but Haskell or Lisp show some of the ideas in a clearer form. – Tomas Petricek Feb 10 '10 at 13:41
  • 1
    community wiki? subjective tag?!! – Michael Easter Feb 10 '10 at 14:03
  • Empi--maybe you want to narrow the dimension of comparison? This is an extremely broad question. – Onorio Catenacci Feb 10 '10 at 15:27
  • 1
    @Paperino: Actually, I would say that Scheme is more forgiving than Haskell. So OP, if you can program in *Haskell*, you can work in Scheme or another LISP dialect. – Vlad the Impala Aug 20 '11 at 06:39
  • Initially I'd say its almost worth looking at F# for the single reason that you get to use the Visual Studio editor and debugger - which is a high quality tool. – dodgy_coder May 03 '12 at 06:52
  • I think you should first learn LOGO. Put the environment first and save the turtles! – gonzobrains Sep 30 '13 at 23:36
  • there are other multi-paradigm languages with the functional paradigm in it, examples are Scala,Clojure(JVM dialect of Lisp),ceylon(this is still new and its functional performance isn't as good as others yet) all the previous are JVM-based languages – niceman Jul 31 '15 at 19:53

9 Answers9

46

F# is my language of choice, but I'd strongly recommend learning them all. They are all quite different and interesting in their own right. Here's a quick over view to each one (with perhaps a slight F# bias), you can easily find more info by googling:

F# - is a language that makes it easy to program in the functional style, lets you easily copy objects rather than mutating them. It also gives you interesting data types, like tuples and algebraic data types, useful language constructs such as pattern matching and list comprehensions. It also has OO and imperative features and good access to libraries, since you can use any .NET framework component.

Haskell - is a pure and lazy functional language, making a rare or even unique beast. This means there are no side effects at all, unless they are tracked by a monad. Haskel too has tuples, algebraic data and pattern matching.

Lisp - whereas F# and Haskell are statically typed, lisp is dynamically typed. It has distinctive syntax which uses lots of parentheses and provides an interesting macro feature that allows you to make transformations to the program itself and extend the syntax.

Games Brainiac
  • 80,178
  • 33
  • 141
  • 199
Robert
  • 6,407
  • 2
  • 34
  • 41
  • 8
    In Haskell, there are more ways to track side effects other than monads, such as arrows and applicatives. – Martijn Feb 19 '10 at 19:22
29

I had the same question once

Since then, I have done some programming in F#. Now I am very glad I did, since it is realy helpful to understand LINQ in C# and that happened to be my background too. (I almost never use foreach in C# now since I learned F#)

I learned through F# a lot of things about lazy evalution, lists and sequences, all of which you could pick any language for with good support for lists, tuples, and so on (like any functional language I guess), but if you pick F#, all of this will be very useful in C# too. Maybe you already know all of this stuff and use it right, but in case you don't, pick F#.

I started out here : a very nice video tutorial, very impressive and a very inspiring tutor.

Olivier De Meulder
  • 2,493
  • 3
  • 25
  • 30
Peter
  • 47,963
  • 46
  • 132
  • 181
  • that video is an excellent introduction to the power of F# – eric.christensen Mar 20 '10 at 05:54
  • 1
    I had a very similar experience, I read Expect F# in 2008 but only practiced the language a little at the time, but I applied the concepts I learned quite effectively to my day work in C#, which in turn re-enforced my recent vigorous efforts learning F# in practice! – Stephen Swensen Dec 07 '10 at 03:00
18

Currently I'm watching these video's on Channel 9 on the basics of Functional programming. It's explained using Haskell, but the basics apply to all languages. I must say it's very informative and easy to understand.

Tony The Lion
  • 61,704
  • 67
  • 242
  • 415
  • 3
    I think there is a reason why Erik Meijer teaches functional programming with haskell and not F#. There are certain features (e.g. no side effects) that only haskell supports. So +1 for haskell – mrsteve Jul 27 '11 at 00:37
8

This is a very subjective question.

My opinion is that Scheme (a Lisp variant) and reading SICP is the right thing. You will learn a lot.

But for practical purposes and if you are a .NET developer then maybe F# is better.

sastanin
  • 40,473
  • 13
  • 103
  • 130
Arve
  • 7,284
  • 5
  • 37
  • 41
8

I don't know F# but I like to play with it sometimes. My language is Clojure which is very functional and works on the CLR too, but the JVM version is the main version.

It overs you a lot of the stuff you want. The main diffrence to F# is that Clojure is dynamicly typed and it has really good way handle concurency (one of the best I would say).

BTW. Did you know that F# was made because Haskell was to hard to get running on the CLR? (Thats not the whole story of course but its part of it)

sastanin
  • 40,473
  • 13
  • 103
  • 130
nickik
  • 5,809
  • 2
  • 29
  • 35
8

Nobody actually answered this specific question: "I wonder if F# has features like Lisp macros or Haskell higher order functions."

F# does not offer macros. Also, it does not offer higher-kinded types (which is what I thought you were asking at first).

F# does offer higher-order functions in that you can easily write a function that takes a function and returns a function. In fact, C# (or really any .NET language) can do this as the Func delegate is part of the .NET framework.

Justin
  • 8,853
  • 4
  • 42
  • 42
  • F# user-voice has a suggestion for macros which will hopefully go through: [linky](http://fslang.uservoice.com/forums/245727-f-language/suggestions/5674940) (Don't forget to vote if interested! can quickly log in via Google/Facebook). – MasterMastic Apr 14 '14 at 23:06
7

Why choose? Learn both Lisp and Haskell on your own. No point in learning F# on your own time though. If you need it for work, you'll learn it at work ;)

EDIT: The guy was looking at language to learn for fun. Well, Lisp and Haskell are good candidates since fun is all they are going to be used for (no paid jobs there). He "might" (although unlikely) have opportunity to use F# at work (he is in MS shop), so why learning something in free time when he can be paid learning it at work.

Rayne
  • 31,473
  • 17
  • 86
  • 101
Marko
  • 30,263
  • 18
  • 74
  • 108
  • 3
    "No point in learning F# on your own", what??? – Bruno Reis Feb 10 '10 at 14:11
  • 3
    No jobs? Someone should tell http://lispjobs.wordpress.com/ so they can shut down the site. ;) – mipadi Feb 10 '10 at 16:54
  • 4
    @mipadi: Well, if they are posting 2 new jobs every two months, they should really shut down the site ;) – Marko Nov 29 '10 at 10:01
  • 1
    F# does not figure in the top 50 TIOBE index, while LISP is in ranked 13. – Marcel Valdez Orozco May 06 '13 at 01:15
  • 1
    "... Haskell are good candidates since fun is all they are going to be used for (no paid jobs there)." This makes me sad... I think the industry missed out on Haskell.. Sometimes I want to start my own company just so I can FORCE software engineers to learn Haskell! – poy Oct 21 '13 at 17:26
5

If We compare this three languages I'll recommend Haskell. It is more practical than LISP I think (because it's type system) and more powerful and clever than F#. As far as you know F# is a .NET port of OCaml and to some extent it is not ideoligally clear as Haskell is or as OCaml is. I'll recommend you study Haskell or OCaml to know how inconvinient F# is.

Kakadu
  • 2,837
  • 19
  • 29
  • I've heard that the reason F# was created was that Haskell's type system was too sophisticated to be ported to .NET – jpaugh Oct 08 '14 at 19:55
  • Well, they ported some OCaml features to .NET and didn't port some OCaml features which are difficult to port to .NET. Does it make F# better than OCaml? Don't think so. If some features can't be ported somewhere it doesn't mean they are not useful. It remembers me a joke about Java programmers which are thinking like "There are no lambdas in Java, that's why they are useless". – Kakadu Oct 09 '14 at 13:31
  • I was actually hinting that Haskell is better than F#. But I haven't tried F# yet, so take it FWIW. – jpaugh Oct 09 '14 at 21:27
5

I learned all of them to a diffeent degree, and would advise starting with Scheme (a Lisp dialect) - simply because it is easiest to learn. Haskell and F# are statically typed, which is a big advantage for real-life projects, but IMHO they have a little "too much" syntax and are not as easy to pick up as Scheme.

There is a nice Scheme implementation for .NET - IronScheme. You can take a look at my article "Playing with IronScheme" to see if you like it.

Nemanja Trifunovic
  • 24,346
  • 3
  • 50
  • 88