How to limit import of a module in F # to a local area?

Is it possible to locally restrict import of a module, is it preferable to combine it with Module Abbreviations? The goal is not to pollute my current module with symbols from imports.

eg. (inspired by OCaml) something like this:

let numOfEvenIntegersSquaredGreaterThan n =
    let module A = Microsoft.FSharp.Collections.Array in
        [|1..100|] |> A.filter (fun x -> x % 2 = 0)
                   |> A.map    (fun x -> x * x)
                   |> A.filter (fun x -> x > n)
                   |> A.length

let elementsGreaterThan n =
    let module A = Microsoft.FSharp.Collections.List in
        [1..100] |> A.filter (fun x -> x > n)

Also, is there a way to achieve something similar with namespaces?

+5
source share
1 answer

The goal is not to pollute my current module with characters from import.

Note that it is open Arraynot allowed in F # (contrary to OCaml). You can use abbreviations for modules, but only in the global area:

module A = Microsoft.FSharp.Collections.Array

Microsoft.FSharp.Collections.Array Array. , :

let numOfEvenIntegersSquaredGreaterThan n =
    [|1..100|] |> Array.filter (fun x -> x % 2 = 0)
               |> Array.map    (fun x -> x * x)
               |> Array.filter (fun x -> x > n)
               |> Array.length

, Seq:

let elementsGreaterThan n =
    [1..100] |> Seq.filter (fun x -> x > n)
+1

All Articles