F# - 反向管道顺序

标签 f#

我怎么能做到:

let printTeams x : unit = 
    let rnd = new Random()
    Seq.toList x |> List.sortBy (fun x -> rnd.Next()) |> printTeams'

但不是:

let printTeams x : unit = 
    let rnd = new Random()
    printTeamsRec'  <| Seq.toList x <| List.sortBy(fun x -> rnd.Next())

我刚刚在最后一个错误中收到错误,其中显示:

Type mismatch. Expecting a string list -> 'a -> 'b but given a
string list -> unit The type ''a -> 'b' does not match the type 'unit'

错误发生在 printTeamsRec' 的第三行

如有任何帮助,我们将不胜感激。

最佳答案

有两件事:前向管道到后向管道的转换不正确,并且优先级不同。

let printTeams x : unit = 
    let rnd = new Random()
    printTeamsRec' <| (List.sortBy(fun x -> rnd.Next()) <| Seq.toList x)

关于F# - 反向管道顺序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5290009/

相关文章:

generics - 可区分联合的通用容器上的模式匹配

entity-framework - 是否可以在 F# 中实现 IDbSet<T> 接口(interface)?

.net - 为什么 F# 中 bigint 缺少按位非运算符 (~~~)?

recursion - 实现将实数转换为 #F 中的连分数的算法

f# - FSharp.Data.JsonProvider - 从类型中获取 json

f# - 记录 F# 代码

f# - Seq.find 返回 'a -> int 而不是 int

F# 中 ||> 和 |||> 管道运算符的性能影响

f# - F# 引用的另一个限制?

.net - F#、Deddle 和 R.Net : seq<'a> [] vs. IEnumerable 数组