Using the F# pipe symbol with an object constructor

前端 未结 2 1413
粉色の甜心
粉色の甜心 2020-12-18 21:47

I\'m trying to figure out the correct syntax to use the pipe operator |> into the creation of an object. Currently I\'m using a static member to create the object and just

相关标签:
2条回答
  • 2020-12-18 22:02

    Apparently, object constructors aren't composable. Discriminated union constructors don't seem to have this problem:

    > 1 + 1 |> Some;;
    val it : int option = Some 2
    

    If you want to use the pipeline, Brian's answer is probably best. In this case, I'd consider just wrapping the entire expression with Shape( ).

    0 讨论(0)
  • 2020-12-18 22:18

    There's always

    (fun args -> new Shape(args))
    
    0 讨论(0)
提交回复
热议问题