我想用这个Monad折叠一个HList,但是 at the type-level
trait TypeMonad{
type Append[A,B] = A with B
type Identity = Any
}
因此,HList:“A :: B :: C :: HNil”将给出类型“A with B with C with Any”
如果我实现了HList,那很容易做到:
sealed trait HList {
type Fuse
}
final trait HCons[H,L<:HList] extends HList {
type Fuse = H with L#Fuse
}
final trait HNil extends Hlist {
type Fuse = Any
}
但是我不知道如何在无形环境中使用此功能
My use case is the following :
我需要通过约束有效参数来限制对某些类的隐式类使用例如:
trait Filter
trait IC1Filter extends Filter
trait IC2Filter extends Filter
(...)
implicit class IC1[T <: IC1Filter](val v : MyPrettyClass[T]){...}
implicit class IC2[T <: IC2Filter](val v : MyPrettyClass[T]){...}
(...)
例如,如果我有
class MC extends MyClass[IC1Filter with IC3Filter with IC4Filter with Any]
MC必须由隐式类IC1或IC3或IC4解析,但不能由IC2或IC5解析
我使用由“Filters”组成的HList来动态定义T参数 . 当创建所需的HList时,我需要聚合HList组件以便为隐式类生成可解析的过滤器
所以我需要例如:
IC1FIlter :: IC3Filter :: IC4Filter :: HNil
被转变为
IC1Filter with IC3Filter with IC4Filter with Any