मैं कल रात बहुत देर तक इस बेकार मुद्दे को समझने की कोशिश कर रहा था और मुझे डर है कि अगर मैं इसे बंद नहीं कर पाता हूं तो यह मेरी शाम को खाने जा रहा है मेरी छाती, तो यहाँ जाता है।अजीब व्यवहार केस वर्गों को विषम सूचियों में बदलने के लिए निरंतर सूची में बदलने की कोशिश कर रहा है
इस कम से कम संस्करण में मैं सिर्फ heterogeneous सूचियों में एक प्रकार वर्ग कि रिकर्सिवली मामले कक्षाओं में परिवर्तित कर देंगे परिभाषित करने हूँ:
import shapeless._
trait DeepHLister[R <: HList] extends DepFn1[R] { type Out <: HList }
trait LowPriorityDeepHLister {
type Aux[R <: HList, Out0 <: HList] = DeepHLister[R] { type Out = Out0 }
implicit def headNotCaseClassDeepHLister[H, T <: HList](implicit
dht: DeepHLister[T]
): Aux[H :: T, H :: dht.Out] = new DeepHLister[H :: T] {
type Out = H :: dht.Out
def apply(r: H :: T) = r.head :: dht(r.tail)
}
}
object DeepHLister extends LowPriorityDeepHLister {
implicit object hnilDeepHLister extends DeepHLister[HNil] {
type Out = HNil
def apply(r: HNil) = HNil
}
implicit def headCaseClassDeepHLister[H, R <: HList, T <: HList](implicit
gen: Generic.Aux[H, R],
dhh: DeepHLister[R],
dht: DeepHLister[T]
): Aux[H :: T, dhh.Out :: dht.Out] = new DeepHLister[H :: T] {
type Out = dhh.Out :: dht.Out
def apply(r: H :: T) = dhh(gen.to(r.head)) :: dht(r.tail)
}
def apply[R <: HList](implicit dh: DeepHLister[R]): Aux[R, dh.Out] = dh
}
के लिए इसे बाहर की कोशिश करते हैं! सबसे पहले हम कुछ मामले वर्गों की जरूरत है:
case class A(x: Int, y: String)
case class B(x: A, y: A)
case class C(b: B, a: A)
case class D(a: A, b: B)
और फिर (ध्यान दें कि मैं इस की खातिर नहीं एक पूरी तरह से पढ़ने योग्य नहीं गड़बड़ होने के लिए प्रकार वाक्य रचना को साफ कर दिया है):
scala> DeepHLister[A :: HNil]
res0: DeepHLister[A :: HNil]{
type Out = (Int :: String :: HNil) :: HNil
} = [email protected]
scala> DeepHLister[B :: HNil]
res1: DeepHLister[B :: HNil] {
type Out = (
(Int :: String :: HNil) :: (Int :: String :: HNil) :: HNil
) :: HNil
} = [email protected]
scala> DeepHLister[C :: HNil]
res2: DeepHLister[C :: HNil] {
type Out = (
((Int :: String :: HNil) :: (Int :: String :: HNil) :: HNil) ::
(Int :: String :: HNil) ::
HNil
) :: HNil
} = [email protected]
अब तक तो अच्छा। लेकिन तब:
scala> DeepHLister[D :: HNil]
res3: DeepHLister[D :: HNil] {
type Out = ((Int :: String :: HNil) :: B :: HNil) :: HNil
} = [email protected]
B
परिवर्तित नहीं हुआ। अगर हम -Xlog-implicits
पर बारी यह पिछले संदेश है:
<console>:25: this.DeepHLister.headCaseClassDeepHLister is not a valid implicit value for DeepHLister[shapeless.::[B,shapeless.HNil]] because:
hasMatchingSymbol reported error: diverging implicit expansion for type DeepHLister[this.Repr]
starting with method headNotCaseClassDeepHLister in trait LowPriorityDeepHLister
DeepHLister[D :: HNil]
^
कौन मुझ को समझ में headCaseClassDeepHLister
DeepHLister[B :: HNil]
ठीक उत्पन्न करने के लिए सक्षम होना चाहिए नहीं है, और यदि आप इसे सीधे पूछना होता है।
यह 2.10.4 और 2.11.2 दोनों पर होता है, और 2.0.0 रिलीज और मास्टर दोनों के साथ होता है। मुझे पूरा यकीन है कि यह एक बग होना है, लेकिन मैं इस संभावना से बाहर नहीं हूं कि मैं कुछ गलत कर रहा हूं। क्या किसी ने इससे पहले कुछ देखा है? क्या मेरे तर्क या Generic
पर कुछ प्रतिबंध के साथ कुछ गड़बड़ है, मुझे याद आ रही है?
ठीक है, सुनने के लिए धन्यवाद-शायद अब मैं एक किताब या कुछ पढ़ सकता हूं।
मुझे 'दीपलिस्टर [बी :: एचएनआईएल]' के साथ एक ही समस्या है। मैंने बस 5 मिनट पहले कोड कॉपी किया था, इसलिए मैं आगे की जांच करूंगा। – EECOLOR
यह व्हाइटबॉक्स मैक्रोज़ के साथ बहुत आसान होगा। –
@ GuillaumeMassé, ठीक है, निश्चित रूप से, लेकिन लक्ष्य मैक्रोज़ के उपयोग को बेकार द्वारा प्रदान किए गए कुछ मौलिक लोगों तक सीमित करना है। –