Provide instances of HasTrie for `Text`
ocharles opened this issue · comments
Ollie Charles commented
Avi Dessauer commented
I believe this is the correct instance, but memorizing on Text
or String
leads to massive memory consumption.
@conal Is this expected because a node is being created for every Char? Or am I just doing something wrong in this file.
-- taken from MemoTrie.hs
enum' :: (HasTrie a) => (a -> a') -> (a :->: b) -> [(a', b)]
enum' f = (fmap . first) f . enumerate
instance HasTrie T.Text where
newtype (T.Text :->: b) = TextTrie (String :->: b)
trie f = TextTrie (trie (f . T.pack))
untrie (TextTrie t) = untrie t . T.unpack
enumerate (TextTrie t) = enum' T.pack t