Learning F# : AboutTheStockExample koan

In the last couple of months, our Nashville .NET user group (@nashdotnet) has been working hard on learning F#. By the way, if you live in Nashville and are interested in Functional Programming, you can also join Nashville Functional Programmers or NashFP (@nashfp).

In the first week, we have walked through tutorials in try F# while the second week, we have played with F# Koans. The try F# tutorials have detailed explanation and code, and it will take you some time to finish it. F# Koans, by the way, is letting you learn F# by making the unit test (e.g., koan) pass. You can go through it pretty quickly, but you might not understand what’s going on much.

For the F# Koans, the last koan that I have done is AboutTheStockExample which is pretty challenging for F# newbie like me. Coming from C#, I have to resist thinking about applying loops or mutable variables. Anyway, after 15~ minutes of trial-and-error using F# interactive tool that comes with Visual Studio, I came up with the solution:

However, the solution looks just like someone is converting C# LINQ to F# Winking smile

If you want to find better solutions, a Leeds Sharp member has blogged about solving this koan while the best solution is shown in try F# site.

So far Learning F# is pretty fun and addicted journey although I haven’t spent time with it much yet (haven’t finished either try F# or Koans). Hopefully, I will get better with F# and start “Thinking functionally” soon.

Advertisements

2 thoughts on “Learning F# : AboutTheStockExample koan

  1. Hi kimsk, thanks for the link. Your solution looks pretty functional to me – C# LINQ is pretty much all functional, after all! Not that it reminds me of LINQ – it’s broadly similar to mine, apart from using two lists instead of tuples. I hadn’t come across map2 before, so it’s interesting to see that in action. I’ve seen a few solutions now and they’re all different, so I’m starting to think there is no best way!

    If you’re looking for something else to have a go at with F#, the Project Euler problems are a good bet: http://projecteuler.net/

    • Thanks for the comment, Grant. I agree that C# LINQ has functional taste, so it really helps. Project Euler looks fun. I’ll try that with F#. I know that our Nashville Functional Programmers has a repository for it in GitHub and encourage members to post solutions 🙂 https://github.com/NashFP/euler

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s