Given:
let ab = ArgumentBlockSettingStore()
let a = ab :> ISettingStore
Is there a way to define a prefix operator (~~)
so that
let ab, a = ~~ArgumentBlockSettingStore() : _ * ISettingStore
becomes possible?
Given:
let ab = ArgumentBlockSettingStore()
let a = ab :> ISettingStore
Is there a way to define a prefix operator (~~)
so that
let ab, a = ~~ArgumentBlockSettingStore() : _ * ISettingStore
becomes possible?
I think you're hitting the compiler restrictions that you mentioned in the comment - you can't write the ~~
operator in a fully generic and safe way meaning that it will only allow casting to an interface that the argument implements. You can define an operator that will cast to any other type, but that's less safe:
let inline (~~) (a:^T) : ^T * ^R = a, (box a) :?> ^R
let reader, (disposable:IDisposable) = ~~(new StreamReader("..."))
I used inline
, because the operator is quite simple, but it works the same way with normal operators. This compiles even if you use Random
in the type annotation for disposable
, which is a bit unfortunate.