raulraja
05/21/2018, 11:37 AMraulraja
05/21/2018, 11:38 AMadd
to resolve it or the compiler fails.raulraja
05/21/2018, 11:38 AMTraverse#traverse
which requires Traverse<F>
and Applicative<G>
jacob
05/21/2018, 11:39 AMraulraja
05/21/2018, 11:43 AMtraverse
is now defined as:
fun <G, A, B> Kind<F, A>.traverse(AP: Applicative<G>, f: (A) -> Kind<G, B>): Kind<G, Kind<F, B>>
raulraja
05/21/2018, 11:43 AMfun <G, A, B> Kind<F, A>.traverse(f: (A) -> Kind<G, B>, with Applicative<G>): Kind<G, Kind<F, B>>
jacob
05/21/2018, 11:44 AMjacob
05/21/2018, 11:45 AMraulraja
05/21/2018, 11:45 AMlistOf(Option(1), Option(2)).traverse(::identity, Option.applicative())
they'd be able to just do:
import OptionApplicative
listOf(Option(1), Option(2)).traverse(::identity)
raulraja
05/21/2018, 11:45 AMwith
dependencyraulraja
05/21/2018, 11:45 AMraulraja
05/21/2018, 11:46 AMraulraja
05/21/2018, 11:46 AMjacob
05/21/2018, 11:47 AMjacob
05/21/2018, 11:48 AMjacob
05/21/2018, 11:48 AMraulraja
05/21/2018, 11:48 AMwith
and the call sites shows proof of implementation in its imported scope.jacob
05/21/2018, 11:52 AMraulraja
05/21/2018, 11:59 AMwith
or something similar is introduced in the compiler grammar similar to how varargs
is treated today with the following rules:
1. It has to be declared in arguments position
2. Naming the with
arguments is optional and can be ignored in the first impl.
3. with
arguments are implemented by the bytecode emitter as regular arguments in the same order they are declared so these functions can be invoked from Java explicitly providing the instances values.
4. The compiler will inject the with($ev1) { ... }
scoping blocks around the function bodies.
5. with
is currently a function in the std lib but what it does is just wrap a receiver block so a different function reference may be used:
fun <A, B> withEvidence(f: A.() -> B) : B = f($evA)
jacob
05/21/2018, 12:02 PMfun <A, B> fmap(f: (A) -> B, Fa: Kind<F, A> with Functor<F>): Kind<F, B>...
?jacob
05/21/2018, 12:03 PMfun <F, G, A, B> foo(f: (A) -> B, Fa: Kind<F, A>): Kind<G, B>
? how would I say which interfaces constrain G?raulraja
05/21/2018, 12:04 PMfun <A, B> Kind<F, A>.fmap(f: (A) -> B, with Functor<F>): Kind<F, B>
raulraja
05/21/2018, 12:05 PMfun <F, G, A, B> Kind<F, A>.foo(f: (A) -> B, with WhateverConstrain<G>): Kind<G, B>
jacob
05/21/2018, 12:05 PMraulraja
05/21/2018, 12:06 PMraulraja
05/21/2018, 12:06 PMfun User.saveAndLog(with UserRepository, SystemLogger) =
log(user.save())
raulraja
05/21/2018, 12:08 PMinterface Repository<A> {
fun A.save(): A
}
extension object UserRepository : Repository<User> {
fun User.save(): User = TODO()
}
raulraja
05/21/2018, 12:10 PMjacob
05/21/2018, 12:11 PMraulraja
05/21/2018, 12:12 PM