-
Notifications
You must be signed in to change notification settings - Fork 1.1k
compiletime.summonAll should be able to create constraints. #23233
-
Dilemma: I have a trait Foo[Q,R]
, and a tuple type Qs
. I need to use implicit search to summon a tuple of Tuple.Map[Qs, [Q] =>> Foo[Q, ?]
but also infer a tuple type Rs
corresponding to the R
of each Foo[Q, ?]
.
problem - If i use compiletime.summonAll
then there is no way to infer the output Rs as far as i can tell..
With traditional implicit search, this is easy:
opaque type Rows[X <: Tuple, +Y <: Tuple] = List[Queryable.Row[?, ?]] object Rows { given concatRows: [Q, R, Qs <: Tuple, Rs <: Tuple] => (x: Queryable.Row[Q, R]) => (xs: Rows[Qs, Rs]) => Rows[Q *: Qs, R *: Rs] = x :: xs given emptyRows: Rows[EmptyTuple, EmptyTuple] = Nil } given NamedTupleRow: [N <: Tuple, X <: Tuple, Y <: Tuple] => (rs: Rows[X, Y]) => Queryable.Row[NamedTuple[N, X], NamedTuple[N, Y]] = ???
i.e. given only a concrete tuple type X := (Expr[Int], Expr[String])
i can summon from context Rows[(Expr[Int], Expr[String]), (Int, String)]
and so infer the type Y := (Int, String)
.
I have not been able to find a way to do the same with just compiletime.summonAll
which i think is meant to be more efficient, the recursive implicit search approach is quite slow if there are say 200 elements in the tuple.
This recursive way is also necessary because match types can not handle large tuple sizes without blowing the stack - but this recursive implicit search can
Beta Was this translation helpful? Give feedback.