Okay… don’t judge me… I have been coding in C# for a few years now and up till the point that I got into F# I never used lambda’s. This last week I realized just how much I am using the lambda expression in F# and thought it was about time I exposed myself to it in C#… So first of all, the lambda expression in C# is symbolized by the =>. From what I understand it is really syntactical sugar over the C# language to anonymous delegates, which have been in the language for sometime. I am not going ......

So I must admit, the first time I saw it I scratched my head and thought to myself, why will I ever use that? Several months since then and now I love the Forward Pipe (FP) in F#. Why? For me, the the FP makes me think of a problem in a different way. In C# when I attempt to solve I problem I typically break it down in steps, once I have reached the end result I have my smallest step, and then I work my methods backwards so that I can get back to the original input… in a very real way it makes me ......

Today I had a quick bash at problem 6. To me this has been the easiest of the problems so far. It is the first time though that I got to use the Seq.Fold function which was good to get exposure to. I am not to happy with my code though, I can’t explain it, but it just seems a bit messy… Anyhow, I look forward to feedback from everyone in the F# community on their approaches. Problem The sum of the squares of the first ten natural numbers is, 12 + 22 + ... + 102 = 385 The square of the sum of the ......

As per the post I decided to do a F# attempt at FizzBuzz. It took a few seconds… Using FizzBuzz to Find Developers who Grok Coding.. let FizzBuzz = seq {1..100} |> Seq.iter (fun x -> match x with | x when x % 5 = 0 && x % 3 = 0 -> printfn "FizzBuzz" | x when x % 3 = 0 -> printfn "Fizz" | x when x % 5 = 0 -> printfn "Buzz" | _ -> printfn "%d" x) ......

I hope I spelt “Fizzbuzz” correctly, but I had a real laugh listening to Hansel Minutes Show 218 when Scott suggested that we have a secret password to give to Tech Support so that they know we aren’t idiot’s. I think it is a great idea… So a typical call would go as follows… You) Hi, I need help with my internet connection Tech Support) Yes Sir, click the big button on the bottom left corner of your screen called the “start button” You) Fizzbuzz Tech Support) Okay, so you have obviously checked ......

So today I tackled a Euler problem that I had originally looked into several months back when I initially started exploring F# Problem 2520 is the smallest number that can be divided by each of the numbers from 1 to 10 without any remainder. What is the smallest positive number that is evenly divisible by all of the numbers from 1 to 20? Solution I decided on the brute force approach again. I believe that I could have worked with prime factors etc to have reached the solution a lot quicker – but ......

The last few days I began to play around with problem 4 of Euler. I really enjoyed this problem since it dealt with a few functions in F# that I haven’t dealt with in the past. Problem A palindromic number reads the same both ways. The largest palindrome made from the product of two 2-digit numbers is 9009 = 91 99. Find the largest palindrome made from the product of two 3-digit numbers. Solution So I divided the problem up into a few functions… reverseString simply reverses a string. isPalindrome ......

So I have been playing around with more Euler problems and I have found it a great way to learn some of the basic functions of F# and Seq specifically. The more I play the more I am really loving F# and how succinct the language is. Today I thought I would put up a brief post on the Seq.unfold function. So, I see this function being used everywhere… my understanding of it is that it is a way that one can build a sequence based on a series of commands. I will use a small code snippet to show an example ......

So this weekend I made an attempt at problem 3 of Project Euler. Problem 3 The prime factors of 13195 are 5, 7, 13 and 29. What is the largest prime factor of the number 600851475143 ? My Solution // // Checks whether a number is prime or not using the Trial Division approach // To improve performance I have only pass through odd numbers greater than 2 and do not check for this case // let isPrime (number : bigint) = match number with | _ -> seq { bigint(2) .. bigint(1) .. bigint (Math.Sqrt (float ......

Today I thought I would give a bash at problem 2 of Euler. Problem 2 Each new term in the Fibonacci sequence is generated by adding the previous two terms. By starting with 1 and 2, the first 10 terms will be: 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, ... Find the sum of all the even-valued terms in the sequence which do not exceed four million. My Solution (Brute Force) So first of all I needed a Fibonacci generator. I resorted to one that recursively defines the Fibonacci number based on the index with ......

Every now and then I give project Euler a quick browse. Since I have been playing with F# I have found it a great way to learn the basics of the language. Today I thought I would give problem 1 an attempt… Problem 1 If we list all the natural numbers below 10 that are multiples of 3 or 5, we get 3, 5, 6 and 9. The sum of these multiples is 23. Find the sum of all the multiples of 3 or 5 below 1000. My F# Solution I broke this problem into two functions… 1) be able to generate a collection of numbers ......

I did a recent post on implementing WPF with F#. Today I would like to expand on this posting to give a simple implementation of the MVVM pattern in F#. A good read about this topic can also be found on Dean Chalk’s blog although my example of the pattern is possibly simpler. With the MVVM pattern one typically has 3 segments, the view, viewmodel and model. With the beauty of WPF binding one is able to link the state based viewmodel to the view. In my implementation I have kept the same principles. ......

A few days ago I was programming on a personal project and hit a roadblock. I was applying the MVVM pattern and for some reason my view model was not updating the view when the state changed??? I had applied this pattern many times before and had never had this problem. It just didn’t make sense. So what did I do… I did what anyone would have done in my situation and looked to pass the blame to someone or something else. I tried to blame one of the inherited base classes, but it looked fine, then ......

I was listening to Dot Net Rocks show #560 about F# and during the podcast Richard Campbell brought up a good point with regards to F# and a GUI. In essence what I understood his point to be was that until one could write an end to end application in F#, it would be a hard sell to developers to take it on. In part I agree with him, while I am beginning to really enjoy learning F#, I can’t but help feel that I would be a lot further into the language if I could do my Windows Forms like I do in C# ......

This evening I had the pleasure of reading one of ThomasP’s blog posts on first class events. It was an excellent read, and I thought I would make a brief derivative of his post to explore some of the basics. In Thomas’s post he has a form with an ellipse on it that when he clicks on the ellipse it pops up a message box with the button clicked… awesome. Something that got me on the post though was the code similar to the one below… // React to Mouse Move events on the form let evtMessages = frm.MouseMove ......

Another day gone by looking into F#. Today I thought I would ramble on about lists and arrays in F#. Coming from a C# background I barely ever use arrays now days in my C# code – why you may ask – because I find lists generally handle most of the business scenario’s that I come across. So it has been an interesting experience with me keep bumping into Array’s & Lists in F# and I wondered why the frequency of coming across arrays was so much more in this language than in C#. Take for instance ......

Today I had a few minutes in the evening to go over my original Adam and Eve code… what I wanted to see tonight was if I could optimize the code any further… which I was pretty sure could be done. Ultimately what I wanted to find from the experiment was a balance between optimized code an reusable code. On the one hand I can put everything into a single function and end up with a totally unusable function that is extremely compressed, which would have big comebacks when making modifications at a ......

So I am loving my Expert F# book. I wish I had more time with it, but the little time I get I really enjoy. However today I was completely stumped by what the book was trying to get across with regards to pattern matching. On Page 38 – Chapter 3, it briefly describes F# option values. On this page it gives the code snippet along the code lines below and then goes on to speak briefly about pattern matching... open System type 'a option = | None | Some of 'a let people = [ ("Adam", None); ("Eve", None); ......