scala - Composing type-level functions with implicit witnesses -
i experimenting rather complex type-level calculations. there, have type tags (say, a
, b
, , c
), , functions working on them, represented implicit witnesses path-dependent result types:
class class b class c trait f1[t] { type result } trait f2[t] { type result } implicit object f1ofa extends f1[a] { type result = b } implicit object f2ofb extends f2[b] { type result = c } trait composed[t] { type result }
in course of calculations, when "implementing" composed
, need make use of fact can, given above code, in principle transform a
c
(in example, need composition, there's more things involved).
however, don't know how express composition, limited restriction implicits not transitively applied; following code fails "implicit not found":
implicit def composed1[x](implicit f2dotf1ofx: f2[f1[x]]): composed[x] = new composed[x] { type result = f2dotf1ofx.result } implicitly[composed[c]]
what tried write following:
implicit def composed2[x](implicit f1ofx: f1[x], f2oflast: f2[f1ofx.result]): composed[x] = new composed[x] { type result = f2oflast.result }
this of course failed because there used f1oflast
in same parameter list defined. if not implicit parameter, write
implicit def composed3a[x](f1ofx: f1[x])(f2oflast: f2[f1ofx.result]): composed[x] = new composed[x] { type result = f2oflast.result }
but not possible using 2 implicit parameter lists, since disallowed language.
in short: how can witness f2[f1[x]]
in above examples? if necessary, change way of writing type-level functions, have not yet found way express them.
you use type parameter , require f1ofx.result
that:
implicit def composed4[x, y](implicit f1ofx: f1[x] { type result = y }, f2oflast: f2[y]): composed[x] = new composed[x] { type result = f2oflast.result }
Comments
Post a Comment