Propagating optional arguments

前端 未结 3 1568
难免孤独
难免孤独 2021-02-13 17:11

The following code does not compile.

type A(?arg) =
  member __.Arg : string option = arg

type B(?arg) =
  inherit A(arg) //ERROR expected type string but has t         


        
3条回答
  •  余生分开走
    2021-02-13 17:59

    F# will translate ?-marked arguments to optional values. Providing an argument gives a Some-value while not providing it gives a None-value. The combination of optional and named arguments lets you have huge flexibility.

    See also my answer here https://stackoverflow.com/a/66043023/15143713 /JEE, Sharp#Soft

提交回复
热议问题