Scenario 1
let map = Dictionary<string,obj>() map.Add("1",10) map.Add("2",10L) map.Add("3","10")
It matches thin
Scenario 2
let map = Dictionary<string,(unit -> obj)>() map.Add("1",fun() -> 10) map.Add("2",fun() -> 10L) map.Add("3",fun() -> "10")
Here the compiler says that it excluded obj, but detected an int when it occurs 10
Scenario 3
let map = Dictionary<string,(unit -> 'a)>() map.Add("1",fun() -> 10) map.Add("2",fun() -> 10L) map.Add("3",fun() -> "10")
Here, the compiler accepts the first entry, but it causes a to be constrained by int, which is why the next two entries fail because they are not int
1st question: why does it compile in scenario 1 when it is not in scenario 2?
2nd question: Is there a way to prevent the 'restriction in scenario 3, or is there a specific template that can be used to include various types in the F # set (types of functions similar to this example)?
The only thing for which the values ββ(obj / 'a) should be used is the argument for println "%A" , which I do not see why this cannot be.
source share