In continuing our look at F#, I’d like to look at flow control, like conditional and looping of logic.
Before I get to that, I mentioned in my previous post, that F# uses a type inference, which means the compiler can guess which type the variables and methods are. However, you can also explicitly declare a variable type.
For example, here is a function that takes in a string parameter, we are declaring the input as a string type. You can see how the function is called and passed input parameters from the EntryPoint main method:
let SayHello (input : string) =
printfn "Hello, %s" (input)
let main argv =
System.Console.ReadKey(false) |> ignore
0 // return an integer exit code
I wanted to pick up a new programming language and learn as I go along, which will hopefully let you learn as well. I have decided to learn F#. I was going to do Python, and probably will but I found a great blog that has already done this using Python. I would like to do a comparison between these languages as I know they are similar and F# was influenced by Python. As of now, I still don’t have a good reason to learn F#, but it’s syntax looks similar to Lambda expressions in C#, so it hopefully will open my mind more to functional languages. I took Scheme in college and found it to be a lot of fun, but not a very useful language, compared to a more object oriented based language.
The first thing I notice about F# is its succinctness. It uses Type Inference, which means the compiler will figure out what type a variable is, or what a function will return. So you don’t have to declare the types.
I can really see the functional programming style of Lambda (=>) expressions in C#.
Compatibility switches is a new feature in the .NET Framework 4.6 which will be useful for Windows App store applications. The .NET Framework only provided compile time features for supporting different versions. While this is a good way to support multiple features, it is not dynamic enough with the different formats and features that Windows applications will need to support today without using a custom solution.
For just a quick overview, the compilation version features are either using Preprocessor Directives and complication symbols, and the System.Diagnostics Conditional features seen below.
This week, I wanted to take a look at a non-technical topic, and talk about something that I found really helpful for me, Butter Coffee, aka Bulletproof Coffee. I know everyone’s first reaction is that it sounds disgusting but it tastes really good, and I can get some serious focus while consuming this mind friendly beverage. I have been drinking this for almost 2 years now and still look forward to it.
I think a worthwhile excursion for a .NET developer is to drill down the LINQ rabbit hole and see how far we can go. A good first step is delegates.
There are delegates, multicast delegates and their syntactically sweeter versions, Actions, Funcs.
First, what is a delegate?