Open alaendle opened 1 week ago
Maybe my last code-snippet with works
and how
signatures is a little bit misleading. Given a BareB
instance I can write some "addition" for types like Bar
as follows:
addB :: (BareB b, ApplicativeB (b Covered)) => b Bare Identity -> b Covered Maybe -> b Bare Identity
addB x dx = bstrip $ bzipWith fromMaybeI (bcover x) dx
fromMaybeI :: Identity a -> Maybe a -> Identity a
fromMaybeI (Identity a) Nothing = Identity a
fromMaybeI _ (Just a) = Identity a
For sure I can implemented this for my nested Foo
type "by-hand":
add :: Foo Bare Identity Identity -> Foo Covered Maybe Maybe -> Foo Bare Identity Identity
add (Foo x y) (Foo dx dy) = Foo (runIdentity $ fromMaybeI (Identity x) dx) (maybe y (addB y) dy)
But is it possible to write something similar to addB
? I'm mean something that is in the same way generic.
As you say, in order to use Cover
/Bare
with with Foo
we'd need something like BareT
. In the end I never used BareB
too much myself so it got all probably a bit neglected when I added the "transformers" part of the api (instead of BareB
I tend to just use some accessor function that strips the Identity
, and was hoping Unsaturated Type Families would eventually make it to the language). At the moment I don't have much time to look into it, but if you or someone else would like to submit a PR that adds BareT
, I'd happily accept it :)
Thanks for your quick reply. While it is easy to "copy" BareB
for BareT
I fear the GenericsN
stuff is above my proficiency level.
I'll need a instance like:
barbies-2.1.1.0:Barbies.Generics.Bare.GBare
0
(Rec
(Data.Functor.Identity.Identity
(Nested2FW
Covered
(barbies-2.1.1.0:Data.Generics.GenericN.Param
0 Data.Functor.Identity.Identity)))
(Data.Functor.Identity.Identity
(Nested2FW Covered Data.Functor.Identity.Identity)))
(Rec
(Nested2FW
Bare
(barbies-2.1.1.0:Data.Generics.GenericN.Param
0 Data.Functor.Identity.Identity))
(Nested2FW Bare Data.Functor.Identity.Identity))’
Guess the problem is that it is not obvious for GHC that Param 0 Identity
is actual Identity
and therefore a simple instance like
Coercible a b => GBare n (Rec (Identity a) (Identity a)) (Rec b b)
could match.
I fear the GenericsN stuff is above my proficiency level
If it's any consolation, I need to think again from the beginning how this works every time I work on it :)
Not sure how useful it will be without the commentary, but here are some old slides that I used to explain the general idea behind GenericN
.
As a first step, what I'd do is study a bit how the generic implementation of FunctorB and FunctorT differ, as that will probably guide you into what needs to be done for BareB / BareT?
Thank you, a really good introduction to the subject. But I'm still getting a bit confused. At the moment I can understand it more or less for each of the paths - but somehow I need both simultaneously (in order to be able to switch between Covered
and Bare
in a type-safe way); and so I'm not sure whether I don't have to change even more deeply. I'm thinking of the FilterIndex
or the use in RepP
- or I've completely lost track. I'm afraid I'd have to rebuild it from scratch to really understand the underlying mechanisms - I'm not sure I want to go down that path anymore 🤔
Hi, first thank you for this library - I really love the approach ❤️. While I am playing around with modelling a data type that I can view both as a "whole" (
Identity
) and as "patch" (Maybe
) - so that the can add patches (Semigroup
) and apply them also to the whole object I stumbled around the following problem/question (but I'm pretty sure this is due to some misconception or limited knowledge on my side - but maybe you can point me to the right direction):How can I combine bi-functors/nesting with covering/stripping?
To illustrate my problem:
This code works fine, but my problems begin to arise if I try to model using
Wear
to get rid ofIdentity
for the "whole".And now to my problem - how to cover
Foo
?For sure, by looking at the types it is pretty obvious why this couldn't work- however I'm relatively unsure if or how this could be resolved. As far as I get I couldn't implement
BareB
forFoo
? Do "we" miss something likeBareT
?Thanks in advance for any hint how to solve this and please let me know if I was unclear or could contribute further information.