在内部使用列表时未定义相互递归类型
Mutual recursive types are not defined when using lists inside
我在编译位于 here. Offending file is here.
的旧 F# 项目时遇到问题
它使用相互递归类型并且正确定义了缩进。但是none越少,不是EDNValue
,也不是EDNValueParsed
,都是在同样的context/indentation水平上看到的。
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): Error FS0039: The type 'EDNValueParsed' is not defined. (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"
更正后项目构建没有错误。
我在编译位于 here. Offending file is here.
的旧 F# 项目时遇到问题它使用相互递归类型并且正确定义了缩进。但是none越少,不是EDNValue
,也不是EDNValueParsed
,都是在同样的context/indentation水平上看到的。
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): Error FS0039: The type 'EDNValueParsed' is not defined. (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"
更正后项目构建没有错误。