DataStructures.jl icon indicating copy to clipboard operation
DataStructures.jl copied to clipboard

cons does not create list of supertype

Open RichardRedding opened this issue 5 years ago • 1 comments
trafficstars

Apologies if this is due to my lack of understanding (I am relatively new to Julia) but it would be useful if the list constructor promoted subtypes in the same way as the base data collections seem to. In particular, below you can see that the element type of the LinkedList is "Any" whereas the element type of the Array is "Int64".

typeof(list(Int32(1), Int64(1))) typeof([Int32(1), Int64(1)])

RichardRedding avatar Aug 19 '20 10:08 RichardRedding

Yes, adding this would be a nice feature. Probably could be done by using the promote machinery to promote everything to a common type before construting the nil Change would need to be made around this point in the code https://github.com/JuliaCollections/DataStructures.jl/blob/e3c9c5698415e3c65d5a11255680c72e23927234/src/list.jl#L45

oxinabox avatar Aug 19 '20 20:08 oxinabox

Implemented in https://github.com/JuliaCollections/DataStructures.jl/pull/685

laborg avatar Oct 05 '23 04:10 laborg