Type extensions
Definition
Intrinsic extension
namespace Example
type Variant =
| Num of int
| Str of string
module Variant =
let print v =
match v with
| Num n -> printf "Num %d" n
| Str s -> printf "Str %s" s
// Add a member as an extension - see `with` required keyword
type Variant with
member x.Print() = Variant.print xOptional extension
Limits
Type extension vs virtual methods
Type extension vs type alias
Type extension vs Generic type constraints
Extension method (Cβ―-style)
Tuples
Comparison
Feature
Type extension
Extension method
Limits
Extensions vs Cβ― partial class
Feature
Multi-files
Compiled into the type
Any type
Last updated