From what I understand of KEEP-87, the objective i...
# arrow
c
From what I understand of KEEP-87, the objective is to give the possibility to make an object implement an interface from outside the object itself, allowing users to make classes they don't control implement behavior they want, such as
Comparator
and similar behavior interfaces (which are called ‘Type classes'? Please correct me if I'm wrong). It would also allow to implement a behavior in different ways, and choose which behavior is used when calling a function (with an explicit
with
parameter), which makes dependency injection trivial (possibility to implement patterns such as DAO with some nice syntax sugar).
✔️ 1
r
we have both those of those already working on Meta and if you are interested I’m gonna be presenting them tomorrow at the Chicago KUG Meetup
c
Yes, I signed up for the talk, I'm hyped 👍
One idea, that I'm not sure is good or not, would be to have a specific operator/function to ‘bind' (probably not the right word) an object with an extension implementation; for example:
class Thing(val a: String)
Copy code
interface Order<T> {
  operator fun compareTo(other: T): Int
}
fun test(o: Order<T>) = o.compareTo(o2)
extension class ThingOrder: Order<Thing> { ... }
Copy code
val thing: Thing = Thing("thing")
val thingOrder: ThingOrder = ThingOrder()
Copy code
val foo = thing + thingOrder
// You can call all functions from Thing on 'foo', and you can also call functions from 'ThingOrder'; basically it's a combination of both objects
test(foo) // This is legal, even though Thing doesn't implement Order, because this specific object has been combined with an Order implementation.
As I see it, this could remove the need for
with
parameters, which would make it possible to use these kind of interfaces in the standard library without having to change function declarations I guess someone must have already thought of doing something like that, especially with Unions coming with Meta, and I guess there was a reason why this wasn't added to the proposal... I'm curious to what it is. (I'm not posting this on the proposal itself out of fear of polluting the discussion, since I'm far from understanding all subtility of it... Please tell me if this is not the correct place either)
r
This is also implemented in meta
It's extension projections and replaces typeclasses restriction of one type arg
Also there is coherent implicits you can summon without actually making it a requirement in method args since there is a polymorphic function for given
For any expression position
c
Damn. I like how every wish/thing that sounds great is always answered by “well yeah, we have that”. Great project! I hope one day I'll know enough about it to not be surprised anymore ^^