Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
I like to study languages outside my comfort zone, but I've had a hard time finding a place to start for functional languages. I heard a lot of good things about Structure and Interpretations of Computer Programs, but when I tried to read through it a couple of years ago it just seemed to whiz over my head. I do way better with books than web sites, but when I visit the local book store the books on LISP look kind of scary.
So what's a good starting point? My goal is to be able to use a functional programming language to solve simple problems in 6 months or so, and the ability to move to more advanced topics, recognize when a functional language is the right tool for the job, and use the language to solve more problems over the course of 2-3 years. I like books that are heavy on examples but also include challenges to work through. Does such a thing exist for functional languages?
The Little Schemer teaches recursion really well, and it's fun and simple to read.
I also liked The Scheme Programming Language for a broader introduction into the language.
Try Real World Haskell. It's free online.
SICP is a great book.
This is probably my bias, but I thought ocaml was pretty easy to get into. You have the option of programming in a few different styles until you're completely comfortable. I posted a bunch of links to Haskell and Ocaml references that are books, with examples et cetera that seem right up your alley.
If you prefer Lisp, you can try to power through the 99-problems in Lisp(which you can do in any language, really), or you can watch the lectures from the people who wrote SICP.
Further down the road, get a hold of "Purely Functional Data Structures", as it'll get into the hard-core deep design and considerations you have to take into account in functional languages --it uses ML (which ocaml derived from).
I really recommend "On Lisp" from Paul Graham.
It is concise and very readable even for beginners in functional programming (as I was when I read it). It contains a lot of very short examples, each which helps to understand one single thing.
I often thought reading this book: this is just the language containing exactly the features I ever wanted in other (nonfunctional) languages, but never got. :-(
And this is exactly the book to learn it, always comprehensible, sometimes even funny!
You may get it for free at the author's site!
I really like Thompson’s “Haskell: The Craft of Functional Programming” because it’s well written and Haskell allows an easier start than other functional languages while being completely pure (unlike Lisp or Scheme).
Since there are a bunch of different functional programming languages, it's hard to recommend books. But if you're interested in Common Lisp, recently I've been reading "Practical Common Lisp" by Peter Seibel, which you can check out online for free before dropping your hard earned cash on it. It's a pretty gentle introduction to CL, with great explanations and tons of examples. Seibel's a great writer (example: read the story of Mac,) he's good at keeping you engaged, which is really where SICP falls down, I think. It's just so dry! But while Practical Common Lisp is pretty example-heavy, it doesn't really have challenges to work through, although the examples are mostly designed to let you continue to work and build on them.
Another good book, this one Scheme-oriented: How to Design Programs. (Online)
I haven't had as much time with this book, being more of a Lisper than a Schemer myself, but it's well written, has good explanations and examples, and has lots of exercises to work on. It seems pretty popular in the Scheme crowd.
The Schemers Guide and related software - seriously good stuff
http://www.schemers.com/tsg.html
Check out Introduction to functional programming. It offers a different perspective.
I found The Little Schemer a great, great introduction to functional programming. It's entirely based on simple, bite sized examples which are built up upon as the book goes on.
I learned from Jeffrey Ullman's Elements of ML Programming, which is pretty good. It loses points for being about Standard ML, when OCaml, F#, and Haskell are (seemingly) more popular.
I feel Purely Functional Data Structures by Chris Okasaki is worth a look.
FYI http://www.cs.cmu.edu/~rwh/theses/okasaki.pdf
Haskell is a very good functional programming language for beginners. Someone had asked about good resources for Haskell, so I will point you there.
If you are looking for a good book on Functional Programming, I would recommend "Functional Programming: Practice and Theory" by Bruce J. Maclennan.
It is however required that you brush up on your Set Theory and Logic before giving it a read. It includes examples in LISP, Haskell and other languages.
If you have experience with .NET, Expert #F is good.
F# is derived from OCaml. Lisp is more pure as functional languages go.
Real-World Functional Programming (with examples in F# and C#)
I have heard good things about Haskell Functional Programming, but I also found this list of functional programming books at amazon that might be helpful to you.
Related
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 6 years ago.
Improve this question
I am a lifelong object-oriented programmer. My job is primarily java development, but I have experience in a number of languages. Ruby gave me my first real taste of functional programming. I loved the features Ruby borrowed from the functional paradigm such as closures and continuations. Eventually, I graduated to Scala. This has been a great way to gradually learn to approach non-trivial problems in a functional manner.
Now I am interested in Clojure. I know all the sexy features that make it enticing (software transactional memory, macros, etc.), but I just can't get used to "thinking in lisp". I've seen Rich Hickey's screencasts aimed at java programmers, but they are geared towards explaining language features and not approaching real world problems.
I am looking for any advice or resources which have made this transition easier for others.
Its now 11 months after I originally asked this question. I've just started a new project to help beginners make the transition to clojure. Its called 4clojure, and it challenges you to solve fill-in-the-blank style interactive problems.
4Clojure.com
My first introduction to Lisp was: Paradigms of Artificial Intelligence Programming of Peter Norvig. It is a very readable and gentle introduction to many features of Common Lisp and functional programming concepts.
Starting directly with some Clojure books could be preferable for you, because there are several differences between Common Lisp and Clojure which may become confusing if you're trying to learn both at the same time.
At the same time, try to get hands on experience messing with the Clojure REPL, doing some exercises like Project Euler which you then can contrast with other Clojure and imperative Java solutions.
Furthermore, if you have any questions on Clojure programming and idiomatic style, do not hesitate to discuss your code with other Clojurians. There are several options to do this, such as: Clojure on Google Groups, the #clojure IRC channel on Freenode, Twitter via hashtag #clojure, and of course here on Stackoverflow!
Going right to Clojure from OOP, I'd only recommend the excellent Programming Clojure by Stuart Halloway.
I love it, and it does a great job of covering a lot of Clojure and a fair bit of funcational programming in the process.
The Little Schemer and SICP are great, but they're not so relevant for Clojure, if that is what you want to learn.
I'd recommend getting the MEAP version of The Joy of Clojure. I have it, and right now the MEAP offers a total of 12 chapters. So far, it's by far the best book I've ever read on a programming language. Those 12 chapter are plenty to get you started with Clojure, all the way up to some advanced topics. The current MEAP (which gets updates with new chapters quite frequently) combined with the ociweb Clojure tutorial, stackoverflow.com, and the #clojure IRC channel on freenode, I think you'll be fine.
While I agree that Programming Clojure is a great introduction to Clojure, and does a very good job, we can't deny the fact that it gets more and more outdated every week. You have to keep in mind that Programming Clojure was written for Clojure 1.0. Right now, we are fast approaching the release of Clojure 1.2. For example, with the inclusion of defrecord, structs are going to be obsolete.
I really like Brian Twill's series of Clojure videos on youtube as a painless introduction to some of clojure's ideas. They don't assume any great knowledge of Lisp or functional programming languages.
As far as books go, I agree with Isaac that Programming Clojure is an excellent resource. You might also consider some forthcoming books on clojure:
The Joy of Clojure
Clojure in Action
Both have early access available online if you buy now. Also I think both have discounts available -- try looking on clojure.org.
The Lisp books that Peter and Norman mention are probably good choices (I like SICP, but haven't read the others). But the differences in syntax with Clojure might get a bit frustrating if you're just starting out. For that reason I recommend starting with Clojure-specific books at the beginning.
(Edited to fix link.)
For a raw beginner, How to Design Programs will get you thinking like a Lisper. If you get impatient, go faster :-) Another good book is On Lisp by Paul Graham, which as a bonus is now free online.
I don't care for Structure and Interpretation of Computer Programs; if you know Lisp or Scheme, already, it's a great intellectual tour de force and very satisfying—but my students and I have not found it a good book to learn from. The Little Schemer has lots of good information if you can stomach its dialectical organization and cutesie-pie style. I can't.
All the answers so far are great. I would add:
Purely Functional Retrogames is an excellent series on how to design old school video games in a functional, side effect free manner. If you go through this and grasp how to write Pac-Man without side effects, then you will have gone a long way to inducing the mindset necessary to solve many/most other problems functionally.
Halloway's Programming Clojure is the best general introduction to Clojure, and gives some idea of how to think about problems in a functional rather than object-oriented way, particularly the snake game example.
Seibel's Practical Common Lisp is an excellent practical guide to solving real-world problems functionally, such as building a database. Though written for CL rather than Clojure, which allows mutable data, the concepts carry over without much modification, and the full text is available online for free from the author's website. Worth at least a glance.
If you're looking for an introduction to "Lispy thinking", I'd recommend Practical Common Lisp . It's a good read and IMHO perfect for seasoned programmers coming from a non-lisp background.
The downside is that it targets Common Lisp, not Clojure; the main reason being that Clojure is much more functional in its approach. You'll probably want a Clojure specific book too.
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 6 years ago.
Improve this question
I'm learning functional programming with Clojure. What practical exercises can you recommend? Online repositories with solutions would be perfect.
One idea I can think of is going through all the popular algorithms on sorting, trees, graphs etc. and implementing them in Clojure myself. While it could work, it may be pretty steep and I'm likely to do it inefficiently (compared to someone who knows what she's doing).
4clojure was launched recently. It takes a lot of inspiration from Functional Koans, and several of the puzzles from 99 Lisp Problems; but it improves on both by providing a learning experience for which you need only your browser.
Problems vary in difficulty from language tutorials like What is the second element of this list? to thought-provoking questions like Is it possible to arrange these N words so that each differs from the preceding one by at most one character, and more problems are being added every day.
I would recommend doing the Project Euler exercises:
http://projecteuler.net/
Project Euler is a series of
challenging mathematical/computer
programming problems that will require
more than just mathematical insights
to solve. Although mathematics will
help you arrive at elegant and
efficient methods, the use of a
computer and programming skills will
be required to solve most problems.
Because many programmers are solving Project Euler exercises, you can compare the solutions to other (non-functional) programming languages, but also Clojure solutions are available: http://clojure-euler.wikispaces.com/, so you can contrast imperative vs. functional/idiomatic Clojure.
Of course you will learn the most by first doing the exercises yourself, without consulting any of the solutions.
Try 99 Lisp Problems. The solutions aren't in clojure, but it should be easy to translate.
I recently started learning Clojure myself, and found labrepl useful.
It lets you get familiar with the basics and the REPL, contains a number of exercises and describes quite a bit of non-obvious stuff that is hard to find in the documentation since you don't yet know what you are looking for.
Recommended.
Edit
Also the Python Challenge, a series of puzzles that can be solved by a few lines of programming; the solution to a puzzle gives you the URL to visit for the next puzzle.
Although not specifically Clojure, the puzzles are quite entertaining and a good way to get your feet wet with any new language IMHO. (There are a couple of puzzles that are specific to Python, but the majority are not. See the forum for Python Challenge Hints when stuck.)
The Python Challenge differs from the Euler tasks in being more practical and less math oriented; tasks include things like filtering the bytes of an image and following hyperlinks programmatically.
There are some Functional Koans for Clojure: https://github.com/functional-koans/clojure-koans
I have not gotten round to trying these, but have heard good reviews.
As a once-upon-a-time LISP programmer, I found Clojure Koans https://github.com/functional-koans/clojure-koans extremely efficient and methodically sound.
Use a three window arrangement (editor + evaluator + repl) for instant feedback, documentation reference and on the fly experimenting.
The topics of the "tutorial" are well organized and gradually introduce more complex material. Certainly a good starting point if you have at least some LISP experience.
I would recommended studying the code in clojure.contrib on github.
As an exercise for learning FP I would recommend just writing the apps you're currently working on in Clojure, but try not to use any Refs or loops. Be dedicated to solving your problems functionally using recursion. If you think you have to use a Ref or a loop make sure you can explain why that is.
http://exercism.io/ has several not-so-trivial exercises, they give you a test and a description, you submit a solution and you refactor by looking at other people's code I highly recommend it, plus it's polyglot you can do the exercises in any programming language they support.
As others have mentioned Project Euler is a great place to start. But pick a good book that will teach you the fundamentals and the rationale for clojure's implementation, Programming Clojure by Stuart Halloway comes to mind.
Once you're done with that Timothy Baldridge offers several video tutorials where he dissects core.async, transducers, logic programming and lots of other fun stuff to play around with at: https://tbaldridge.pivotshare.com/
I strongly recommend Hackerrank, it has functional programming domain: https://www.hackerrank.com/domains/fp/intro
You may check your skills not only with clojure, but haskell, scala, erlang and many more
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.
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 2 years ago.
Improve this question
With all the hype around functional programming, which are the best resources to getting started in functional programming [for a C# programmer]? I am not looking for C# 3.0 language improvements.
Shameless plug: I'm the co-author (well, glorified editor really :) of Real World Functional Programming. It's squarely aimed at people such as yourself. It teaches the principles of functional programming, mostly via F#, and also shows how you can apply the same principles in many cases in C#.
It assumes you know C# already, but introduces F# from scratch. It gives you enough knowledge of F# to get you started so you can experiment, but the aim is to teach a functional way of thinking rather than going into every nook and cranny of F# as a language. (In other words, if you want to start using F# as a production language, I'd get another book as well.)
It's not out yet, but you can get early access via the MEAP programme. Several chapters are available already, with more coming soon.
I think for a C# developer with .NET background, the best way to enter functional programming is to learn F#.
Pick a functional language. Python has many functional features. Haskell is purely functional.
Go to Project Euler.
Solve some problems.
If you look at the Project Euler stats, Python and Haskell are very highly ranked.
Edit
Functional Programming in Python:
http://www.ibm.com/developerworks/library/l-prog.html
http://www.amk.ca/python/writing/functional
http://linuxgazette.net/109/pramode.html
http://www.slideshare.net/adambyrtek/functional-programming-with-python-516744
http://scott.andstuff.org/FunctionalPython
http://docs.python.org/tutorial/datastructures.html#functional-programming-tools
http://www.freenetpages.co.uk/hp/alan.gauld/tutfctnl.htm
The free online version of Real World Haskell is a good, cheap way to get started.
Once you've done a few chapters, you'll be in a position to decide whether FP is for you, and whether you want to continue with Haskell or move on to some other language. You may even go on to buy the dead tree version (as I did).
The paradigms you learn from this book, especially the opening chapters, apply equally well to other functional languages. (I like to think my Javascript and Groovy benefited from my studying Haskell).
Spend some time looking at Lisp or Scheme as they're the mother and father of functional programming. PLT Scheme is a great environment to play with Scheme. Get yourself a copy of The Little Schemer as it's a good introduction to Scheme and will help you get up to speed fairly quickly.
Once you've got your head around functional try doing some of the Project Euler problems in a functional way.
I learned functional programming in college, using language Haskell.
In its homepage you most likely find what you need to get started :)
BTW, it takes a lot of practice to see the solution; algorithms, as such, are not what everybody's used to code in Object-Oriented, logic or procedural languages.
I agree with Mehrdad Afshari. If you are familiar with C# start functional programming with F#. The syntax is similar to lambda expressions in C#.
I've been liking learn you a haskell so far, it's pretty good for beginners.
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.