Hey, cannot search in the forum apparently, please excuse if this has been asked before.
In Nim, this compiles:
import tables
var table: Table[string, seq[int]]
table["foo"] = @[]
The compiler determines that the sequence being assigned to the “foo” key cannot be of any other type than seq[int]
, so it infers it and moves on.
However, as we know, the equivalent in Crystal does not compile:
hash = {} of String => Array(Int)
hash["foo"] = [] # Error: for empty arrays use '[] of ElementType'
Is there a fundamental reason for this?