Skip to content

Commit e01ca04

Browse files
committed
Drop duplication in test
1 parent f7a5071 commit e01ca04

File tree

1 file changed

+0
-71
lines changed

1 file changed

+0
-71
lines changed

tests/run/HLists-nonvariant.scala

Lines changed: 0 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -76,74 +76,3 @@ object Test {
7676
println(at(zs1, Succ(Succ(Zero))))
7777
}
7878
}
79-
80-
object TestNonVariant {
81-
82-
type HNil = HNil.type
83-
type Zero = Zero.type
84-
85-
trait Concat[Xs <: HList, Ys <: HList, Zs <: HList] {
86-
def concat(xs: Xs, ys: Ys): Zs
87-
}
88-
89-
implicit def concatNil[Xs <: HList]: Concat[HNil, Xs, Xs] =
90-
new Concat[HNil, Xs, Xs] {
91-
def concat(fst: HNil, snd: Xs) = snd
92-
}
93-
94-
implicit def concatCons[X, Xs <: HList, Ys <: HList, Zs <: HList](
95-
implicit ev: Concat[Xs, Ys, Zs]
96-
): Concat[HCons[X, Xs], Ys, HCons[X, Zs]] =
97-
new Concat[HCons[X, Xs], Ys, HCons[X, Zs]] {
98-
def concat(xs: HCons[X, Xs], ys: Ys): HCons[X, Zs] =
99-
HCons(xs.hd, ev.concat(xs.tl, ys))
100-
}
101-
102-
def concat[Xs <: HList, Ys <: HList, Zs <: HList](xs: Xs, ys: Ys)(implicit ev: Concat[Xs, Ys, Zs]): Zs =
103-
ev.concat(xs, ys)
104-
105-
val xs = HCons(1, HCons("A", HNil))
106-
val ys = HCons(true, HNil)
107-
val zs = concat(xs, ys)
108-
val zs1: HCons[Int, HCons[String, HCons[Boolean, HNil]]] = zs
109-
110-
trait At[Xs <: HList, N <: Num] {
111-
type Out
112-
def at(xs: Xs, n: N): Out
113-
}
114-
115-
implicit def atZero[XZ, Xs <: HList]: At[HCons[XZ, Xs], Zero] { type Out = XZ } =
116-
new At[HCons[XZ, Xs], Zero] {
117-
type Out = XZ
118-
def at(xs: HCons[XZ, Xs], n: Zero) = xs.hd
119-
}
120-
121-
implicit def atSucc[XX, Xs <: HList, N <: Num](
122-
implicit ev: At[Xs, N]
123-
): At[HCons[XX, Xs], Succ[N]] { type Out = ev.Out } = new At[HCons[XX, Xs], Succ[N]] {
124-
type Out = ev.Out
125-
def at(xs: HCons[XX, Xs], n: Succ[N]): Out = ev.at(xs.tl, n.pred)
126-
}
127-
128-
def at[Xs <: HList, N <: Num](xs: Xs, n: N)(
129-
implicit ev: At[Xs, N]
130-
): ev.Out = ev.at(xs, n)
131-
132-
def main(args: Array[String]) = {
133-
val ys1 = HCons(1, HNil)
134-
println(at(ys1, Zero))
135-
136-
val ys2 = HCons(1, HCons("A", HNil))
137-
val y2 = at(ys2, Succ(Zero))
138-
println(at(ys2, Succ(Zero)))
139-
val ys3 = HCons(1, HCons("A", HCons(true, HNil)))
140-
println(at(ys3, Succ(Succ(Zero))))
141-
val ys4 = HCons(1, HCons("A", HCons(true, HCons(1.0, HNil))))
142-
println(at(ys4, Succ(Succ(Zero))))
143-
144-
println(zs1)
145-
println(at(zs1, Zero))
146-
println(at(zs1, Succ(Zero)))
147-
println(at(zs1, Succ(Succ(Zero))))
148-
}
149-
}

0 commit comments

Comments
 (0)