相关疑难解决方法(0)

测试一些必须无法编译的断言

问题

当我使用支持类型级编程的库时,我经常会发现自己编写如下的注释(来自Paul Snively在Strange Loop 2012中提供的示例):

// But these invalid sequences don't compile:
// isValid(_3 :: _1 :: _5 :: _8 :: _8 :: _2 :: _8 :: _6 :: _5 :: HNil)
// isValid(_3 :: _4 :: _5 :: _8 :: _8 :: _2 :: _8 :: _6 :: HNil)
Run Code Online (Sandbox Code Playgroud)

或者这,从一个例子中的无形资源库:

/**
 * If we wanted to confirm that the list uniquely contains `Foo` or any
 * subtype of `Foo`, we could …
Run Code Online (Sandbox Code Playgroud)

testing types scala type-level-computation shapeless

46
推荐指数
4
解决办法
3148
查看次数