3 ms·
>Type inference has spread everywhere that the old argument of having to repeat your types doesn't hold anymore. Indeed. I find one of the most elegant recent
by dahauns 9y ago
>Type inference has spread everywhere that the old argument of having to repeat your types doesn't hold anymore.
Indeed. I find one of the most elegant recent examples is this snippet in Kotlin (yes, this is fully and statically typed):
https://kotlinlang.org/docs/reference/type-safe-builders.html https://kotlinlang.org/docs/reference/type-safe-builders.htm...
import com.example.html.*
fun result(args: Array<String>) =
html {
head {
title {+"XML encoding with Kotlin"}
}
body {
h1 {+"XML encoding with Kotlin"}
p {+"this format can be used as an alternative markup to XML"}
// an element with attributes and text content
a(href = "http://kotlinlang.org") {+"Kotlin"}
// mixed content
p {
+"This is some"
b {+"mixed"}
+"text. For more see the"
a(href = "http://kotlinlang.org") {+"Kotlin"}
+"project"
}
p {+"some text"}
// content generated by
p {
for (arg in args)
+arg
}
}
}