Functional programming

Rustom Mody rustompmody at gmail.com
Mon Mar 3 14:48:00 CET 2014


On Monday, March 3, 2014 5:50:37 PM UTC+5:30, Chris Angelico wrote:
> On Mon, Mar 3, 2014 at 10:45 PM, Rustom Mody  wrote:
> > - cannot do a 'type-incorrect' expression like
> >>>> [1,2] + [[3,4],[5]]
> > [1, 2, [3, 4], [5]]

> What do you mean by "type-incorrect"? This is adding two lists and
> getting back a list. Seems perfectly correct to me.


Here's the behavior from an (old version of) haskell.

Unfortunately modern versions give a less helpful error message
'++' is list-append, '?' is the prompt

? [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...



More information about the Python-list mailing list