21 people like it.

Active pattern to define default values

This active pattern allows you to specify default values for option arguments in the signature of your function, so you can remove unnecessary calls to defaultArg. It also save you having to define a new name for the defaulted value.

1: 
2: 
3: 
4: 
5: 
6: 
let (|Default|) defaultValue input =
    defaultArg input defaultValue

//val compile : bool option -> bool
let compile (Default true optimize) = 
    optimize
val defaultValue : 'a
val input : 'a option
val defaultArg : arg:'T option -> defaultValue:'T -> 'T

Full name: Microsoft.FSharp.Core.Operators.defaultArg
val compile : bool option -> bool

Full name: Script.compile
active recognizer Default: 'a -> 'a option -> 'a

Full name: Script.( |Default| )
val optimize : bool
Raw view Test code New version

More information

Link:http://fssnip.net/5z
Posted:13 years ago
Author:Kurt Schelfthout
Tags: active patterns , defaultarg , option