Functional programming

Chris Angelico rosuav at gmail.com
Wed Mar 5 13:04:20 CET 2014


On Wed, Mar 5, 2014 at 10:28 PM, BartC <bc at freeuk.com> wrote:
> But I agree that in many cases, an initialised declaration *could* often be
> used to infer the likely type without too much trouble:
>
> var x=2     # integer
> var y=3.0   # real
> var z="A"   # probably, a C-style string pointer ('char*')
>
> (And since I'm working on such a language at the moment, I felt obliged to
> implement exactly this. And yes, with 10 minutes' effort, something like
> this was working, to prove my assertion.
>
> However it is not satisfactory, which is one reason why no well-established
> static language is likely to adopt such a feature. It is just too untidy,
> too ad-hoc and undisciplined, to say that usually you need to provide an
> exact type, but sometimes, in such and such an instance, you don't need to
> bother!)

C++ has something very like this, with the 'auto' keyword. It's not
particularly useful for the examples you give, but can be much more so
when you have templates, iterators, and so on - where the exact type
declaration might be a couple dozen characters of pure syntactic salt,
since you're initializing it to some function's return value.

ChrisA



More information about the Python-list mailing list