You never know when you might need this.
7 people like thisPosted: 13 years ago by Dmitri Pavlenkov
Simple domain-specific language (DSL) for describing financial contracts in F#. A contract is represented using a discriminated union. Evaluating a contract gives the orders that may happen at a given date.
8 people like thisPosted: 13 years ago by Tomas Petricek
The sample shows two different reprezentations of Tesco checkout. The first one stores scanned items - as a list of either purchase or cancel items - and the second stores final bill with product and total quantity. The snippet implements transformation that corresponds to finalizing the purchase.
3 people like thisPosted: 12 years ago by Tomas Petricek
A simple example that shows how to refactor discriminated unions to extract common members
3 people like thisPosted: 11 years ago by Tomas Petricek
Single-case Discriminated Unions (https://fsharpforfunandprofit.com/posts/designing-with-types-single-case-dus/) are a lightweight way to create types for important concepts in your domain. Unfortunately, there's a few gotchas when consuming from C# to be aware of. For one, if you use the `==` or `!=` operators in C#, it will do a reference comparison, which is almost certainly not what you want for these wrapper types. By overriding `op_Equality` and `op_Inequality`, this will force it to use a structural comparison. Secondly, when using string concatenation via `+`, `String.Format`, or string interpolation, C# will implicitly convert non-string arguments to a string via `ToString`. This means if you forget to use `.Item` to unwrap your value, you will not get a compiler error, it will just implicitly call `ToString`, which by default will look like this: `Id "c148b684-2c40-4383-a1b9-0e8f37752fd0"`. By overriding `ToString`, we can make sure it will look like the raw underlying type when converted to a string: `c148b684-2c40-4383-a1b9-0e8f37752fd0`.
2 people like thisPosted: 6 years ago by Justin Hewlett
This shows an alternative to using spaces in the discriminated union cases, which makes it harder to write in code, and tends to be needed when interoping with the likes of WPF or any other element that uses the ToString of the union case to display its value. Also useful as an alternative to using special characters like á or ç which make it harder to work with colleagues that don't have keyboards with those characters. Uses code from snippet http://fssnip.net/9l
0 people like thisPosted: 5 years ago by Micael Morais
A simple example of how to define a custom type that enforces extra business rules by using a single-case discriminated union with a private constructor
7 people like thisPosted: 4 years ago by Tomas Petricek
General toString and fromString for discriminated unions using FSharp.Reflection
46 people like thisPosted: 13 years ago by Jonas Avelin
Discriminated unions to represent a HTML file.(not completely)
3 people like thisPosted: 12 years ago by Gab_km
F# introduction course - Get and read the Titanic data set using CSV type provider, define the type of "feature" and use it to classify the data and then implement a simple decision tree that can be used for writing more complex classifiers. To be used in Try F#.
7 people like thisPosted: 11 years ago by Tomas Petricek
single-case DU with shadowed constructor for passing non-primitives around that are already validated.
5 people like thisPosted: 10 years ago by ImaginaryDevelopment.blogspot.com
This returns a sequence of union cases for a given discriminated union type, the values in this sequence can be passed into any place that expects a case of that discriminated union. Useful for use as the option values for a combobox, or for printing out all available options for that given discriminated union.
7 people like thisPosted: 5 years ago by Micael Morais
A generic value converter for discriminated unions, it allows to use a single converter for any discriminated union along with facilitating the creation of new ones with a default option value for when an incompatible union case is provided. Large part of this snippet uses http://fssnip.net/62 as a base, all credit on the ConverterBase goes to him, one of the authors also has a new version of it http://fssnip.net/7Q
1 people like thisPosted: 5 years ago by Micael Morais