Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #67654
| From | "BartC" <bc@freeuk.com> |
|---|---|
| Newsgroups | comp.lang.python |
| References | <B512F079-4F01-4865-BEF3-07DF94F21832@gmail.com><mailman.7612.1393810048.18130.python-list@python.org><4c7dbc57-eef9-4582-aecd-aac13a39b45f@googlegroups.com><mailman.7633.1393849247.18130.python-list@python.org><3b54a279-03a1-4a81-a428-ecad6eb16036@googlegroups.com><mailman.7641.1393855219.18130.python-list@python.org><216bb5f4-32c4-4f86-a9f4-1b0dd37a2a81@googlegroups.com><mailman.7644.1393856584.18130.python-list@python.org><0129a5b9-b85f-4ad5-b5e2-bfb2a48041d5@googlegroups.com><mailman.7647.1393858917.18130.python-list@python.org> <5314bb96$0$29985$c3e8da3$5496439d@news.astraweb.com> |
| Subject | Re: Functional programming |
| Message-ID | <TehRu.7$8R3.4@fx30.am4> (permalink) |
| Organization | virginmedia.com |
| Date | 2014-03-04 09:41 +0000 |
"Steven D'Aprano" <steve+comp.lang.python@pearwood.info> wrote in message news:5314bb96$0$29985$c3e8da3$5496439d@news.astraweb.com... > Think about the sort of type declarations you have to do in (say) Pascal, > and consider how stupid the compiler must be: > > function add_one(x: integer):integer; > begin > add_one := x+1; > end; > > Given that x is an integer, and that you add 1 (also an integer) to it, > is it really necessary to tell the compiler that add_one returns an > integer? What else could the output type be? > > This was state of the art back in 1970, but these days, if the compiler > cannot *at least* infer the type of the return result of a function given > the argument types, the static type system is too dumb to bother with. To me that is perfectly reasonable. This kind of language, while it allows expressions of mixed numeric types, treats each kind of number type as different: integer and real, even signed and unsigned integer, and there might be short, medium and long versions of each! And Pascal has an unlimited number of scalar types too. The compiler could make a guess at what the intended result might be, based on a hundred add_one:= assignments, all with a slightly different type on the right-hand-side, and perhaps choose a type that encompasses all the possibilities (although it might erroneously decide the result is real, based on one of those hundred, and use floating point for all of them). But then someone edits the code, and this time the guess will be different! For a static language such as this, type-discipline is important. And even if the compiler gets it right, a human reading the code would have trouble determining the return type, except in trivial examples like this. Putting in an explicit return type is the simplest way to go. -- Bartc
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Re: Functional programming Ned Batchelder <ned@nedbatchelder.com> - 2014-03-02 20:27 -0500
Re: Functional programming Rustom Mody <rustompmody@gmail.com> - 2014-03-03 03:45 -0800
Re: Functional programming Chris Angelico <rosuav@gmail.com> - 2014-03-03 23:20 +1100
Re: Functional programming Rustom Mody <rustompmody@gmail.com> - 2014-03-03 05:48 -0800
Re: Functional programming Rustom Mody <rustompmody@gmail.com> - 2014-03-03 05:51 -0800
Re: Functional programming Chris Angelico <rosuav@gmail.com> - 2014-03-04 01:00 +1100
Re: Functional programming Rustom Mody <rustompmody@gmail.com> - 2014-03-03 06:08 -0800
Re: Functional programming Chris Angelico <rosuav@gmail.com> - 2014-03-04 01:23 +1100
Re: Functional programming Rustom Mody <rustompmody@gmail.com> - 2014-03-03 06:38 -0800
Re: Functional programming Chris Angelico <rosuav@gmail.com> - 2014-03-04 02:01 +1100
Re: Functional programming Rustom Mody <rustompmody@gmail.com> - 2014-03-03 07:28 -0800
Re: Functional programming Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2014-03-03 17:27 +0000
Re: Functional programming Chris Angelico <rosuav@gmail.com> - 2014-03-04 05:37 +1100
Re: Functional programming Steven D'Aprano <steve@pearwood.info> - 2014-03-04 05:35 +0000
Re: Functional programming Rustom Mody <rustompmody@gmail.com> - 2014-03-03 21:59 -0800
Re: Functional programming Chris Angelico <rosuav@gmail.com> - 2014-03-04 17:04 +1100
Re: Functional programming Rustom Mody <rustompmody@gmail.com> - 2014-03-03 22:20 -0800
Re: Functional programming Steven D'Aprano <steve@pearwood.info> - 2014-03-04 08:56 +0000
Re: Functional programming Antoon Pardon <antoon.pardon@rece.vub.ac.be> - 2014-03-04 11:56 +0100
Re: Functional programming Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2014-03-04 11:47 +0000
Re: Functional programming Chris Angelico <rosuav@gmail.com> - 2014-03-05 00:01 +1100
OT Sine Rule [was Re: Functional programming] Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2014-03-04 14:25 +0000
Re: OT Sine Rule [was Re: Functional programming] Tim Chase <python.list@tim.thechases.com> - 2014-03-04 08:37 -0600
Re: OT Sine Rule [was Re: Functional programming] Mark Lawrence <breamoreboy@yahoo.co.uk> - 2014-03-04 14:42 +0000
Re: OT Sine Rule [was Re: Functional programming] Chris Angelico <rosuav@gmail.com> - 2014-03-05 02:06 +1100
Re: OT Sine Rule [was Re: Functional programming] Tim Chase <python.list@tim.thechases.com> - 2014-03-04 09:21 -0600
Re: Functional programming Antoon Pardon <antoon.pardon@rece.vub.ac.be> - 2014-03-05 09:59 +0100
Re: Functional programming Marko Rauhamaa <marko@pacujo.net> - 2014-03-04 21:49 +0200
Re: Functional programming Chris Angelico <rosuav@gmail.com> - 2014-03-05 07:01 +1100
Re: Functional programming Marko Rauhamaa <marko@pacujo.net> - 2014-03-04 22:50 +0200
Re: Functional programming Chris Angelico <rosuav@gmail.com> - 2014-03-05 08:06 +1100
Re: Functional programming Marko Rauhamaa <marko@pacujo.net> - 2014-03-04 23:21 +0200
Re: Functional programming Chris Angelico <rosuav@gmail.com> - 2014-03-05 08:26 +1100
Re: Functional programming Marko Rauhamaa <marko@pacujo.net> - 2014-03-04 23:43 +0200
Re: Functional programming Chris Angelico <rosuav@gmail.com> - 2014-03-05 08:52 +1100
Re: Functional programming Gregory Ewing <greg.ewing@canterbury.ac.nz> - 2014-03-05 12:57 +1300
Re: Functional programming Marko Rauhamaa <marko@pacujo.net> - 2014-03-05 02:11 +0200
Re: Functional programming "BartC" <bc@freeuk.com> - 2014-03-04 13:30 +0000
Re: Functional programming Chris Angelico <rosuav@gmail.com> - 2014-03-05 00:47 +1100
Re: Functional programming Mark Lawrence <breamoreboy@yahoo.co.uk> - 2014-03-04 14:05 +0000
Re: Functional programming Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2014-03-04 14:55 +0000
Re: Functional programming Chris Angelico <rosuav@gmail.com> - 2014-03-05 02:13 +1100
Re: Functional programming MRAB <python@mrabarnett.plus.com> - 2014-03-04 17:07 +0000
Re: Functional programming Chris Angelico <rosuav@gmail.com> - 2014-03-05 01:17 +1100
Re: Functional programming Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2014-03-04 15:18 +0000
Re: Functional programming Chris Angelico <rosuav@gmail.com> - 2014-03-05 02:28 +1100
Re: Functional programming Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2014-03-04 15:45 +0000
Re: Functional programming Chris Angelico <rosuav@gmail.com> - 2014-03-05 03:04 +1100
Re: Functional programming Antoon Pardon <antoon.pardon@rece.vub.ac.be> - 2014-03-05 10:09 +0100
Re: Functional programming "BartC" <bc@freeuk.com> - 2014-03-05 11:28 +0000
Re: Functional programming Chris Angelico <rosuav@gmail.com> - 2014-03-05 23:04 +1100
Re: Functional programming Marko Rauhamaa <marko@pacujo.net> - 2014-03-05 14:11 +0200
Re: Functional programming Gregory Ewing <greg.ewing@canterbury.ac.nz> - 2014-03-04 11:06 +1300
Re: Functional programming Ben Finney <ben+python@benfinney.id.au> - 2014-03-04 09:31 +1100
Re: Functional programming Grant Edwards <invalid@invalid.invalid> - 2014-03-04 14:59 +0000
Re: Functional programming Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2014-03-04 15:22 +0000
Re: Functional programming Chris Angelico <rosuav@gmail.com> - 2014-03-04 09:42 +1100
Re: Functional programming Ben Finney <ben+python@benfinney.id.au> - 2014-03-04 10:52 +1100
Re: Functional programming "BartC" <bc@freeuk.com> - 2014-03-04 09:41 +0000
Re: Functional programming 88888 Dihedral <dihedral88888@gmail.com> - 2014-03-03 16:35 -0800
csiph-web