hi,
i keep trying to find something that feels terribly obvious but i can't make any link.
say i have a function of the following type:
foo :: (a, b) -> ([a], [b]) -> ([a], [b])
or perhaps more generally:
foo :: SomeClass f => f a b -> f [a] [b] -> f [a] [b]
is SomeClass supposed to be BiFunctor or something else?
clearly, what i want to do is to combine the elements of the first pair into the elements of the second, preferrably without pattern matching, that is, merely in function of (:).
i think the problem with bifunctor is that it seems to only allow the application of both arguments in a separate fashion. but here the first argument is in one block, that is (a,b).
i know, ofc we could do something like:
foo pair pairList = bimap (fst pair :) (snd pair:) pairList
or maybe use curry or whatever. but i'd like my pair to not need to be unboxed!
is there not a way to not have to manually call fst and snd? are both of these functions typeclass methods by any chance? then we could write a generalized function that could work for any f = (:) or any kind of pair-like thingy. mind you i'm not sure to which extent it would keep the opacity of the type constructor (,).
especially, it's a bit like unboxing the Maybe type constructor: you can do it manually by pattern matching, but when you have the exact same issue but with IO, it's not possible anymore to unbox the underlying type
equally, i bet one could invent IO a b, in a way that you could not just get a and b, but you could somehow implement
opaqueBimap :: (i -> k i) -> f a b -> f (k a) (k b) -> f (k a) (k b)
with here of course f = (,), k = [] or List, and (i -> k i) = (:)