Propagating optional arguments

前端 未结 3 1574
难免孤独
难免孤独 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:57

    Sorry had to test it first: it seems you are right - you have to do the "?" for A yourself:

    type A(arg : string option) =
      new (a) = new A(Some a)
      new () = new A(None)
      member __.Arg : string option = arg
    
    type B(?arg) =
      inherit A(arg)
    

提交回复
热议问题