I have two interfaces:
IState
and IAction
.
A State has a method: GetActions - which returns a collection of IActions.
A Action has a method: Apply - which acts on a State, to return a new State.
IState takes a type parameter to control what sort of actions it returns with get actions, IAction takes a type parameter to control what sort of states it can act on. (By sort, i ment implementation). I want to be able to garentee that a State only return actions that can act on a state of that same type.
type IAction<'S when 'S:>IState> =
abstract member Apply : 'S->'S
and IState<'A when 'A:>IAction<'S when 'S:> typeof(this)>> =
abstract member GetActions : seq<'A>
but obviously typeof(this)
is not a thing.
How can I have a type constraint making sure my type paramerer is of type equal to the type I am defining?