patternModerate
Why isn't the Swift programming language type inference more aggressive?
Viewed 0 times
swiftwhytheaggressiveprogrammingmoreinferencelanguagetypeisn
Problem
Couldn't the type inference in Apple's new programming language Swift had been done more aggressive? For instance why can't the return type of a function be deduced?
func sayHello(personName: String) -> String {
let greeting = "Hello, " + personName + "!"
return greeting
}Solution
I don't understand Swift's typing system yet, so I can only speculate, but I imagine that it's for the same reason that Scala doesn't have full type inference: nobody knows how to do it in a pragmatically viable way. The combination of parametric polymorphism and subtyping is deadly from the point of view of algorithmic complexity.
Context
StackExchange Computer Science Q#26389, answer score: 10
Revisions (0)
No revisions yet.