Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Intersection.Aux[Int :: HNil, Int :: HNil, HNil] #562

Closed
aryairani opened this issue Mar 19, 2016 · 2 comments
Closed

Intersection.Aux[Int :: HNil, Int :: HNil, HNil] #562

aryairani opened this issue Mar 19, 2016 · 2 comments

Comments

@aryairani
Copy link
Contributor

There seems to be a problem with Intersection:

scala> implicitly[Intersection.Aux[Int :: HNil, Int :: HNil, Int :: HNil]]
res27: Intersection.Aux[Int :: HNil, Int :: HNil, Int :: HNil] = shapeless.ops.hlist$Intersection$$anon$58@342165b9

This correctly witnesses that { Int } ∩ { Int } = { Int }

scala> implicitly[Intersection.Aux[Int :: HNil, Int :: HNil, HNil]]
res25: Intersection.Aux[Int :: HNil, Int :: HNil, HNil] = shapeless.ops.hlist$LowPriorityIntersection$$anon$56@50fc9b74

This incorrectly witnesses that { Int } ∩ { Int } = ∅
😞

@aryairani
Copy link
Contributor Author

scala> reify { implicitly[Intersection.Aux[Int::HNil,Int::HNil,HNil]] }
res29: $r.intp.global.Expr[shapeless.ops.hlist.Intersection.Aux[shapeless.::[Int,shapeless.HNil],shapeless.::[Int,shapeless.HNil],shapeless.HNil]] = Expr[shapeless.ops.hlist.Intersection.Aux[shapeless.::[Int,shapeless.HNil],shapeless.::[Int,shapeless.HNil],shapeless.HNil]](Predef.implicitly[hlist.Intersection.Aux[::[Int, HNil], ::[Int, HNil], HNil]](hlist.this.Intersection.hlistIntersection1(hlist.this.Intersection.hnilIntersection)))

simplifies to

Intersection.hlistIntersection1(Intersection.hnilIntersection))
implicit def hnilIntersection[M <: HList]: Aux[HNil, M, HNil] =
  new Intersection[HNil, M] {
    type Out = HNil
    def apply(l: HNil): Out = HNil
  }

implicit def hlistIntersection1[H, T <: HList, M <: HList]
  (implicit i: Intersection[T, M]): Aux[H :: T, M, i.Out] =
    new Intersection[H :: T, M] {
      type Out = i.Out
      def apply(l: H :: T): Out = i(l.tail)
    }

Yes. hnilIntersection says ∅ ∩ M = ∅, which is good.
But hlistIntersection1 says (H :: T) ∩ M = T ∩ M (which is false if H ∈ M)
i.e. { H } ∩ M = ∅ ∩ M = ∅

@aryairani
Copy link
Contributor Author

There's an equivalent bug in Union:

import shapeless._, ops.hlist.Union
implicitly[Union.Aux[Int :: HNil, Int :: HNil, Int :: Int :: HNil]]

compiles as well, witnessing that { Int } ∪ { Int } = { Int, Int }
😭

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants