因此,我有以下法典:
// Learn more about F# at http://fsharp.net
open System
open System.Linq
open Microsoft.FSharp.Collections
let a = [1; 2; 3; 4; 54; 9]
let c = a |> List.map(fun(x) -> x*3) |> List.filter(fun(x) -> x > 10)
let d = a.Select(fun(x) -> x*3).Where(fun(x) -> x > 10)
for i in c do
Console.WriteLine(i)
for i in d do
Console.WriteLine(i)
这两种情况似乎都是一样的,但大多数F#例见我使用“The >;管道运营商,而I m则更多地用于计算链条(a.l.a. C# Linq)。 后者也稍有缩短,不过,它们又增加了共同点。 现在使用C# Linq syntax的i m,但这一数值比任何真正的设计决定都多。
我是否知道或基本相同的考虑?
Edit: The other consideration is that the Pipe syntax is significantly more "noisy" than the Linq syntax: the operation I am doing (e.g. "map") is really short and in lowercase, while each one is preceded by this Huge "|> List" that, apart from making it longer distracts the eye away from the tiny, lowercase method name. Even StackOverflow s syntax highlighter highlights the wrong (irrelevant) thing. Either that or I m just not used to it.