Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/scala/16.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Scala 方法返回大小为n的无形状列表_Scala_Scala 2.10_Shapeless - Fatal编程技术网

Scala 方法返回大小为n的无形状列表

Scala 方法返回大小为n的无形状列表,scala,scala-2.10,shapeless,Scala,Scala 2.10,Shapeless,是否可以使以下代码正常工作 def zeroTo[N <: Nat]:Sized[List[Int], N] = { new Sized[List[Int], N](List.iterate(0, toInt[N])(1+)) { type A = Int } } def zeroTo[N您只需添加一个上下文绑定: def zeroTo[N <: Nat: ToInt]: Sized[List[Int], N] = { new Sized[List[Int],

是否可以使以下代码正常工作

def zeroTo[N <: Nat]:Sized[List[Int], N] = {
  new Sized[List[Int], N](List.iterate(0, toInt[N])(1+)) {
    type A = Int
  }
}

def zeroTo[N您只需添加一个上下文绑定:

def zeroTo[N <: Nat: ToInt]: Sized[List[Int], N] = {
  new Sized[List[Int], N](List.iterate(0, toInt[N])(1+)) {
    type A = Int
  }
}
请注意,您可以使用
wrap
,大致相当于以下内容:

def zeroTo[N <: Nat: ToInt]: Sized[List[Int], N] =
  Sized.wrap(List.iterate(0, toInt[N])(1+))
def zeroTo[N
def zeroTo[N <: Nat: ToInt]: Sized[List[Int], N] =
  Sized.wrap(List.iterate(0, toInt[N])(1+))
def zeroTo[N <: Nat: ToInt]: Sized[List[Int], N] = {
  Sized.wrap[List[Int], N]( List.iterate( 0, toInt[N] )( 1+ ) )
}