Another rushed post, thought of in the shower, written before I get to work. This is day 3 of my actually trying to learn and use F#. Everything here is rather rough.
If you groaned at the title then I guess your a functional programmer too 🙂
What do I mean?
In VB or C#, a function/method that has more than one parameter (that is not optional!) requires them all to be called before it will get past the IDE.
What happens if you wanted to return a partial function because you didn’t collect all the needed parameters yet?
In F# functions do not require all the parameters, they just don’t execute until they have them.
Have a look:
let p = [1;2;3] |> List.map(fun x -> x * x * x)
let q x y = x * y / (x * 2 + y)
let d = p |> List.sum
let x = q d 10
let part1 = q 10
let part2 = part1 12
printfn "Value of X: %A - Value of curried function: %A" x part2
printfn "List is now %A" p
As I’ve literally got two minutes before I’m officially going to be late for work, I will clarify this code further.
Also lookout for my fight with Mvvm, Entity Framework and Repository – the controversial extra layer for my data. Yes, I got one working with navigation properties but I have to say, for newcomers to N-tier, WPF and EF5 it is not an easy run. I think my research blog count ran to 30 explorer tabs before I was done!
For those that wonder why so many little blog posts, it’s part of my learning strategy. Reading alone has never been enough for coding work, neither has watching. So my strategy in no specific order is: read & watch, apply and question, write and teach. Ok, take that very last point with a big pinch of salt as I’ve yet to take the time to build any step by step tutorials or explanations.
The small code chunks are also the result of working through Project Euler as a means of apply code Kata practice to my learning.
As I started to code somewhere in my 33rd year of life, I’ve some catching up to do!
New book, Purely Functional Data Structures arrived today!
I can use it within the .net world and it emphasises a contrasting code style / way of thinking. It has type providers-giving me intellisense strongly typed objects from Sql, Odata and even R-a stats language I’m thinking about learning.
Also, I can use my comfortable Vb or even C# for interface work.