Marc Knaup
03/11/2021, 3:59 PM0 to a Double? Why 0.0?Paul Woitaschek
03/11/2021, 4:17 PMZach Klippenstein (he/him) [MOD]
03/11/2021, 4:20 PMMarc Knaup
03/11/2021, 4:21 PMInt when inferring a type.
@Zach Klippenstein (he/him) [MOD] actually Kotlin does.Paul Woitaschek
03/11/2021, 4:21 PMPaul Woitaschek
03/11/2021, 4:22 PMMarc Knaup
03/11/2021, 4:24 PMMarc Knaup
03/11/2021, 4:26 PM0 as universal unitless value.
In kotlin-css for example we could just write top = 0 instead of top = 0.px. But that’s another more advanced use case 😄Marc Knaup
03/11/2021, 6:31 PMnull is absence of value. 0 means 0.
Whether the div is 0 cm, px or rem away from the top doesn’t matter - it’s at the top. Hence it’s just 0 in CSS.
null would mean that the distance to top is not defined.Marc Knaup
03/11/2021, 6:39 PM0 can be converted in any type that supports it.
Just like we have in Kotlin already:
val int: Int = 0
val long: Long = 0 // implies 0L
if (int == long) // not allowed
The same way I could write
marginTop(0)
And allow that only for integer 0 and no other. The respective overload would resolve that properly and it only works if explicitly supported.Marc Knaup
03/11/2021, 6:46 PMkotlin-css and have written my own library. Properties are too inflexible, functions are much better here.
Zero could work the same way as Nothing? does. It only has one valid value. Only difference is that it is inferred as Int and Zero is only used explicitly.Marc Knaup
03/11/2021, 6:53 PMNothing?.
top(0)
With
fun top(value: Zero) {
top(LinearDimension("0")) // example
}
fun top(value: LinearDimension) { … }
0 is not a matrix and thus wouldn’t be an acceptable value. In that case you’d probably use Matrix.identity or alike.Marc Knaup
03/11/2021, 6:57 PMvax x = 0 // Int
vax x: Zero = 0 // ZeroMarc Knaup
03/11/2021, 6:57 PMvar x = 0 // Int
var x: Long = 0 // LongMarc Knaup
03/11/2021, 6:59 PMInt on the callee side - or totally inaccessible.Marc Knaup
03/11/2021, 7:01 PM0 on its own has no type. Otherwise you couldn’t assign it to Byte, Long, etc.Marc Knaup
03/11/2021, 7:02 PMclass LinearDimension(val value: String) {
companion object: ZeroConstructible {
override fun constructFromZero() = LinearDimension("0")
}
}
val foo: LinearDimension = 0Marc Knaup
03/11/2021, 7:03 PMMarc Knaup
03/11/2021, 7:07 PM0 specifically.
They have for IntegerLiteral, FloatLiteral, StringLiteral, ListLiteral (e.g. for Set construction) etc.Marc Knaup
03/11/2021, 7:07 PMMapLiteralMarc Knaup
03/11/2021, 7:08 PMExpressibleBy… by now
https://developer.apple.com/documentation/swift/expressiblebyintegerliteralMarc Knaup
03/11/2021, 7:08 PMMarc Knaup
03/11/2021, 7:09 PMZero would be already but still an acceptable trade-off for simpler CSS API.Marc Knaup
03/11/2021, 7:09 PMMarc Knaup
03/11/2021, 7:09 PM0 but not unitless 1 in CSS.Marc Knaup
03/11/2021, 7:09 PM1 needs a unit and cannot be implicitly pixel.Marc Knaup
03/11/2021, 7:10 PM0. For example in some calc(…) expressions.
So 0 should never implicitly become 0px.Marc Knaup
03/11/2021, 7:15 PM0 everywhere where it has the same meaning. Int, Byte, Long, Double and customs like css.LinearDimension.Marc Knaup
03/11/2021, 7:16 PM0 for Float and Double 😄Marc Knaup
03/11/2021, 7:19 PMcss.LinearDimension is about literal 0 not the Int value 0Marc Knaup
03/11/2021, 7:21 PMMarc Knaup
03/11/2021, 7:21 PMMarc Knaup
03/11/2021, 7:31 PM0 literal for floating-point values.Zach Klippenstein (he/him) [MOD]
03/11/2021, 7:53 PM