You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
With IWSAMs support included in F# 7 the question is posed frequently: can we take advantages of IWSAMs and simplify the library?
IWSAMs are implemented in the CLR as first class citizens, this has lots of advantages but they have many limitations as compared to SRTPs:
As normal interfaces, they can't retroactively make a pre-existing type implement an interface.
They can't "calculate" new types. SRTPs allow arbitrary types to be inferred once the overload resolution is solved.
Their definitions can't contain inlined SRTPs.
In order to take advantage of IWSAMs we need a type class (Invokable) that
Doesn't involve primitive types
Doesn't have SRTPs / calculated type in the method implementation
Monoids fall into 2, but not into 1. Same is true for Pointed.
Monad trans methods fall into 1 but not into 2. Same is true for Invokables themselves.
Regarding the first limitation, it's technically possible to keep writing SRTPed Invokables for primitive types and define an InvokeOnInstance which instead of doing a trait-call, calls a static method from an IWSAM.
The question is, what's the advantage of doing that?
There might be some very specific cases where we don't care about primitive types (ie: Lenses) and we could replace a Return.InvokeOnInstance (Pointed) which is still a (simple) trait-call, with IWSAMs.
That advantage seems to be very marginal, if we look at disadvantages we can name a few:
Having 2 mechanism, one is used only is some specific cases, it's confusing
Switch to nominal types means giving up structural types, which means some 3rd party libraries should include a reference to F#+ in order to make their classes compatible.
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
With IWSAMs support included in F# 7 the question is posed frequently: can we take advantages of IWSAMs and simplify the library?
IWSAMs are implemented in the CLR as first class citizens, this has lots of advantages but they have many limitations as compared to SRTPs:
In order to take advantage of IWSAMs we need a type class (Invokable) that
Monoids fall into
2
, but not into1
. Same is true for Pointed.Monad trans methods fall into
1
but not into2
. Same is true for Invokables themselves.Regarding the first limitation, it's technically possible to keep writing SRTPed Invokables for primitive types and define an
InvokeOnInstance
which instead of doing a trait-call, calls a static method from an IWSAM.The question is, what's the advantage of doing that?
There might be some very specific cases where we don't care about primitive types (ie: Lenses) and we could replace a
Return.InvokeOnInstance
(Pointed) which is still a (simple) trait-call, with IWSAMs.That advantage seems to be very marginal, if we look at disadvantages we can name a few:
Beta Was this translation helpful? Give feedback.
All reactions