为什么以前定义的方法在fsharp的模块中不可用?

时间:2012-03-01 08:28:34

标签: f#

在toMap2函数的内部调用中无法识别Seq.toMap

open System
open Microsoft.FSharp.Collections

module Seq =
   let toMap(seqinit:seq<'a*'T>) = 
      seqinit |> Map.ofSeq

   let toMap2(seqinit:seq<'a*seq<'b*'T>>) = 
      seqinit |> Seq.map (fun (key1 ,seq1) -> (key1, seq1 |> Seq.toMap )) 
              |> Map.ofSeq

更新

一个更好的功能代码(初始pb解决为Ramon Snir建议)

let inline (||>) (seqinit:seq<'a*'T>) f = 
       seqinit |> Seq.map  (fun (key1 ,seq1) -> (key1, seq1 |> f ))

let toMap  (seqinit:seq<'a*'T>)                 =  seqinit |> Map.ofSeq
let toMap2 (seqinit:seq<'a*seq<'b*'T>>)         =  seqinit ||> toMap  |> toMap
let toMap3 (seqinit:seq<'a*seq<'b*seq<'c*'T>>>) =  seqinit ||> toMap2 |> toMap

1 个答案:

答案 0 :(得分:2)

open System
open Microsoft.FSharp.Collections

module Seq =
   let toMap(seqinit:seq<'a*'T>) = 
      seqinit |> Map.ofSeq

   let toMap2(seqinit:seq<'a*seq<'b*'T>>) = 
      seqinit |> Seq.map (fun (key1 ,seq1) -> (key1, seq1 |> toMap )) |> Map.ofSeq

在模块中您不需要合格的访问权限。只需致电toMap