-
Notifications
You must be signed in to change notification settings - Fork 33
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
support for constraints #18
Comments
Another solution which looks fine to me is parametrise DMap over one more parameter which can be DSum. This has the big advantage of being backward compatible. I will give this a go |
@paolino Hey! This looks like interesting stuff :) Thanks for thinking about backwards compatibility - I definitely think we should try very hard to maintain backwards compatibility. Another concern is performance: existentials are generally very slow, and adding additional memory usage to DMap could have a serious impact, since so many of the datastructures are currently very small, so even one additional field could add 33-50% more memory usage. |
Yep, I've found a solution which is backward compatible
then
and all functions working with f a now have c a at disposal
Sadly I arrived there after 3 trials and changing some code on dependent-sum and now I have to get back. Thanks for commenting |
It seems like it should also be possible without modifying DSum, by using a type that wraps a key and adds the context - something like:
I don't have the time to fully explore the idea, unfortunately, but it seems like it should provide the same information and allow the same map operations to be written. |
Yeah, that would make sense to me! I *suspect* it's doable.
…On Mon, Sep 18, 2017 at 3:06 PM, James Cook ***@***.***> wrote:
It seems like it should also be possible without modifying DSum, by using
a type that wraps a key and adds the context - something like:
data Constrained c k t where Constrained :: c t => k t -> Constrained c k t
I don't have the time to fully explore the idea, unfortunately, but it
seems like it should provide the same information and allow the same map
operations to be written.
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
<#18 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/ABGlYE7JC-9TjEbFcLD7Gso4qqMK60mCks5sjr9IgaJpZM4PaFxs>
.
|
If I understand correctly then I find myself working with
which is somewhat not what I want because I cannot define the 'k' as the GADT at the caller of map
I would like to keep the client as minimal as this if possible. |
what the
https://hackage.haskell.org/package/vinyl-0.7.0/docs/Data-Vinyl-Core.html#t:Dict given
or, to constrain only the value and not the whole functor:
But since DMap works for all types, not a known list of types like class Show1 f where https://hackage.haskell.org/package/transformers-0.4.3.0/docs/Data-Functor-Classes.html for example, iiuc, you would.reify the constraint by constructing the DSum with GDict, instead of Identity: -- :: GDict Show Maybe Char then consume the constraint: :: (forall v. (GDict f v) -> g v) -> DMap k f -> DMap k g -- pattern matching exposes the constraint -- or to preserve constraint: :: (forall v. DSum v => (GDict f v) -> (GDict g v) -> DMap k f -> DMap k g |
I've added support for constraint in DSum and DMap.
I'm needing this at my work to make a more useful map operation
where I can do something on the v while changing the containing type
I'm not sure it is worth the bump (useful for anyone else) as I guess it will break all code around . But I'd like to know opinions before not submitting the pull request.
My stab has just deleted the Read instances, I couldn't solve the issues for that.
Hope it is interesting for someone else, because if it's not I will just use a list of modified definition of DSum with a lookup based on GOrdering which suffices for my needs (read-only , small set)
Btw, thanks a lot for this code, which I find a great approach to tackle modular software aspects
The text was updated successfully, but these errors were encountered: