Automatic typing

JS js.mdnq at gmail.com
Sun Jun 30 23:38:19 PDT 2013


On Monday, 1 July 2013 at 04:19:51 UTC, Timon Gehr wrote:
> On 07/01/2013 05:44 AM, JS wrote:
>> On Monday, 1 July 2013 at 01:56:22 UTC, Timon Gehr wrote:
>>> ...
>>> The described strategy can easily result in non-termination, 
>>> and which
>>> template instantiations it performs can be non-obvious.
>>>
>>> auto foo(T)(T arg){
>>>    static if(is(T==int)) return 1.0;
>>>    else return 1;
>>> }
>>>
>>> void main(){
>>>    auto x;
>>>    x = 1;
>>>    x = foo(x);
>>> }
>>
>> Sorry,
>
> That's fine.
>
>> it only results in non-termination if you don't check all 
>> return
>> types out of a function.
>
> Why is this relevant? I was specifically responding to the 
> method lined out in the post I was answering. There have not 
> been any other attempts to formalize the proposal so far.
>
>> It is a rather easy case to handle by just
>> following all the return types and choosing the largest one.
>
> That neither handles the above case in a sensible way nor is it 
> a solution for the general issue. (Hint: D's type system is 
> Turing complete.)
>
>> No big deal...  any other tries?
>
> That's not how it goes. The proposed inference method has to be 
> completely specified for all instances, not only for those 
> instances that I can be bothered to provide to you as 
> counterexamples.

well duh, but it is quite a simple mathematical problem and your 
counter-example is not one at all.

For a statically typed language all types must be known at 
compile time... so you can't come up with any valid 
counter-example. Just because you come up with some convoluted 
example that seems to break the algorithm does not prove anything.

Do you agree that a function's return type must be known at 
compile time in a statically typed language? If not then we have 
nothing more to discuss... (Just because you allow a function to 
be compile time polymorphic doesn't change anything because each 
type that a function can possibly return must be known)


More information about the Digitalmars-d mailing list