nicolas
nicolas

Reputation: 9805

why are previously defined methods not available in a module in fsharp?

Seq.toMap is not recognized in the inner invocation of the toMap2 function

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

a better functional code would be (with initial pb solved as Ramon Snir suggested)

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

Upvotes: 1

Views: 114

Answers (1)

Ramon Snir
Ramon Snir

Reputation: 7560

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

You don't need qualified access while in the module. Just call toMap.

Upvotes: 2

Related Questions