F# pattern match directly against let binding

前端 未结 4 485
不知归路
不知归路 2021-01-18 22:39

Is it possible in F# to pattern match directly against a let binding?

For example, this compiles without any warnings:

    let value = 
        match         


        
4条回答
  •  情深已故
    2021-01-18 22:57

    just use capital letters and [] them and it works as expected.

    let [] X = 0
    let [] Y = 1
    let bla arg =
        match arg with
        | X -> "zero"
        | Y -> "one"
        | somethingelse -> somethingelse.ToString()
    

    the lower case name by convention typically means a wildcard that is bound to the name.

提交回复
热议问题