F# 2.0 命名空间警告

8

我刚刚安装了最新版本的F#,并打开了一个旧的解决方案,看看它会告诉我什么。

这是一个多文件解决方案,第一个文件包含一些对List模块的“扩展函数”:

module List = 
    ///Given list of 'rows', returns list of 'columns' 
    let rec transpose lst =
        match lst with
        | (_::_)::_ -> List.map List.hd lst :: transpose (List.map List.tl lst)
        | _         -> []
编译器不再支持此操作,并提示: 在库或多文件应用程序中,必须以命名空间或模块声明开头,例如“namespace SomeNamespace.SubNamespace”或“module SomeNamespace.SomeModule”。 但如果我这样做:
module Foo.List = 
它说:模块缩写必须是简单的名称,而不是路径。我在这里错过了什么?如果我要扩展来自其他地方的模块,有什么解决方案呢?
1个回答

阿里云服务器只需要99元/年,新老用户同享,点击查看详情
6

明确命名空间:

namespace Microsoft.FSharp.Collections

module List =  
    ///Given list of 'rows', returns list of 'columns'  
    let rec transpose lst = 
        match lst with 
        | (_::_)::_ -> List.map List.head lst :: transpose (List.map List.tail lst) 
        | _         -> []
请注意,List.hdList.tl已经更名为List.headList.tail

hd -> 头部,tl -> 尾部?这些人不关心代码高尔夫吗? :) - Benjol
4
答案的另一半很令人困惑,就是如果你没有命名空间,只有一个模块,那么在模块声明后面不能加上 =。但如果你有一个命名空间,就需要加上 =。 - Benjol

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,