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 »

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