-
Notifications
You must be signed in to change notification settings - Fork 16
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Shadowing as a workaround for orphans #23
Comments
When I started this project and was hitting my head against the wall trying to workaround orphan instances I came to the conclusion that a way to implement a poor man orphan instances is by shadowing functions and then re-wiring the overloads to the original definition by adding and additional parameter. 1 - Does it work always, or at least in most cases? If the latter is not possible it might be another good point to switch to your proposed convention although default methods seems to be preferable feature over orphan instances. |
I had a look at the proposal, tested your script and did some tests on my own.
and it will fail, because the tuple instance does the original call, without the new (orphan) instance. Right now in the coming version 2 of FsControl a new convention is being used, which is very similar to the one used in Fleece but usually has an extra parameter for defaults. I found that doing a slight modification of that convention, that allows you to keep passing on the extra parameter through all calls, it's possible to workaround it. Here's a working solution. |
Interestingly the above mentioned technique is being used now in F#+ to specify default methods for the MonadPlus/Alternative Invokables when used by generic computation expressions. The idea there is that monads that are not MonadPlus should use a generic 'sequencing' implementation based on This shows that this technique is not only good as a workaround for orphans, it also allows you to create a different version of the Invokable class and augment it with other defaults. |
I've been thinking about a workaround for orphan instances. One way would be to shadow the original inline function and add another dictionary/lookup type.
For example, say you want to use Fleece to serialize a
System.Collections.Generic.HashSet<T>
. This type is currently not defined in the ToJSON class in Fleece, so it would be an orphan. Here's the shadowing:I'm almost certain this can also be done with the FsControl convention, but surely you can figure out how faster than me :)
The obvious downsides:
Do you see any other downsides? What do you think?
The text was updated successfully, but these errors were encountered: