2012-03-01 47 views
1

Seq.toMap未在toMap2功能爲什麼以前定義的方法在fsharp的模塊中不可用?

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 

UPDATE

一個更好的功能代碼將是的內調用識別(與初始PB作爲解決聖拉蒙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 

回答

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即可。

+0

是的,我明白了這一點。模塊和命名空間在這一點上對我來說是相當混亂的。 – nicolas 2012-03-01 08:42:32

相關問題