Propagating optional arguments

F# spec 8.13.5 Optional arguments to method members

Callers may specify values for optional arguments by using the following techniques:

  • By name, such as arg2 = 1.
  • By propagating an existing optional value by name, such as ?arg2=None or ?arg2=Some(3) or ?arg2=arg2. This can be useful when building one method that passes optional arguments on to another.
  • By using normal, unnamed arguments matched by position.

    type A(?arg) =
        member __.Arg : string option = arg
    
    type B(?arg) =
        inherit A(?arg = arg) 
    
    printfn "1. %A" (B()).Arg // None
    printfn "2. %A" (B("1")).Arg // Some "1"
    
    printfn "3. %A" (A()).Arg // None
    printfn "4. %A" (A("1")).Arg // Some "1"