His take was “If I have an `x` and call `copy` on ...
# announcements
j
His take was “If I have an
x
and call
copy
on
x
, I expect to be able to call the same functions on the copy as I could on
x
.”
a
I'm with this take tbh
I understand your ask in the message before, but that's not how statically typed languages work. /shrug
j
I mean, Haskell and Scala both work that way. They’re statically typed.
a
I don't see a reason why kotlin isn't able to support it (it just hasn't been implemented yet)
j
(“That way” meaning they allow polymorphic copies.)
a
but I guess it can get complicated to implement it, for example:
Copy code
data class Foo<A>(val bar: A, val baz: A)

val fooString = Foo("hello", "world")
val fooInt = fooString.copy(bar = 5) //Does it work? What is <A> afterwards?
a
Ahh I don't have any experiences with those languages.
j
@Andreas Sinz Oh, interesting. Let me check what Scala does in that case. I’d assume a compile error of some sort.
Oh, it just unifies up to Any. Unsurprising, but bleh.
Copy code
scala> case class F[A](x: A, y: A)
defined class F

scala> val stringstringF = F("asdf", "zxcv")
stringstringF: F[String] = F(asdf,zxcv)

scala> val stringIntF = stringstringF.copy(x = 1)
stringIntF: F[Any] = F(1,zxcv)
Same behavior would work for Kotlin, though.
m
i still stand by that not matching my personal semantic definition of what a copy is. A copy of an X to me makes sense to also be an X. but that's just about the naming, i definitely agree that the functionality could be useful. just rename the original method from
copy
to
change
and 👍
cuz even the existing method ain't really a "copy"
j
We can rename “flatten” to “smoosh” while we’re at it. 🙂
m
perf
i'm sure
groovy
has some bizarre name for the operation