F#从另一个文件中引用模块功能

Avi*_*ale 5 .net f# functional-programming .net-core

我正在编写一个非常初学者的F#程序(F#CoreVisual Studio Code),如下所示:

1.Sort.fs

namespace Demo

module Sort =
    let rec quickSort list =
        match list with
        | [] -> []
        | head::tail ->
            let smalls =
                tail |> List.filter(fun c-> c<head)|> quickSort
            let bigs =
                tail |> List.filter(fun c-> c>=head)|> quickSort
            List.concat [smalls;[head];bigs]        
Run Code Online (Sandbox Code Playgroud)

2.Program.fs

namespace Demo

open Sort

module Program =
    let list = [3;1;8;4;9;5;7;6]

    [<EntryPoint>] 
    let main argv =
        list |> Sort.quickSort |> printfn "%A"       
        printfn "Hello World from F#!"
        0
Run Code Online (Sandbox Code Playgroud)

但是,当我尝试open Sort模块化时,我Main遇到以下错误:

未定义名称空间或模块"排序".

未定义值,命名空间,类型或模块"排序".也许你想要以下之一:sqrt

在哪里,如果我把sort模块放在同一个文件下 - `Program.fs,一切正常.还有什么需要引用文件吗?

Ira*_*nia 6

项目资源管理器中文件的顺序非常重要。如果Sort要从模块中使用模块ProgramSort.fs必须出现在之前Program.fs

可以在此处此处此处找到更多信息