Recently, I began an attempt to learn the new .NET language, F#. I had never worked with a functional programming language before, and the C# 3.0 “functional” features had piqued my interest. I began by buying the excellent Expert F# 2.0 written for the F# 2.0 spec. It is written by Don Syme the designer and architect of F#. Its an excellent book, which I highly recommended.
I only have two small criticisms of the book which can probably be overlooked. First, it is a little unforgiving in making sure the reader is “up to speed” when combining concepts introduced in previous chapters. This is a book where you will want to take notes, and make sure you understand the concepts before moving on. Secondly, it has many chapters towards the end describing the basics of the .NET framework, which may be useful to some but are also a repeat of what I see in dozens of other books in the same family, e.g. .NET, Silverlight, C#, asp.net mvc, webforms, etc.
While the book was excellent, I do my best learning by doing and not reading. So what program should be my first in F#?
I found a blog post in my daily barrage of code forum emails that looked interesting enough to try and solve with F#. It described an approach to programmatically solving a riddle created by Albert Einstein. The riddle is as follows:
- In a town, there are five houses, each painted with a different color.
- In every house leaves a person of different nationality.
- Each homeowner drink a different beverage, smokes a different brand of cigar, and owns a different type of pet.
Who owns the fishes?
- The Brit lives in a red house.
- The Swede keeps dogs as pets.
- The Dane drinks tea.
- The Green house is next to, and on the left of the White house.
- The owner of the Green house drinks coffee.
- The person who smokes Pall Mall rears birds.
- The owner of the Yellow house smokes Dunhill.
- The man living in the center house drinks milk.
- The Norwegian lives in the first house.
- The man who smokes Blends lives next to the one who keeps cats.
- The man who keeps horses lives next to the man who smokes Dunhill.
- The man who smokes Blue Master drinks beer.
- The German smokes Prince.
- The Norwegian lives next to the blue house.
- The man who smokes Blends has a neighbor who drinks water.
To be continued in part 2.