glguy / tries

BSD 3-Clause "New" or "Revised" License
11 stars 8 forks source link

Support DerivingVia #32

Closed treeowl closed 2 years ago

treeowl commented 2 years ago

OrdKey seems pretty much tailor made for DerivingVia, and it would be possible to produce similar newtypes for tries implemented using IntMap, HashMap, etc. However, it's not actually possible to use DerivingVia to derive TrieKey. Ugh. The problem is the usual one of traversals. Since we control the types of the internals, we can work around that in a somewhat well known but rarely used way:

trieTraverse :: (Applicative f, Coercible (Trie k b) r) => (a -> f b) -> Trie k a -> f r
gtrieTraverse  :: (Applicative m, Coercible (GTrie f b) r) => (a -> m b) -> GTrie f a -> m r

With these method types, and similar ones for trieTraverseWithKey, trieTraverseMaybeWithKey, etc., we should be able to unlock the convenience for users.

treeowl commented 2 years ago

Fixed in #34.