如何TypeRepr在更高级的类型上正确地进行模式匹配?存在成功匹配类,但是当我尝试使用类型时,出现编译器错误unreducible application of higher-kinded type writetype.Foo to wildcard arguments
import scala.quoted.*
type Foo[X]
class Bar[X]
inline def writeType[T]: String = ${writeTypeImpl[T]}
def writeTypeImpl[T](using Type[T], Quotes): Expr[String] =
import quotes.reflect.*
val tpe = TypeRepr.of[T]
val s = tpe.asType match
//case '[Foo[?]] => "FooSuccess"
case '[Bar[?]] => "BarSuccess"
case _ => "Fail"
Expr(s)
Run Code Online (Sandbox Code Playgroud) 我正在尝试验证平面上的一些多边形is_valid,但我得到 Too few points in geometry component at or near point的多边形的 z 不是恒定的。
有没有办法验证这些其他多边形?
这是一个例子:
from shapely.geometry import Polygon
poly1 = Polygon([(0,0), (1,1), (1,0)])
print(poly1.is_valid)
# True
# z=1
poly2 = Polygon([(0,0,1), (1,1,1), (1,0,1)])
print(poly2.is_valid)
# True
# x=1
poly3 = Polygon([(1,0,0), (1,1,1), (1,1,0)])
print(poly3.is_valid)
# Too few points in geometry component at or near point 1 0 0
# False
Run Code Online (Sandbox Code Playgroud) 这是基本设置:
trait MyProduct[A, B](a: A, b: B)
class X
class Y
class XxY(x: X, y: Y) extends MyProduct(x,y)
Run Code Online (Sandbox Code Playgroud)
我正在尝试检查该MyProduct特征的论据。更具体地说,我想提取一些信息,例如字符串“x”和“y”,它们指示 的哪些字段XxY传递给MyProduct.
重要的是,我需要满足具有相同类型的多个字段的情况,例如class XxYxY(x: X, y1: Y, y2: Y) extends MyProduct3(x, y1, y2),因此从类型参数进行推理是不够的。
我想也许问题是我还没有找到一种方法来为条款extends本身添加符号。我可以找到ClassDeffor XxY,从中我可以提取parents并获取已经构造的类型MyProduct[X,Y]。我还查看了symbol.declarations封闭模块和XxY.<init>函数的 ,以查看是否有可用于查找参数的数据,但这些似乎都没有我正在寻找的信息。
查看封闭模块的树让我认为这些信息可能被删除,而是需要从源代码解析为文本,但我希望有人有更好的解决方案。
从评论中编辑:
作为输入,我有一个Type封闭对象/模块的实例。例如:
trait MyProduct[A, B](a: A, b: B)
class X
class Y
class XxY(x: X, y: Y) extends MyProduct(x,y)
Run Code Online (Sandbox Code Playgroud)
作为输出,我想要一些允许我检查 extends 子句中使用的特征的参数的东西。