I'd like to implement an index structure as follows:
f :: [String] -> String -> Maybe Int
f haystack needle = Map.lookup needle m
where m = Map.fromAscList $ zip (sort haystack) [1..]
g :: String -> Maybe Int
g = f ["123", "456", "789", ......]
Every time I evaluate g str, the map m needs to be newly computed.
What's an elegant way to avoid that?
I feel like I'm missing some terminology here. What's the concept I'm looking for?