compiltime.constvalue [t]在Scala 3中的对面
如果我们有一个透明的内联def f(...):boolean = ...
,是否可以将f
的结果转换为true
代码>或false
类型,假设f
的结果是在编译时知道的吗?我想在隐式搜索中使用这些类型。
但是
given [A](using f(5) <:< true): MyTypeClass with ...
,问题是f(5)
是一个值,而不是类型。因此上述代码不会编译。
If we have a transparent inline def f(...): Boolean = ...
, is it possible to convert the result of f
to true
or false
types, assuming the result of f
is known at compile-time? I would like to use those types in an implicit search.
For example,
given [A](using f(5) <:< true): MyTypeClass with ...
However, the problem is that f(5)
is a value, not a type. So the above code won't compile.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我猜最接近的是
我们无法替换
(使用Xt&lt;:&lt; a)
用(使用TypeOf(f(f(5))。t&lt;:&lt; a)
因为路径依赖类型即使在Scala 3中也必须具有稳定的前缀。 -expression-in-scala“>如何获得Scala中的(静态)表达式的类型?
type注释通过推论表达式类型
Scala定义自定义类型 - 类型不匹配错误
I guess the closest is
Unfortunately we can't replace
(using x.T <:< A)
with(using TypeOf(f(5)).T <:< A)
because path-dependent types must have stable prefix even in Scala 3.How to get the (static) type of an expression in Scala?
type annotations overriden by inferred expression type
Scala Defining Custom Type - Type Mismatch Error