Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on May 7th, 2012  |  syntax: None  |  size: 0.38 KB  |  hits: 13  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. import Control.Arrow
  2.  
  3. data Trie a = Trie (Maybe a) [(Char, Trie a)] deriving Show
  4.  
  5. find :: Trie a -> String -> Maybe a
  6. find (Trie v _)  []     = v
  7. find (Trie v ts) (c:cs) = case lookup c ts of
  8.                                Just t  -> find t cs
  9.                                Nothing -> Nothing
  10.  
  11. instance Functor Trie where
  12.     fmap f (Trie v ts) = Trie (fmap f v) (map (second (fmap f)) ts)