On Tue, Mar 4, 2014 at 12:48 AM, Rustom Mody <rustompm...@gmail.com> wrote: > ? [1,2] + [[3,4],[5]] > ERROR: Type error in application > *** expression : [1,2] + [[3,4],[5]] > *** term : [1,2] > *** type : [Int] > *** does not match : [[Int]] > > IOW [1,2,[3,4],[5]] > is a type-wise ill-formed expression just as in python > [[1,2]) > is syntax-wise ill-formed > > Is it worth having such a restriction? > Thats a different argument...
How do you know that [1,2] is a list that must contain nothing but integers? By extension, it's also a list that must contain positive integers less than three, so adding [5] violates that. And [] is a list that must contain nothing, ergo it can't be added to, although (since it contains nothing) it can be added to anything. Some languages do let you specify element types (Pike has an "array" type that can hold anything, or you can say "array(int)" to restrict it to integers; you could also say "array(int(1..2))" to specify what I said above, if you actually intend that), but without a declaration from the programmer, it's dangerous to assume there's an error. ChrisA -- https://mail.python.org/mailman/listinfo/python-list