Learning F# Using Project Euler
I’ve decided that immersion is the best way for me to learn new programming concepts. My exposure to WPF came 4 years ago when I started at a new employer and was told that my first assignment was to learn the application codebase and create a WPF Datagrid that could display data from our application (the view of the data was dynamically composed using metadata from an EAV database). Needless to say, the effort helped bring me up to speed quickly with both the internal codebase and WPF.
I want to learn F# and have been looking for a way to immerse myself in it. Enter Project Euler, an online collection of math/computer science puzzles. I’m using F# to solve the problems one by one, purposefully using the functional aspects of the language rather than the OO aspects. Here is my solution for the first problem in F#
let list =
[1..999]
|>List.map(fun n ->
if n % 3 = 0 || n % 5=0 then
n
else
0)
|>List.sum
printfn "Sum of integers %d" list
I’m trying to figure if there’s a way for me to remove the if…then…else clause (possibly using pattern matching). But I guess it’s a good start for now.