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)
但是,这会给出错误:
未定义类型"标识符"
如何将我的类型案例用作类型参数?
Identifier是一个案例构造函数,而不是一个类型.它实际上是一个类型的函数string -> Expression.案例的类型是string,所以你可以定义definitions为
type definitions : Map<string, Expression>
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
61 次 |
| 最近记录: |