- import Control.Arrow
- data Trie a = Trie (Maybe a) [(Char, Trie a)] deriving Show
- find :: Trie a -> String -> Maybe a
- find (Trie v _) [] = v
- find (Trie v ts) (c:cs) = case lookup c ts of
- Just t -> find t cs
- Nothing -> Nothing
- instance Functor Trie where
- fmap f (Trie v ts) = Trie (fmap f v) (map (second (fmap f)) ts)