An Overview of Functional Programming


 

Obscure syntax, missing looping constructs, unknown programming patterns, the lack of libraries or documentation, there are a lot of reasons discouraging imperative programmers to start learning and using functional programming languages.

Microsoft released in 2002 F#, a multi-paradigm programming language, targeting the .NET Framework, that encompasses functional programming as well as imperative and object-oriented programming disciplines to help address these issues.

F# is first class .NET language, it has a complete access to the .NET Framework, can consume and generate classes, can be either interpreted or compiled to .NET assemblies, and it is well integrated to the Visual Studio Microsoft IDE.

Through a series of articles I would like to introduce some of the powerful F# features and features common to functional languages:

  1. Recursion -  Where are my for/while loops?
    Discussion about recursion and why loops are rarely used in functional programming.
  2. List – Cons, Car, Cdr & Co
    Showing the importance and the power of list processing in functional languages.
  3. Pattern Matching – Be Explicit
    A great feature to write clear and concise code.
  4. 1st Class Functions – Power is in simplicity
    What does it mean to have first class functions, partial application, how to build abstraction with functions.
  5. Generic Parameters – Static typing without typing
    Presentation of generic parameters which will help you to make generalist and reusable algorithms.
  6. Sequences – Being lazy is allowed
    Usage of laziness to create on demand computations, and infinite streams of data.
  7. Workflows – A Monad alias
    Introduction to the concept of monads, how they can be built in F# and what the power they provide. 
  8. Quotations – Say “your name”
    An overview of meta-programming in F#.
  9. Continuations – Future is yours
    Continuations allow non lexical escapes, it is then possible to get coroutines , exception handling, recursion optimizations and more.
  10. Macros – Do you like parenthesis?
    This article will presents IronScheme, a Scheme implementation for the .NET, in order to speak about macros in functional programming

Learning functional programming when coming from the imperative world is not something easy, it takes time, but I encourage all of you to try it, since this mind shift will not only help you become better programmers by mastering new concepts, but it will also bring you a lot of fun!


Comments (8)

  1. That's a great article as functional programming (preferably F#), is on my list of things to learn after C# and Python/Iron Python.  

  2. One of the very next things I've to learn this year.

    Could you suggest us where we can find more reources?

  3. Hello,

    @cron22:

    Great, I hope you will enjoy this serie of articles then!

    @Luigi Bruno:

    I think the best book to start learning functional programming is: Structure and Interpretation of Computer Programs (http://mitpress.mit.edu/sicp/), however all examples in the book are in Scheme a LISP dialect.

    An other great and funny book is Learn You Haskell for a Great Good (http://learnyouahaskell.com/) about learning Haskell which shares many concepts with F#

    And finally an Apress book entirely focusing on F# written by several people including the F# author Don Syme, entitled Experts F#. (since this book was written the F# library evolved and some code example are not valid anymore)

    Thanks

  4. Thank you for the resources.  And speaking of Lisp, isn't there a dialect for .net called Iron Scheme?  

  5. @cron22:

    Yes, there is IronScheme, I have been watching this project for more than one year, I developed several personal projects with it, it is a nice implementation of scheme. Some .NET integration features are still lacking (you can consum but can't create .NET compatible classes, and you cannot use .NET generics), however leppie, (IronScheme author alias) is taking any feedbacks and is really reactive when it is about improving his project. I will introduce Ironscheme in my article about macros.

  6. That would be great.  You really should.  It seems that out of all the iron you guys have forged (no pun intended),

  7. BradNelson says:

    Thank you.  One of the most well written and easy to understand introductions to Functional Programming that I have come across; great job!

  8. I agree very much with that statement.