Functional Programming

F# – Extending Discriminated Unions using marker interfaces

One of the problems with using F#’s Discriminated Unions is that they are not extensible, in that all your union cases must be specified inside one Discriminated Union (abbreviated to DU from this point) type and you can’t inherit from an existing DU type to add additional union cases. In most cases, having to specify …

F# – Extending Discriminated Unions using marker interfaces Read More »

F# – Serializing F# Record and Discriminated Union types

I love using F#’s Record and Discriminated Union types, they work nicely with pattern matching inside your F# code and can often alleviate some of the ceremony involved around creating and using a complex object hierarchy. However, on the odd occasion when you need to serialize them into JSON/XML/Binary format, it might not be immediately …

F# – Serializing F# Record and Discriminated Union types Read More »

F# equivalent of C#’s Object Initialization syntax

In C#, you can use the object/collection initialization syntax like this: The F# equivalent of object initialization is done like this: As for collection initialization, you have a far more diverse range of tools available to you, for example: You can also create slices of an existing array: You can even add your own multi-dimensional …

F# equivalent of C#’s Object Initialization syntax Read More »

Performance Test – SortedDictionary vs Dictionary vs Map vs Array

I stumbled upon this interesting question on StackOverflow today, Jon Harrop’s answer mentions a significant overhead in adding and iterating over a SortedDictionary and Map compared to using simple arrays. Thinking about it, this makes sense, the SortedDictionary class sorts its constituent key-value pairs by key, which will naturally incur some performance overhead. F#’s Map …

Performance Test – SortedDictionary vs Dictionary vs Map vs Array Read More »

Project Euler – Problem 65 Solution

Problem The square root of 2 can be written as an infinite continued fraction. The infinite continued fraction can be written, ?2 = [1;(2)], (2) indicates that 2 repeats ad infinitum. In a similar way, ?23 = [4;(1,3,1,8)]. It turns out that the sequence of partial values of continued fractions for square roots provide the …

Project Euler – Problem 65 Solution Read More »

By continuing to use the site, you agree to the use of cookies. more information

The cookie settings on this website are set to "allow cookies" to give you the best browsing experience possible. If you continue to use this website without changing your cookie settings or you click "Accept" below then you are consenting to this.

Close