我可以在F#类型提供程序中生成相同类型的多个别名吗?
我正在使用类型提供程序创建一个版本化的api,在这里,您可以选择要调用的组件的旧版本,而不是当前的最新版本 目前,它将它们放在一个名称空间中,类似于:我可以在F#类型提供程序中生成相同类型的多个别名吗?,f#,type-providers,F#,Type Providers,我正在使用类型提供程序创建一个版本化的api,在这里,您可以选择要调用的组件的旧版本,而不是当前的最新版本 目前,它将它们放在一个名称空间中,类似于: Provided.ComponentName.VersionName(... this is the type constructor ...) ComponentName目前是一个名称空间,如果这有区别的话 一旦我构建了组件的所有特定版本,我还想公开: Provided.ComponentName.Latest(... constructor
Provided.ComponentName.VersionName(... this is the type constructor ...)
ComponentName
目前是一个名称空间,如果这有区别的话
一旦我构建了组件的所有特定版本,我还想公开:
Provided.ComponentName.Latest(... constructor ...)
作为静态方法或类型别名,将返回最新版本的实例
最好的方法是什么?我不认为有办法生成F#type别名(这将是将最新的别名为该类型的特定版本的好方法) 作为替代方案,我假设您可以将
VersionName
生成为嵌套类型,将Latest
生成为静态方法,以返回类型的适当版本。为此,ComponentName
必须是包含其他类型的类型&一个静态方法:
// Creates an instance of `VersionName`
// (a nested type of `ComponentName`)
Provided.ComponentName.VersionName(....)
// Creates an instance of `SomeVersionName` type
// (a static method of the `ComponentName` type)
Provided.ComponentName.Latest(....)
唯一糟糕的是,
VersionName
是一种类型(可以使用new
创建),而Latest
是一种静态方法,因此它不能与new
一起使用 谢谢你,托马斯。遗憾的是,化名是不可能的。