Talk:Key-value apply

Add topic
From HaskellWiki

Initial problem context[edit]

This function actually occurred in the definition of a larger utility. It has the type

decode :: (Eq k) => [([k],[v])] -> [k] -> [v]

This takes a large input, searches the lookup table for the longest possible matching key, and returns the corresponding value. It then processes the rest of the input the same way.

The apply function on the content page occurs because the case actually transforms the [([k],[v])] into a tree to facilitate faster searching.

The Data.Map module does the exact same thing - but it's already implemented for you!

Is a function like decode already out there somewhere?

Possibly, if you take the [k] as the keys in the map implementation. (I haven't had this exact case in my use of Data.Map so far) BrettGiles 18:39, 16 February 2007 (UTC)