Path to Become a Better F# Programmer

I would like to hear from you folks that have achieved a high-level of proficiency in F# (and also in functional programming in general too) what should be my steps from now on to become a better/professional F# programmer?

I already know much of the F# syntax and have some years of experience with C++. My goal is, as an engineer and mathematician, to design better scientific libraries (linear algebra packages, partial differential solvers, etc.).


what should be my steps from now on to become a better/professional F# programmer?

Keep coding everyday :)

I jumped on the F# train in Sept '07, before that I had a boatload of C# experience. It took about 3 months or so for me to stop writing code as C# with a little funnier syntax and start picking up on the right coding style :)

Tips and things that helped me:

  • I found that F# makes it really hard to write non-idiomatic code, really easy to write good, clean code. If you find yourself fighting the compiler, 9 times out of 10 your doing something wrong. Go back to the drawing board and try again.

  • The entire concept of immutability was a mystery at first, but implementing all of the data structures from Okasaki's Purely Functional Data Structures was hugely helpful.

  • During some slow days at work, between '08 and '09, I wrote a wikibook. I haven't looked at it in a while, but I'm sure its really bad --- but, the experience of explaining the language to others was a good jumpstart for someone like me who normally wouldn't have enough motivation to start a pet project in F# :)

  • Map, Fold, and Filter are your friends. Try to express algorithms in these functions rather than implementing a loop with recursion.

  • Non-tail recursive functions are almost always easier to read and write. See here.

  • Project Euler. Lots of people recommend it, I didn't find it particularly helpful at all. You might get more use from it than me if your a mathematician, however.

  • <3 unions! Use them!

  • Falling back on mutable state -- big no-no. At least for beginners. The worst beginner code is full of mutables and ref variables. Immutability is an alien concept at first, so I recommend writing fully stateless programs for a while.

  • Still, the best advice is just keep coding everyday.

    Hope that helps!

    -- Juliet


    Like any other language now that you know the syntax and the basics it's time to write code and more code.

  • Make sure you have the core concepts of functional programming down.
  • Work on a large project so you also get familiar with the large and not just the small.
  • Write a few immutable data structures.
  • Work on a large project without using inheritance.
  • If your familiar with design patterns implement some of them in a purely functional way and notice how some of them disappear.
  • F# is about mixing functional and OOP styles. Once you've done a fare amount of abstraction without inheritance bring it back and start mixing the styles together. Find a balance.
  • Since your goal as an engineer and mathematician is to design better scientific libraries may I suggest as a learning exercise working on a video game style simulation. Something that involves physics and math but also requires control of state.


    I can only agree that trying to explain functional programming to others is a great way to learn it. I spent a lot of time about thinking the structure of my F# book and I think it really helped me to understand how functional concepts relate. Even giving a talk on F# in your company or to your friends should have a similar effect.

    When I started learning F#, I started working on the F# WebTools project. I think this was quite useful, because many components of the project were perfect for functional programming, so I learned many functional tricks (because they were the best way to solve the problem). The project processed source code tree of F# and translated it to JavaScript, so I was using a lots of recursive functions and discriminated unions.

    The area you're working in is quite different than my, so I cannot give you any specific advice, but it is a good idea to write programs in a clear functional way - even if you think that it would look nicer if you wrote it in the C++ style. When you write it, you'll probably find some way to simplify your code.

    So, I think that the tips I could give are:

  • Try to explain F# to others - this helps you to organize ideas in your mind
  • Pick good problems to start with - eg algorithmic problems, processing tree structures, etc.
  • Write as much F# as you can and don't be afraid to start with a solution that does not look perfect to you - I rewrote my first program so many times!
  • 链接地址: http://www.djcxy.com/p/80866.html

    上一篇: 在F#中使用机器学习的资源

    下一篇: 成为更好的F#程序员的途径