3
votes

I'm using a type provider to create a versioned api, where you can choose to select older versions of a component to call than the current lastest version.

At the moment, it puts these in a namespace that looks something like:

Provided.ComponentName.VersionName(... this is the type constructor ...)

ComponentName is a namespace at the moment, if that makes a difference.

Once I've built all the specific versions of the component, I'd also like to expose:

Provided.ComponentName.Latest(... constructor ...)

as either a static method or a type alias that will return an instance of the most recent version.

What's the best way of doing this?

1

1 Answers

3
votes

I don't think there is a way to generate F# type alias (which would be a nice way to alias Latest to a specific version of the type).

As an alternative, I suppose you could generate VersionName as a nested type and Latest as a static method that returns the appropriate version of the type. To do this, ComponentName would have to be a type containing other types & one static method:

// 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(....)

The only ugly thing about this is that VersionName is a type (and can be created using new) while Latest is a static method and so it won't work with new.