gpt4 book ai didi

.net - F# 引用另一个文件中的模块函数

转载 作者:行者123 更新时间:2023-12-04 15:18:16 25 4
gpt4 key购买 nike

我正在编写一个非常初学者的 F# 程序( F# Core & Visual Studio Code )如下:

1.排序.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]

2.程序.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

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

The namespace or module 'Sort' is not defined.

The value, namespace, type or module 'Sort' is not defined. Maybe you want one of the following: sqrt



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

最佳答案

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

更多信息可以找到here , herehere

关于.net - F# 引用另一个文件中的模块函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47815943/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com