HiveBrain v1.2.0
Get Started
← Back to all entries
patternModerate

Why isn't the Swift programming language type inference more aggressive?

Submitted by: @import:stackexchange-cs··
0
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.