Unless you are looking for help with homework, there are many different implementations of tries on hackage:
http://hackage.haskell.org/packages/archive/pkg-list.html (search for 'trie' there)
Tries take a lot of code to implement, so don't expect people here to provide full implementations - we can only give some clues. So we need to know which problems you face, so we can help you to move forward.
A general tip is to start top-to-bottom development using where
, deconstruction of arguments and putting undefined
instead of yet undeveloped parts:
Step 1:
trieInsert (keyH : keyT) value (TrieNode oldValue oldChars) = undefined
Step 2:
Then think about some simplest 'base' cases:
trieInsert [] value (TrieNode _ oldChildren) = TrieNode (Just value) oldChildren
trieInsert (keyH : keyT) value (TrieNode oldValue oldChars) = undefined
In this example, the first line reads 'if we add an empty key, then the value must be replaced at the root, and child nodes must be left as they are'. The second line reads: 'if we add a non-empty key, then ...'
Step 3:
trieInsert [] value (TrieNode _ oldChildren) = TrieNode (Just value) oldChildren
trieInsert (keyH : keyT) value (TrieNode oldValue oldChars) = TrieNode oldValue newChildren where
newChildren = undefined
The second line now reads: 'if we add a non-empty key, then we leave oldValue as is and modify children somehow'.
Then in step 4 elaborate newChildren somehow et cetera