Take the 2-minute tour ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free, no registration required.

What would be a good first functional programming project?

I am looking to finish with a bang on my bachelor project and I want to finish it with a functional programming project. We didn't study it in school but we are encouraged to try to learn new things ourselves, and I thought learning a new paradigm not only a new language would be a great exercise for me, and probably something interesting for the teachers to see too.

The problem is I want to start a bit ahead of time on my project to take advantage of the summer holiday and get a better understanding on functional programming, and get familiar with one language.

What would you say would be a good practice project that is a bit challenging, but also lets me learn the language, paradigm etc. And then what would you think would be a good project (a more advanced one) for my bachelor project?

Suggestions for the best language to start with when going into functional programming would be appreciated too.

share|improve this question

closed as off topic by Anna Lear Sep 23 '11 at 15:33

Questions on Programmers Stack Exchange are expected to relate to software development within the scope defined by the community. Consider editing the question or leaving comments for improvement if you believe the question can be reworded to fit within the scope. Read more about reopening questions here.If this question can be reworded to fit the rules in the help center, please edit the question.

    
"What language should I choose" and project selection questions are both off-topic here. Please see the FAQ and this meta discussion for further details. –  Anna Lear Sep 23 '11 at 15:33
add comment

7 Answers

up vote 9 down vote accepted

It's generally easier if you go for something relatively mathematical or logical - functional programming languages are generally well suited for applications that represent some form of transformation from a given input to an output.

Some ideas, in rough order of difficulty:

  • Genetic algorithms - write a program that evolves solutions to a particular task where the solutions are represented in a simple DSL. I've had fun before building little bots that hunt for food in a 2D grid and evolve different kinds of strategies

  • Parsing combinators - build a parser combinator library that enables you to construct a parser for an arbitrary language using higher order functions.

  • If you really want a challenge, you can try writing a computer game... be aware that this is a tricky task since games have a huge amount of mutable state which can be tricky to manage in a functional programming style. Expect to learn more than you ever wanted to know about monads etc.....

I'd recommend Clojure as a pragmatic functional language. I've been using it for about 18 months now and I'm extremely happy with the choice. Main reasons are:

  • Concurrency - Clojure has an amazing STM system that in my view makes it the best language in the world at the moment for multi-core concurrency. See the video at: http://www.infoq.com/presentations/Value-Identity-State-Rich-Hickey if you want to understand why this is so special
  • It's a Lisp - so because of the "code is data" philosophy it is fantastic for macro-based metaprogramming (programs that write programs, genetic algorithms etc.)
  • Pragmatic functional programming - Clojure style is very functional (lots of emphasis on higher order functions, lazy sequences etc.) but it isn't totally pure like Haskell. There are lots of nice tools to handle mtable state and side efects
  • Dynamic - Clojure is a dynamic language by default. I find this a big boost for productivity. However, you can optionally add static type hints later if you want the performance benefits of static typing.
  • Fully compiled - Clojure code is always complied (even if you do an "eval") so you get pretty decent performance - certainly better than most dynamic languages I've used.
  • You get access to all the libraries and tools in the JVM ecosystem for free. So unlike academic languages that have very limited libraries available, you can access anything in the Java universe pretty easily

You can try out the basics very easily with:

  • The 4Clojure online problem set - the early problems serve as a good "learning by doing" introduction to the Clojure language
  • the online Clojure REPL at http://www.try-clojure.org/
share|improve this answer
    
I chose your answer for the question because it answered all my questions. Thank you very much for taking the time. –  Meme May 27 '11 at 15:10
    
Haskell has STM too ;( –  alternative May 27 '11 at 21:01
    
@mikera: For working with the JVM, have you tried ABCL? I tried it out and made only a small example but I have almost no experience with it. (I also have a Clojure book in my todo list, but this is another story, I am curious if you have any experience working with ABCL and Java). –  Giorgio May 11 '13 at 23:03
    
@Giorgio: ABCL seems like it's a decent implementation of Common Lisp on the JVM. OTOH Clojure has the advantages of being designed for the JVM, incorporating a lot more "modern" innovations, and having more community momentum. I think it really comes down to whether you care about maintaining Common Lisp backwards compatibility or not. –  mikera May 12 '13 at 1:56
add comment

You could also contribute to some open source project.

For example, in the Frege programming language project, there is much work to do. For instance, you could care about porting base Haskell libraries. This would make you sort of a Haskell expert while you work on it.

share|improve this answer
add comment

For a head-start, you could try to implement a little blackjack game in F#. This is a homework project assigned during this short video tutorial. Solution is also provided on the net (and in one of the videos).

share|improve this answer
add comment

Which functional language were you thinking of. Each one has different characteristics. The one language that made the largest impact on me was Haskell and I would suggest you do the same.

share|improve this answer
    
I was thinking of F# honestly mainly because in Denmark Microsoft everything is popular, but the more I read different opinions, I am doubting this decision. I want a language that will help me learn the paradigm mainly, and after I am sure it's not hard to learn another one if I need or want to. –  Meme May 27 '11 at 11:47
    
Strongly depends on where you are and what you do. For us Microsoft programming technologies are useless as they don't support our main platform. But I digress: if you want to use F#, great, but then open a new F# specific question. –  user1249 May 28 '11 at 6:32
    
I don't want to use that. I haven't taken a decision yet. The question about the language to use was a secondary one anyway. –  Meme May 28 '11 at 8:55
    
In that case, find a project and then ask for recommendations how to solve it. E.g. Prolog is great for decision tree searching. Haskell is great for pattern matching. Lisp is great for constructing and manipulating Lisp programs at runtime depending on your data. –  user1249 May 28 '11 at 9:04
add comment

You could write an interpreter for scheme or lisp with OCaml.

share|improve this answer
    
Also to note theres even a haskell book on this about writing scheme in haskell. –  alternative May 27 '11 at 10:57
add comment

Quantitative analysis

If you find finance somewhat interesting doing some quant stuff with functional programming is a good match since it's very algorithmic. I'm talking portfolio theory and things like sharpe and sortino ratios etc. Make an app that analyses a fund's returns and gives different statistics, diagrams etc.

I'd recommend F# only because I think it's an easy functional language to get started in, has good tools and good framework backing it. Other alternatives are lisp and clojure but they're a bit harder to learn.

share|improve this answer
    
At high level, it is indeed true that you can do a lot of stuff in a functional manner. People have used functional languages to describe exotic option payoffs, for example. But as you go down to the ground level stuff, like calculating PCA, solving nonlinear equations, etc., the algorithms become increasingly iterative and you're better off coding them in the old-style way. –  quant_dev May 27 '11 at 11:40
1  
I wouldn't say that, in my experience quantiative analysis is all about running algorithms over series. I've implemented quant stuff in C# and it was very much aligned with LINQ, at least for the portfolio theory kind of stuff –  konrad May 27 '11 at 12:19
    
What about the implementations of algorithms themselves? –  quant_dev May 27 '11 at 12:29
    
I see no problem in most instances, do you? Take calculating a sharpe ratio, first you calculate an annualized return from a returns series, then you use that value with a risk free rate and volatility: (annualizedReturn - riskFreeRate) / volatility. Nothing a functional language couldn't handle –  konrad May 27 '11 at 12:59
    
What about pricing model calibration? –  quant_dev May 27 '11 at 14:04
show 2 more comments

Before you start thinking about specific projects, start with learning the basics of functional programming so you can have a good idea of the types of projects that would be a good fit.

The best place to get started is probably The Structure and Interpretation of Computer Programs (SICP), which is based on the Scheme dialect of Lisp. This is a classic CS text, and the full text is available online (link provided).

If you want to get fancy, and use a more modern functional language that targets the JVM, take a look at Clojure. There's even an adapted version of SICP specifically for Clojure.

Going over the SICP text, you'll get an idea of why functional programming is so well-suited to certain types of tasks, and the exercises might inspire a full-fledged project. If you choose to go the Clojure route, and want to examine some existing projects, there are some good links here.

share|improve this answer
    
+1 for mentioning SICP –  Andy Lowry May 27 '11 at 9:39
    
Thank you for providing the link for the book. I am going to read that to get a better understanding. –  Meme May 27 '11 at 10:04
    
Have you read your SICP today? –  MattyD May 27 '11 at 13:10
add comment

Not the answer you're looking for? Browse other questions tagged or ask your own question.