I want to create a map and a function to add item to that map.
This is what I did
let mymap = Map.empty
let myfunc nId nValue =
mymap = Map.add nId nValue ;;
But this produced following ErrorThis expression was expected to have type Map<'a,'b> but here has type Map<'c,'d> -> Map<'c,'d>
What did I do wrong?
Maps are immutable so you need to do let mutable mymap
.
Also, =
does comparison, you need <-
for assignment, which is why you got the error.
Something like
let mutable mymap = Map.empty
let myfunc nId nValue =
mymap <- Map.add nId nValue mymap;;
is what you want
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With