Cleanup combination accessing code

This commit is contained in:
2021-12-06 14:18:11 +00:00
parent 40195d033c
commit 766a1dda83
6 changed files with 98 additions and 112 deletions
+2 -2
View File
@@ -1,6 +1,6 @@
{-# LANGUAGE TemplateHaskell #-}
module SimpleTrie where
import Data.Map
import Data.Map.Strict
import Control.Lens
data Trie a b = Trie
{ _trieMVal :: Maybe b
@@ -22,5 +22,5 @@ insertInTrie (k:ks) x = trieChildren %~ insertWith f k (singletonTrie ks x)
f _ = insertInTrie ks x
lookupTrie :: Ord a => [a] -> Trie a b -> Maybe b
lookupTrie [] t = _trieMVal t
lookupTrie (k:ks) t = _trieChildren t !? k >>= lookupTrie ks
lookupTrie [] t = _trieMVal t