types - 在内部使用列表时未定义相互递归类型

标签 types f# recursive-type

我在编译位于 here 的旧 F# 项目时遇到问题.有问题的文件是 here .

它使用相互递归类型,并且正确定义了缩进。尽管如此,EDNValueEDNValueParsed 都不会出现在相同的上下文/缩进级别。

module EDNParserTypes =
 type EDNException(message : string) = 
    inherit System.Exception(message)

 type QualifiedSymbol = 
    struct
        val prefix: string
        val name: string
        new (prefix, name) = {prefix = prefix; name = name}
        override this.ToString() = "QualifiedSymbol Prefix: " + this.prefix + " Name: " + this.name 
    end

 type EDNValue = EDNNil
                | EDNBoolean of bool
                | EDNString of string
                | EDNCharacter of char
                | EDNSymbol of QualifiedSymbol
                | EDNKeyword of QualifiedSymbol
                | EDNInteger of BigInteger
                | EDNFloat of double
                | EDNComment of string
                | EDNDiscard of EDNValueParsed
                | EDNTaggedValue of QualifiedSymbol * EDNValueParsed
                | EDNList of string list
                | EDNVector of string array
                | EDNMap of List<string>
                | EDNSet of List<string>
  and EDNValueParsed = 
    struct
        val line: int64
        val col: int64
        val ednValue: EDNValue
        new (ednValue, line, col) = { ednValue = ednValue; line = line; col = col }
        override this.ToString() = 
            sprintf "%A" this.ednValue
    end

这两个函数之后定义,编译失败,因为 EDNValueParsed 未被定义。 EDNParserTypes.fs(41,41):错误 FS0039:未定义类型“EDNValueParsed”。 (FS0039) (EDNReaderWriter)

let getLineColString (valueParsed : EDNValueParsed) =
    System.String.Format("line: {0}, column: {1}", valueParsed.line, valueParsed.col); 

let isNotCommentOrDiscard (v : EDNValueParsed) =
    match v.ednValue with 
    | EDNComment _ | EDNDiscard _ -> false
    | _ -> true

奇怪的是,如果我删除类型的列表部分定义,它不会失败(但显然在其他需要这些定义的地方失败)

删除这部分后,类型被正确定义:

   | EDNList of string list
   | EDNVector of string array
   | EDNMap of List<string>
   | EDNSet of List<string>

我错过了什么?

最佳答案

如果您有新版本的 VS,则不能有旧的“预安装”版本的 FSharp.Core (4.0.0.0)。

所以,像这样引用:

<Reference Include="FSharp.Core, Version=4.0.0.0, Culture=neutral,
PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL" />

会坏掉的。

我无法重现问题中的错误,但我得到的错误非常简单:

Could not resolve this link. Could not find assembly "FSharp.Core, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL"

The type "FSharpList<>" is defined in an assembly that is not referenced. You must add a reference to assembly "FSharp.Core, Version=4.3.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"

更正后项目构建没有错误。

关于types - 在内部使用列表时未定义相互递归类型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50612172/

相关文章:

C# 访问接口(interface)数组中对象的非接口(interface)方法

c++ - Number Base 转换和数字访问?

f# - 如何让 F# Interactive 窗口使用与项目相同的路径?

F# 使用递归列表

c++ - 分配自身的类型的分配器

c# - 如何将 "int"分配给对象?

php - Typo3 extbase @param int 不工作

f# - 如何在 f# 中声明和使用标记接口(interface)?

typescript - 如何获得元组元组的扁平元组类型?