F# explicit match vs function syntax

后端 未结 8 2488
耶瑟儿~
耶瑟儿~ 2020-12-04 23:21

Sorry about the vague title, but part of this question is what these two syntax styles are called:

let foo1 x = 
    match x with
    | 1 -> \"one\"
    |         


        
8条回答
  •  北荒
    北荒 (楼主)
    2020-12-04 23:32

    The pro for the second syntax is that when used in a lambda, it could be a bit more terse and readable.

    List.map (fun x -> match x with | 1 -> "one" | _ -> "not one") [0;1;2;3;1]
    

    vs

    List.map (function 1 -> "one" | _ -> "not one") [0;1;2;3;1]
    

提交回复
热议问题