3

I'm looking for a way to derive fmapFirst and fmapSecond for bifunctors automatically. I would prefer a way to do it using the new Generic type class or using Data.Data, and without Template Haskell.

(Note that I already know that https://hackage.haskell.org/package/genifunctors-0.2.2.0/docs/Data-Generics-Genifunctors.html supports this with use of Template Haskell, I wish to know if Template Haskell can be avoided here)

AndrewC
  • 32,300
  • 7
  • 79
  • 115
tohava
  • 5,344
  • 1
  • 25
  • 47
  • Ask this question somewhere else. Questions about software recommendations, including library recommendations, are off-topic for SO. – Bakuriu Jan 18 '15 at 13:40
  • Your question doesn't typecheck in my brain. Haskell can automatically derive class instances (like `Eq`, or `Functor`) but never member functions. Those derivations are provided by the compiler (after using a suitable pragma like `DeriveFunctor`), never by a package. Or am I missing something? – Hans Lub Jan 18 '15 at 14:06
  • @HansLub Check this out: https://hackage.haskell.org/package/genifunctors-0.2.2.0/docs/Data-Generics-Genifunctors.html . I want something like this but without Template Haskell if possible. – tohava Jan 18 '15 at 14:07
  • Ah, I see. Template Haskell can 'generate' class instance declarartions; your use of the word "derive" made my head explode (but [you're not the only one](https://github.com/ekmett/bifunctors/issues/17). It is still not clear to me what you mean by 'derive' _outside_ the context of TH (as you want to avoid it) – Hans Lub Jan 18 '15 at 14:22
  • @HansLub - I mean that maybe it can be implemented generically by using properties of other generic programming oriented type classes (Data.Data and Generic) – tohava Jan 18 '15 at 14:23
  • 2
    [The generic-deriving package](https://hackage.haskell.org/package/generic-deriving) mentions a paper "A generic deriving mechanism for Haskell". Seems I will have to read it to prevent future brain explosions :-) – Hans Lub Jan 18 '15 at 14:31
  • 2
    This question can be edited to be on-topic for StackOverflow. Instead of asking for library recommendations, you can ask how to do something specific like, "I'm trying to derive `fmapFirst` and `fmapSecond` for bifunctors ...". It's helpful if you include what you have done so far or references to what you have found researching the problem. If a solution exists in a library, you might still get an answer referring to that library, but a good answer will also include how that library works. This should be more useful to you and more useful to future readers of StackOverflow. – Cirdec Jan 18 '15 at 19:13
  • The closest thing I know of is the derived `GFunctor` in [`Generics.Deriving.Functor`](https://hackage.haskell.org/package/generic-deriving-1.7.0/docs/Generics-Deriving-Functor.html), which solves both halves of the problem, leaving only a problem of juggling two type arguments. – Cirdec Jan 18 '15 at 19:17

0 Answers0