As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance.
Closed 10 years ago.
Given that a persona has extensive experience in different imperative programming languages right from C to JAVA. Whats the learning curve for functional programming languages such a Haskell ?
Before taking on Haskell you may find it easier to learn something that isn't purely functional, like a Lisp or ML. Given your Java experience, Clojure, a Lisp that runs on the JVM, might be a good place to start.
Like the OP, I came from an OOP/imperative background before jumping to functional programming around 2006ish.
I had lots of C# and Java under my belt, and wanted to learn a new language. I started on Python, picked up on Perl, and cut my teeth on C++. It was all fine and dandy, but there wasn't anything new to learn, I was basically re-learning the same language over and over again with a little different syntax. By accident, I stumbled on Paul Graham's classic article Beating the Averages, where he talks about Lisp and functional programming.
I thought it'd be fun to learn one of these "obscure" functional programming languages. So, between Erlang, Lisp, Haskell, and OCaml, I picked up OCaml for no particular reason except that camels are wicked cuteness (totally!). Lots and lots of new stuff to struggle with here:
Graaaaah, why I have to fight the compiler to get type-inference to work right?
Arrrragh, why aren't there any decent IDEs for this language? Why doesn't emacs have a GUI editor? Where's my intellisense!
Currying? Is that just a gimmick, or is it supposed to be useful?
Waaaaah, how can I do anything practical with algebraic data types?
[] -> ... | x::xs -> ..., WTF does that mean?
For me, moving from Java to Python was easy: similar architectural idioms, similar programming style, etc. The hardest part was really learning a new library, which takes all of 6 weeks to go from n00b to pro.
Moving from Java to OCaml was really really hard, because there's nothing build on, its like starting from step 0. It took about 6 months of waffling around with the language before I stopped saying to myself "now how would I do this in OCaml?"
In retrospect, I probably wouldn't have struggled as much had I started with Haskell. Optional mutability + OOP makes OCaml seem superficially like familiar territory, and monads are still a mystery to me.
Taken from link
Users of a procedural or object-oriented language like C, Java, or Python should beware, however: You'll have to forget most of what you already know about programming. Haskell is completely different from those languages, and requires a different way of thinking about programming. It's best to go into this tutorial with a blank slate and try not to compare Haskell to imperative languages, because many concepts in them (classes, functions, return) have a significantly different meaning in Haskell.
I haven't developed anything practical in functional programming languages, but I did not have very much trouble adapting to it.
Before starting, I'd suggest improving your thinking recursively, because that's what you're going to need to do, whether in a familiar or unfamiliar language.
Also, you'll need to adapt to the idea that functions are objects, you can pass them to functions, and functions can return them.
Haskell's learning curve is somewhat higher than other functional languages (like OCaml), though it is my personal favorite.
The key, IMO, is to think in terms of composition and inputs and outputs (if you come from OO, you probably think almost entirely in terms of inheritance -- this can hamper your learning).
Try to separate pure (no side effects) from impure (side effect -- example IO, state, etc).
Remember that functions are first-class citizens.
And learn the trick of partial function application. It is quite handy once you get used to it.
Related
Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 9 years ago.
Improve this question
I would like to learn a functional language in order to broaden my horizon. I have knowledge of Python and C/C++ and I want a language to be easy to learn from someone who comes from the imperative domain of languages. I don't care if the language is powerful enough. I just want a language in order to learn the basic of functional programming and then I will try for a more difficult (and powerful language).
Thanks
I recommend pure-lang for these pedagogical ends. It's also plenty powerful. If you want something more popular / with more community support, then I'd recommend Scheme or OCaml, depending on whether you'd rather deal with unfamiliar syntax (go with Scheme) or deal with unfamiliar typing (go with OCaml) first. SML and F# are only slightly different from OCaml. Others have or will mention Clojure, Scala, and Haskell.
Clojure is a variant of Scheme, with its own idiosyncracies (e.g. no tail-call optimization), so using it would be a way of starting with Scheme. I'd expect you'd have an easier time with a less idiosyncratic Scheme implementation though. Racket is what's often used for teaching. Scala looks to be fundamentally similar to OCaml, but this is based on only casual familiarity.
Unlike Haskell, the other languages mentioned all have two advantages: (1) evaluation-order is eager by default, though you can get lazy evaluation by specifically requesting it. In Haskell's the reverse. (2) Mutation is available, though much of the libraries and code you'll see doesn't use it. I actually think it's pedagogically better to learn functional programming while at the same time having an eye on how it interacts with side-effects, and working your way to monadic-style composition somewhat down the road. So I think this is an advantage. Some will tell you that it's better to be thrown into Haskell's more-quarantined handling of mutaton first, though.
Robert Harper at CMU has some nice blog posts on teaching functional programming. As I understand, he also prefers languages like OCaml for teaching.
Among the three classes of languages I recommended (Pure, Scheme and friends, OCaml and friends), the first two have dynamic typing. The first and third have explicit reference cells (as though in Python, you restricted yourself to never reassiging a variable but you could still change what's stored at a list index). Scheme has implicit reference cells: variables themselves look mutable, as in C and Python, and the reference cell handling is done under the covers. In languages like that, you often have some form of explicit reference cell available too (as in the example I just gave in Python, or using mutable pairs/lists in Racket...in other Schemes, including the Scheme standard, those are the default pairs/lists).
One virtue Haskell does have is some textbooks are appearing for it. (I mean this sincerely, not snarkily.) What books/resources to use is another controversial issue with many wars/closed questions. SICP as others have recommended has many fans and also some critics. There seem to me to be many good choices. I won't venture further into those debates.
At first, read Structure and Implementation of Computer Programs. I recommend Lisp (for, example, it's dialect Scheme) as first functional programming language.
Another option is Clojure, which I'm given to understand is more "purely" functional than Scheme/Racket (don't ask me about the details here) and possibly similar enough to let you use it in conjunction with SICP (Structure and Interpretation of Computer Programs, a highly recommended book also suggested by another answer).
I would like to learn a functional language in order to broaden my horizon. I have knowledge of Python and C/C++ and I want a language to be easy to learn from someone who comes from the imperative domain of languages. I don't care if the language is powerful enough. I just want a language in order to learn the basic of functional programming and then I will try for a more difficult (and powerful language).
Great question!
I had done BASIC, Pascal, assembler, C and C++ before I started doing functional programming in the late 1990s. Then I started using two functional languages at about the same time, Mathematica and OCaml, and was using them exclusively within a few years. In particular, OCaml let me write imperative code which looked like the code I had been writing before. I found that valuable as a learner because it let me compare the different approaches which made the advantages of ML obvious.
However, as others have mentioned, the core benefit of Mathematica and OCaml is pattern matching and that is not technically related to functional programming. I have subsequently looked at many other functional languages but I have no desire to go back to a language that lacks pattern matching.
This question is probably off-topic because it is going to result in endless language wars, but here's a general bit of advice:
There are a class of functional programming languages which are sometimes called "mostly functional", in that they permit some imperative features where you want them. Examples include Standard ML, OCaml, F#, and Scala. You might consider one of these if you want to be able to get a grip on the functional idiomatic style while still being able to achieve things in reasonably familiar ways.
I've used Standard ML extensively in the past, but if you're looking for something that has a bit less of a learning curve, I'd personally recommend Scala, which is my second-favourite programming language. The reasons for this include the prevalence of libraries, a healthy-sized community, and the availability of nice books and tutorials to help you getting started (particularly if you have ever had any dealings with Java).
One element that was not discussed is the availability of special pattern-matching syntax for algebraic datatypes, as in Haskell, all flavors of ML, and probably several of the other languages mentioned. Pattern-matching syntax tends to help the programmer see their functions as mathematical functions. Haskell's syntax is sufficiently complex, and its implementations have sufficiently poor parse error messages, that syntax is a decent reason not to choose Haskell. Scheme is probably easier to learn than most other options (and Scheme probably has the king of all macro systems), but the lack of pattern matching syntax would steer me away from it for an intro to functional programming.
As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance.
Closed 11 years ago.
I am seeking concrete and unique features that Lisp (any dialect) offers to a project, compared to the other primarily functional languages.
For example, Haskell offers lazy-evaluation, purity and a type-system which helps build more correct programs. Erlang makes concurrent programming easier by using message passing exclusively, lightweight processes, and so on.
What does LISP bring to the table? What makes it a better suite than other languages for certain projects? What are its features that the other languages lack to make it suitable?
I am not bashing at Lisp; I want to learn more about it and what advantages it offers if used today. Please be specific :)
When I asked my self questions similar to yours, I searched and found this article:
http://www.defmacro.org/ramblings/lisp.html
It doesn't go too much into details, but gives a coarse picture of why Lisp makes sense. I found it very useful (and the whole http://www.defmacro.org/ site for that matter - like the posts there a lot, e.g. this one).
Haskell offers lazy evaluation
Clojure sequence functions are lazy. You can work with infinite lists just like in haskell:
(take 10 (cycle ["odd" "even"]))
purity
Clojure types are immutable. That makes large parts of your program pure without forcing you to climb the ivory tower :) Plus it has STM, just like haskell.
and a type-system
Unfortunately here lisps cannot compete with haskell. Mosts lisps are dynamic.
But dynamic nature of lisps and their VM (image) makes them an awesome choice for a server side programs, like web applications. It is very easy to connect to a running instance of your web app, and change functions or even entire modules on the fly, without restarting application or kicking out users. That is either not possible or very cumbersome with haskell.
Most lisps provide a very easy way to write macros. You write macros in the same language.
With Haskell you will have to learn yet another language (Template Haskell) which is much more complicated and to this day is not even properly documented. You will have a hard time learning it.
Having said that, i use and love both lisp (clojure) and haskell. I prefer haskell because it has the most powerful type system of any available for practical development language.
Plus it bends your mind better than mushrooms :)
Scheme provides hygenic macros and continuations. I'm not sure what other fp languages also provide these features.
Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 9 years ago.
Improve this question
I would like to learn a functional programming language to see a different programming paradigm.
My background in programming: Java (I have just passed the SCJP exam), some ruby and very limited Rails. I use bash for basic sysadmin tasks. I use Ubuntu 9.04.
As a second goal I would like to use fp to show kids (14-18 years olds) how math and cs interrelated. The guys are very good at programing (they are learning Python and Java at politechnical high school from the first year). However as tests show, they have difficulties with math esp. basic concepts of discrete math. I think we can develop their math skills by using programming (and I possibly that can be the topic of my teacher training thesis). I think a language with very basic vocabulary would serve this project best.
I vote for Haskell, which has the following advantages:
In Haskell, the simple case is actually simple
The complex case is (usually) still comprehensible by ordinary human minds
It has an ordinary syntax that's not too different from other non-functional programming languages (unlike, say, Lisp)
I'm a big fan of Scheme, not least because the best book on it is freely available.
If your primary goal is to work with teens, it makes sense to use the functional-language pedagogy and technology that is proven to work with teens, and that is PLT Scheme (aka DrScheme) with the How To Design Programs book (also free online). These guys have got great results from middle school through 3rd semester university. They have resources for teachers as well.
Many respondents like SICP. It is a wonderful book—but not to
learn from. If you already know Scheme, it is a good book to admire, but SICP is less about functional programming and more about how to implement all known interesting computer-science ideas in Scheme.
If your primary goal is to learn a really new programming paradigm, then Scheme lacks some features that are very important to many functional programmers:
Programming with pattern matching
Partial application of curried functions
A polymorphic static type system
Pure functional computation
If you want exciting ideas, try Haskell; Haskell makes it a lot harder for you to program your old thoughts in the new language. Instead, Haskell forces you to think new thoughts. In addition to many other resources, Real World Haskell is free online.
Final note: SO has had many similar questions on learning functional programming.
Scala and Clojure both run the JVM so you might be more familiar with their environments.
I'd try Scala. It's not purely functional, it allows you to use a variety of approaches--but much of your java knowledge should port (It's JVM based) including the JDK libraries, and it's one of the most advanced languages I've ever seen.
If you're interested in learning language features and expanding your knowledge of how languages work, I couldn't imagine a better alternative.
My vote goes to Scala or F#, which are both freely downloadable at the moment.
The advantage here is that they are mixed paradigm languages -- Natively they are functional languages, but you can also use imperative and Object Oriented programming. They also have large standard libraries -- Scala rides on the back of Java and F# has all of .NET, so you can program something interesting fairly quickly.
Scheme and Haskell are both pure functional languages, but unfortunately their standard libraries are relatively small, so it's hard-ish to do relatively common things, like parsing XML or scanning web pages.
Since you're already familiar with Python, why not just use its functional capabilities? For more, see this (draft) HowTo.
My question is what approach is likely to be best for the teens you're working with. If they're willing to learn something new and different, Scheme is an excellent choice as a functional language. It's as basic as they come. If you want to keep to a more familiar syntax, Haskell might be your answer.
If you are doing this for learning, then definitely Scheme with SICP. It's going to be hard and frustrating and will blow your mind if you don't have experience with this stuff, but you will learn a lot.
If you want to use functional programming in practice then F#, Scala and Clojure are worth looking at.
As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance.
Closed 10 years ago.
I have been researching and playing with functional programming lately, solely to broaden my thinking about programming, because I find thinking "functionally" difficult.
I have downloaded Glasgow Haskell and experimented with that.
What I am wondering is, what is the best platform for Windows to experiment with FP? I would prefer a JVM based approach, but another post on SO has indicated that a real FP language cannot be implemented on the JVM due to a lack of support for tail recursion. What say you?
EDIT: As I've said, I've experimented a fair bit with Haskell; on the advice of one of the answers I've been reviewing the Scala website. Looking over the Scala examples, the code seems more "familiar" (my background is C and Java), but it seems decidedly more OO/procedural and less functional. A huge advantage of Scala would be that it gives me another language tool to use side by side with Java and could become another arrow in my current professional quiver, as opposed to solely being a learning exercise. When I get further into Scala, will the functional aspects become more predominant, or will I tend to end up just writing OO code with some functional influence? In other words, will Haskell challenge my preconceptions harder and faster than Scala?
Check out F#. The CLR has a .tail instruction so you can write F# code with tail calls that don't cause a StackOverflow (the exception, not the web site). Here is an intro video about F# from PDC.
If you really want to learn how to think in a functional way, Haskell is definitely the right choice. Just about every other language out there lets you slip into an imperative style much too easily. Haskell will force you into a functional mindset. I found this indispensible when learning. (You may certainly be more disciplined than I am, of course, but why push your luck?)
When you're satisfied with what you've learned from Haskell (which will be a lot!), you're set to go out and evaluate more liberal functional languages like Clojure or Scala. Or you can stay with Haskell, whose library situation isn't actually all that bad, either. At that point, it's a question of circumstance and personal preference. But in order to make such a choice, having learned how to think in a “pure” functional way first is, I think, vital.
I recommend PLT Scheme and SICP. The language is so simple that you can get on to the important concepts very quickly.
No way is Scala going to bend your mind anywhere near as much as Haskell will. The main reason to choose Scala over Haskell when learning FP is to give yourself a more gentle introduction to the dangerous wilds of monads, functors and higher-order goodness. Scala is great if you're coming from an object-oriented background trying to transition that knowledge into functional-land. It's not so great if you want to just dive head-first into the deep end.
Given what you're asking, I would recommend GHC Haskell. Nothing is going to warp your head quite as much as that. :-) With that said though, I think you should still keep an eye on Scala. There are many aspects of the language which are positively unique, particularly its type system (structural+nominal subtyping == sweet). It's not going to hurt your head quite so much as Haskell, but it will give you an insight into some concepts you may not find anywhere else, particularly the so-called "typeful programming" methodology.
Oh, and to answer the second part of your question (FP vs OO in Scala), I tend to write my code in a functional style within an object-oriented framework. It's a bit difficult to describe, but that's the way it is. Think of it like designing an API from an object-oriented standpoint but implementing everything in a functional style. I keep things immutable and spend a lot of time using higher-order methods, but I do it all within the confines of inheritance and conventional nominal subtyping. Every so often, I'll still write something imperative, but only when it is cleaner to do so than to use the functional style.
Also look at Clojure.
In other words, will Haskell challenge my preconceptions harder and faster than Scala?
Yes.
If you really want to learn, get far outside your comfort zone.
Are you really going to use Scala for production code in the next 3 months, anyway?
Look at Scala. It targets the JVM, interoperates with Java, and has many state of the art functional programming features.
I love using Haskell and GHC. GHC includes an interactive interpreter (GHCI) and has wonderfully helpful error messages. Plus Haskell's one of the best examples of a truly functional language, and not too bad to use once you experiment with it a bit. Plus it has an awesome type system.
ever tried Prolog? ... that'll
?- bend(your_mind).
Yes
?- bend(X).
X = your_mind
It gave me a whole new perspective anyway ...
plenty info out there
As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance.
Closed 10 years ago.
I've caught the bug to learn functional programming for real. So my
next self-study project is to work through the Structure and
Interpretation of Computer Programs. Unfortunately, I've never
learned Lisp, as I was not a CS major in college.
While SICP does not emphasize the tools for programming, doing the
exercises entails picking a Lisp-like language to use. It seems like
some implementation of Scheme would be the path of least
resistance. On the other hand, I hear of others who have used Common
Lisp and Clojure. It seems to me that Common Lisp or Clojure would be
more likely to be used in production code, and therefore slightly
better for my resume. BTW, I fully get the argument that learning a
language is worthwhile for its own sake, but learning a language that
helps my resume is still a benefit. I'm a capitalist and an academic
about my learning.
If you had to self-study SICP, which language would you pick and why?
Ideally, I would like to use a language that can run on the JVM.
I can certainly work with a language where REPL works with bash
and emacs.
ADDITION: have any of you tried reading SICP without using Scheme? If so, what was your experience like?
Use Scheme. It is one of the simplest and easiest languages in existence, and you will spend very little time learning enough of it to understand SICP. Once you understand SICP, you will see how the concepts apply in any language.
Use DrScheme. As others have said, Scheme is a simple language, and DrScheme is a great environment to use it in which has a lot of support and mediocre-to-good documentation.
Not a direct answer but I expect this information to be useful for anyone working through SICP. Be sure to have a look at the videos here:
http://swiss.csail.mit.edu/classes/6.001/abelson-sussman-lectures/
There are 20 episodes of an hour each. They were presented by Abelson and Sussman in 1986 for Hewlett Packard employees. I put them on my iPod and watched them while commuting. Fascinating.
Also, the full text of the book is available online at http://mitpress.mit.edu/sicp/
As someone who hires people, I'll tell you that having Scheme on a resume is a good thing. Having Scheme, SML, Ocaml or Haskell on your resume suggests you are a very well rounded programmer, and quite a thinker.
That said, if you are trying for functional programming, why not Haskell instead? Scheme is multiparadigm, it can be OO, Funcitonal, Streams based, or anything else under the sun. This makes it awesome to try out new programming styles and paradigms, but if your goal is strictly functional, it can be a problem. (You will end up writing non functional code and not realizing it.)
I agree that you should just use Scheme. However, if you really have the itch to use Common Lisp or Clojure, I'd pick the latter. Scheme and Clojure are both Lisp-1s, so the code in the book will be more congruent between the two (except for tail calls, but if you understand how to compensate you'll be fine). Common Lisp is a Lisp-2 and will probably obscure the beauty of what SICP is trying to teach you.
The code in the book is Scheme so you'll have to read it anyways - you might as well write it. You might even like it!
To get real value out of the book you'll have to use Scheme. Which implementation of scheme depends on your current environment:
Windows - Dr Scheme (PLT Scheme) - http://download.plt-scheme.org/
Linux - If this is a remote account - you may consider MZScheme (PLTScheme) (http://download.plt-scheme.org/) otherwise you'll want to use Dr Scheme if this is a local instance of Linux.
I think Clojure fits what you want to do just perfectly. It's much more functional than Scheme because the data structures are immutable and it can be very useful as it runs on the JVM. But, be aware that you'll end up learning Scheme anyway to be able to understand the code in the book.
I've caught the bug to learn functional programming for real.
From what I've heard, SICP is about a lot more than just functional programming.
Caveat: I have not read the whole book
Since the examples rely on closures and continuations, you would be better served by using a language with both of those features, otherwise you would need to implement them yourself.
For example, writing a metacircular evaluator in Scheme leverages the fact that Scheme provides closures and continuations.
I used lua when I had a look at sicp
works out pretty well
Use anything but scheme.
While using something else then scheme, you will be encouraged to think more, and avoid temptation to just retype the examples. It is a good thing.
Of course, it has to be similar enough, in lisp-1 sense, so clojure and arc are good to go.
I have used scheme for my self-study. The best way to learn from SICP is to do all the exercises relegiously.
I have used Gnu guile for scheme.
While you could use something other than Scheme, you'd be needlessly adding extra work and possibly cutting yourself off from fully understanding what the book is about. SICP was an introductory programming book. It is a stepping stone to deeper topics in computer science. Getting bogged down in 'translating' from Scheme to CL or Clojure would probably obscure the finer points. That would be a shame, because SICP is truly a gateway to understanding what programming is really about.
Learning Scheme is really straight forward (especially compared to both CL and Clojure) and, in fact, the introductory course as well as the book, assumes the student doesn't know it already. CL and Clojure carry considerable baggage relative to the task at hand.
I hear of others who have used Common Lisp and Clojure.
You should use whatever language most motivates you, but 99% of folks working through SICP are going to use Scheme.
I worked through (most) of it earlier this year, and used Common Lisp, simply because I didn't have Scheme available (don't ask).
As has already been noted, Scheme is a Lisp-1 language whereas Common Lisp is a Lisp-2. There are enough differences between the languages to mean that you have think carefully about translating the code in the book, so it forced me to really get to grips with the material.
but learning a language that helps my resume is still a benefit.
You should try using VB6 or COBOL, then, as there is a lot of billing work out there for it.
I think Scheme would be the natural choice (since it is the "native" language of SICP)
However, since the true value of SICP comes from the concepts rather than the mechanics of the particular language, I think it would be a valuable learning exercise to attempt it in any Lisp-like language. I've personally tried some of the exercises in Clojure and they all translate pretty well.
For those interested there is an ongoing project to create a Clojure translation of SICP.