Re:The 4,000 Lines of Code Harvard Hopes Will Change Transla...
by yters on Wednesday August 01, 2018 @05:36PM
(#17667231)
Yes, strict translation requires solving the halting problem in the general case. E.g. translate this dynamically typed program into a statically typed one:
However, you can always write an interpreter in your desired language and avoid the halting problem. But, that's not really translation.
[ Parent
| on HN ]
Re:The 4,000 Lines of Code Harvard Hopes Will Change Transla...
by mistercow on Wednesday August 01, 2018 @09:59PM
(#17668716)
Can you explain to me what you think “translate this dynamically typed program into a statically typed one” means as concerns your fragment of pseudocode? And are you assuming that the “halts” function is a halting oracle?
Re:The 4,000 Lines of Code Harvard Hopes Will Change Transla...
by yters on Saturday August 04, 2018 @01:35PM
(#17687717)
It'd be better expressed as:
def a_func(input):
if eval(input) == 0:
return 1
else:
return "Nope"
To convert this to a statically typed program, the compiler has to determine what eval(input) returns at compile time, so it knows whether the function has a type signature of int or String.In general, this is impossible, since eval(input) may not halt.
Re:The 4,000 Lines of Code Harvard Hopes Will Change Transla...
by mistercow on Monday August 06, 2018 @01:00AM
(#17695180)
The way to type this would be: String -> Int | String (or, if the bottom type is part of your type system, String -> Int | String | Bottom)
And assuming that "eval" is typed as String -> Any, there should be no problem automatically inferring the type signature of this function. I certainly didn't have to solve the halting problem to generate that signature.
Re:The 4,000 Lines of Code Harvard Hopes Will Change Transla...
by yters on Tuesday August 07, 2018 @09:00AM
(#17706109)
In that case you are relying on generics or the equivalent of dynamic typing. My point is that if the language is just static typing without these extra facilities, you cannot translate without knowing the outcome at runtime.