0

There are Keyed and FunctorWithIndexed classes in keys and lens` libraries respectively.

Their member functions mapWithKey and imap seems to be similar, except that keys is formulated using type families, and lens uses functional dependencies.

When one should prefer one or another? Why lens doesn't use keys, is it because of type-inference? Are there some interesting history of development? As a library writer, should I write variants for both Keyed f and FunctorWithIndex i f containers?

phadej
  • 11,947
  • 41
  • 78

1 Answers1

2

From the keys package readme—

In practice this package is largely subsumed by the lens package, but it is maintained for now as it has much simpler dependencies.

R B
  • 1,109
  • 9
  • 13
  • Excellent question! The answer doesn't immediately occur to me. I'll have to sit and have a think, maybe work it out with a pencil. – R B Jul 28 '16 at 19:28
  • @phadej `Zip` looks [a lot like `Applicative`](http://stackoverflow.com/questions/36474647/haskell-depth-for-each-node-in-binary-tree-using-reader-monad/36480067#36480067) to me – Benjamin Hodgson Jul 28 '16 at 23:06
  • @BenjaminHodgson the `Zip` and `Applicative` for list do extremely different things. I proposed a laws to narrow done `Zip` implementatons: https://github.com/ekmett/keys/pull/15 – phadej Sep 29 '16 at 14:29