On Monday, March 3, 2014 7:53:01 PM UTC+5:30, Chris Angelico wrote: > On Tue, Mar 4, 2014 at 1:08 AM, Rustom Mody wrote: > >> 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. > > If 'integer-less-than-3' were a type then yes there would be this > > problem. More generally, if types could overlap then automatic > > type-inference is impossible
> First, does Haskell allow this? > ? [1,2,'foo'] ++ [3,4,'bar'] > If not, then find some other form of the expression that has the same > point, and substitute in for the below. And then: which of these is > permitted? Dunno what you mean/whats the 'point' > ? [1,2] ++ [3,4,'bar'] > ? [1,2,'foo'] ++ [3,4] > ? [] ++ [3,4,'bar'] > ? [1,2,'foo'] ++ [] > ? ([1,2,'foo'] ++ []) ++ [3,4,'bar'] > ? [1,2,'foo'] ++ ([] ++ [3,4,'bar']) > If it's okay to have heterogeneous lists, Its not. None of the above work If you want the (semantic) equivalent of python's [1,2,'foo'] you need to make an explicit union Int and String and its that *single* union type's elements that must go in. In all cases its always a single type. And so sum([1,2,[3]) is a syntax error unlike python where its a runtime error -- https://mail.python.org/mailman/listinfo/python-list