Skip to content

Instantly share code, notes, and snippets.

View hasrthur's full-sized avatar

Artur hasrthur

  • Lviv
  • 20:41 (UTC +02:00)
View GitHub Profile
@swlaschin
swlaschin / ConstrainedTypesExamples.fsx
Last active November 5, 2024 23:28
Examples of creating constrained types in F#
// General hints on defining types with constraints or invariants
//
// Just as in C#, use a private constructor
// and expose "factory" methods that enforce the constraints
//
// In F#, only classes can have private constructors with public members.
//
// If you want to use the record and DU types, the whole type becomes
// private, which means that you also need to provide:
// * a constructor function ("create").