¿Cómo declara que los valores de una entrada de diccionario son mutables?
Google ofrece muchos ejemplos de cómo agregar y eliminar entradas en un diccionario F # (u otra colección). Pero no veo ejemplos equivalentes a
myDict["Key"] = MyValue;
He intentado
myDict.["Key"] <- MyValue
También he intentado declarar el Diccionario como
Dictionary<string, mutable string>
También varias variantes en esto. Sin embargo, todavía no he encontrado la combinación correcta ... sies en realidad es posible en F #.
Edición: El código ofensivo es:
type Config(?fileName : string) =
let fileName = defaultArg fileName @"C:\path\myConfigs.ini"
static let settings =
dict[ "Setting1", "1";
"Setting2", "2";
"Debug", "0";
"State", "Disarray";]
let settingRegex = new Regex(@"\s*(?<key>([^;#=]*[^;#= ]))\s*=\s*(?<value>([^;#]*[^;# ]))")
do File.ReadAllLines(fileName)
|> Seq.map(fun line -> settingRegex.Match(line))
|> Seq.filter(fun mtch -> mtch.Success)
|> Seq.iter(fun mtch -> settings.[mtch.Groups.Item("key").Value] <- mtch.Groups.Item("value").Value)
El error que estoy recibiendo es:
System.NotSupportedException: This value may not be mutated
at [email protected]_Item(K key, V value)
at <StartupCode$FSI_0036>[email protected](Match mtch)
at Microsoft.FSharp.Collections.SeqModule.iter[T](FastFunc`2 action, IEnumerable`1 sequence)
at FSI_0036.Utilities.Config..ctor(Option`1 fileName)
at <StartupCode$FSI_0041>.$FSI_0041.main@()
stopped due to error