如何在类型参数中使用区分联合分支?

sdg*_*sdh 5 generics f# discriminated-union

假设我在F#中有这样的类型:

type public Expression =
    | Identifier of string
    | BooleanConstant of bool
    | StringConstant of string
    | IntegerConstant of int
    | Vector of Expression list
    // etc...
Run Code Online (Sandbox Code Playgroud)

现在我想使用这种类型来构建一个地图:

definitions : Map<Identifier, Expression>
Run Code Online (Sandbox Code Playgroud)

但是,这会给出错误:

未定义类型"标识符"

如何将我的类型案例用作类型参数?

Mar*_*ann 5

Identifier是一个案例构造函数,而不是一个类型.它实际上是一个类型的函数string -> Expression.案例的类型是string,所以你可以定义definitions

type definitions : Map<string, Expression>
Run Code Online (Sandbox Code Playgroud)