(yes, this is a stale post - but since I had the same problem, figure I'll add an explanation to DeeJay's code to help out the next guy...)
The heart of the matter is that F#'s containers are all done in a "functional" style. Basically, this means they are immutable. Instead of manipulating elements held in a single mutable map object, the Map.add function returns a new map comprised of the given map and the supplied new key/element pair.
While it would be easy enough to substitute System.Collections.Generic.Dictionary into your code, let's take a look at how to use the Map in a functional setting.
The inner loop in DeeJay's code above (modified slightly, below) uses "List.fold_left" to accumulate a map with the keys found from a supplied list and an associated boolean value. The fold_left function accumulates intermediate maps as it folds the list (starting at the left), then returns the final accumulated resulting Map. Since the inner nodes in each intermediate map are shared between each of these maps, the operation is fairly efficient in both time and space.
#light
type
dayofweek = Monday | Tuesday | Wednesday | Thursday | Friday | Saturday | Sunday
let
is_weekend_map = let isWeekend day = match day with
| Saturday | Sunday
-> true | _
-> false
[Monday;Tuesday;Wednesday;Thursday;Friday;Saturday;Sunday]
|> List.fold_left
(
fun acc key -> acc
|> Map.add key (isWeekend key) )
Map.empty
"It seems that perfection is reached, not when there is nothing left to add, but rather when nothing more can be taken away." -- Antoine de St. Exupéry