我在编译位于here的旧F#项目时遇到问题。违规档案为here。
它使用相互递归类型,并且正确定义了缩进。但是,在同一上下文/缩进级别上看不到EDNValue
和EDNValueParsed
。
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>
我错过了什么?
答案 0 :(得分:1)
如果您有新版本的VS,则无法使用旧的“预安装”版本的FSharp.Core(4.0.0.0
)。
所以,像这样引用:
<Reference Include="FSharp.Core, Version=4.0.0.0, Culture=neutral,
PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL" />
将会破产。
我无法从问题中重现错误,但我得到的错误非常简单:
无法解析此链接。找不到程序集“FSharp.Core,Version = 4.0.0.0,Culture = neutral,PublicKeyToken = b03f5f7f11d50a3a,processorArchitecture = MSIL”
“FSharpList&lt;&gt;”类型在未引用的程序集中定义。您必须添加对程序集“FSharp.Core,Version = 4.3.0.0,Culture = neutral,PublicKeyToken = b03f5f7f11d50a3a”的引用
修正后的项目构建没有错误。