2017-10-16 74 views
0

我有以下一個項目,包含下面的代碼:無形錯誤:未發現:價值二

package ch.khinkali 

import shapeless.{::, HList, HNil} 


trait Second[L <: HList] { 
    type Out 

    def apply(value: L): Out 
} 

object Second { 
    type Aux[L <: HList, O] = Second[L] {type Out = O} 

    def apply[L <: HList](implicit inst: Second[L]): Aux[L, inst.Out] = 
    inst 
} 


object Main { 

    implicit def hlistSecond[A, B, Rest <: HList]: Second.Aux[A :: B :: Rest, B] = 
    new Second[A :: B :: Rest] { 
     type Out = B 

     def apply(value: A :: B :: Rest): B = 
     value.tail.head 
    } 

    def main(args: Array[String]): Unit = { 

    val second1 = Second[String :: Boolean :: Int :: HNil] 
    println(second1) 
    } 

} 

當我嘗試在Shell如下:

val second1 = Second[String :: Boolean :: Int :: HNil] 

它顯示錯誤消息:

error: not found: value Second 

我確實導入了包裝,如下圖所示:

enter image description here

我在做什麼錯?

回答

2

嘗試通配符進口:

import ch.khinkali._ 
import shapeless._ 
import ch.khinkali.Main._ 
+0

我已經得到了進一步的錯誤'的錯誤:錯號碼的類型參數::應該是1' –

+0

@zero_coding更新。 –

+0

再次出現錯誤'錯誤:無法找到參數inst的隱式值:ch.khinkali.Second [String :: Boolean :: Int :: shapeless.HNil]',\t雖然我確實有它的實例,您可以看到上面的代碼。 –