Como você declara os valores de uma entrada de dicionário como mutável?
O Google produz muitos exemplos de adição e exclusão de entradas em um dicionário F # (ou outra coleção). Mas eu não vejo exemplos para o equivalente
myDict["Key"] = MyValue;
eu tentei
myDict.["Key"] <- MyValue
Eu também tentei declarar o Dicionário como
Dictionary<string, mutable string>
bem várias variantes sobre isso. No entanto, eu não bati na combinação correta ainda ... seé realmente possível em F #.
Editar: o código incorreto é:
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)
O erro que estou recebendo é:
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