What does -> mean in F#?

后端 未结 9 1094
情深已故
情深已故 2020-12-03 02:54

I\'ve been trying to get into F# on and off for a while but I keep getting put off. Why?

Because no matter which \'beginners\' resource I try to look at I see very

9条回答
  •  旧时难觅i
    2020-12-03 03:35

    In the context of defining a function, it is similar to => from the lambda expression in C# 3.0.

    F#: let f = fun x -> x*x
    C#: Func f = x => x * x;
    

    The -> in F# is also used in pattern matching, where it means: if the expression matches the part between | and ->, then what comes after -> should be given back as the result:

    let isOne x = match x with
     | 1 -> true
     | _ -> false
    

提交回复
热议问题