How can I get started with functional programming? [closed] - functional-programming

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.

Related

Which English tutorial would you advise to learn OCaml? [closed]

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 want to advertise OCaml to beginners, and I am looking for good tutorials in English; not that you have only heard of, but that you have actually tried and found useful...
I quite like the book Developing Applications With Objective Caml -- I guess the title should be updated to mirror the 'OCaml' naming decision. It is old and therefore slightly out-of-date, but on only minor aspects -- eg., it presents the stream syntax as belonging to the core language, but it is now outsourced as a Camlp4 extension. The book is surprisingly complete, and there is a lot of meat already in the chapters 2, 3 and 4.
This books covers a bit of system programming, but if it's what the reader is interested in, I would rather recommend the separate book Unix system programming in OCaml -- also translated into english by a community effort.
Finally, if one want to discover the theoretical underpinnings of OCaml, If found the U3 book, Using, Understanding, and Unraveling the OCaml Language to be a great resource. But it's only for readers that already know about OCaml.
PS: I have a very good opinion on Jason Hickey's introduction to Objective Caml as well, but I can't say I have read it in full, only glanced at it. That's the problem with "beginners" books, you can really read at most one good one.
For me, the primary one is:
$ apt-cache show ocaml-book-en
Package: ocaml-book-en
Source: ocaml-book
Version: 1.0-5
Installed-Size: 7061
Maintainer: Debian QA Group <packages#qa.debian.org>
Architecture: all
Recommends: www-browser | pdf-viewer
Description-en: English book: "Developing applications with Objective Caml"
This is the English translation of the O'Reilly's OCaml French
book "Developpement d'applications avec Objective Caml" that can
be found in the ocaml-book-fr package.
.
This package contains both the HTML and PDF version of the book.
:)
There is also great book for system programming in OCaml and cookbook-style resource here.
The tutorial I used when learning and the one I always recommend to beginners - ocaml-tutorial.org (mirrored at ocamlcore as original site went down).
Here is a book that is intended for newcomers to programming and also those who know some programming but want to learn programming in the function-oriented paradigm, or those who simply want to learn OCaml.
An OCaml port of the book How to Think Like a Computer Scientist has been created by Nicolas Monje.
According to the website, the PDF version of the book should be downloaded
From the book:
The goal of this book is to teach you to think like a computer scientist. This way of thinking combines some of the best features of mathematics, engineering, and natural science. Like mathematicians, computer scientists use formal languages to denote ideas (specifically computations). Like engineers, they design things, assembling components into systems and evaluating tradeoffs among alternatives. Like scientists, they observe the behavior of complex systems, form hypotheses, and test predictions.
The single most important skill for a computer scientist is problem solving. Problem solving means the ability to formulate problems, think creatively about solutions, and express a solution clearly and accurately. As it turns out, the process of learning to program is an excellent opportunity to practice problem-solving skills. That’s why this chapter is called, “The way of the program.”
On one level, you will be learning to program, a useful skill by itself. On another level, you will use programming as a means to an end. As we go along, that end will become clearer.
I've just started with Ocaml, and these are tutorials that I find most helpful:
Documentation and user’s manual - most useful and official
Introduction to Caml - this one i used in my first days (recently) and it was really helpful because of it's simplicity
I thought Jason Hickey's Introduction to Objective Caml was very good (the only actual text on the language I've read, and how I started). INRIA's documentation is nice as well; and reading module signatures by themselves is quite instructive once you get the hang of it ;)
Believe it or not, OCaml was the first language I (really) learned.
There is a new book "Real World OCaml" of Jason Hickey is going to be published soon. On the web-site there is a public beta available for free. Despite the fact the book is not finished yet, I didn't notice any major mistakes or irrelevancies.
It gave me a full-fledged understanding of OCaml. It contains lots of examples illustrating concepts and could be easily considered as a tutorial. I also liked that it partly covers standart modules (List, ListLabels, Map, Sys, String, may be some others).
"The Runtime System" section in this book is very useful. It provides details about compiler implementation, memory management, linkage with foreign code, language cost intuition. The latter I consider very important, because many functional programming books cover concepts without saying how expensive they are in terms of memory and time. Highly recommend this book, especially when there is a free online version.

Clojure for a lisp illiterate [closed]

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.

Learning functional/Clojure programming - practical exercises? [closed]

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

Which functional programming language should I choose as first functional programming language? [closed]

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.

What's a good beginning text on functional programming? [closed]

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.

Resources