Skip to content

Commit 2e377ca

Browse files
committed
Fix scala#6088: add test
1 parent 881d6dd commit 2e377ca

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

tests/patmat/i6088.scala

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
/** Natural transformation. */
2+
trait ~>[F[_], G[_]] {
3+
def apply[A](fa: F[A]): G[A]
4+
}
5+
6+
/** Higher-kinded pattern functor typeclass. */
7+
trait HFunctor[H[f[_], i]] {
8+
def hmap[A[_], B[_]](nt: A ~> B): ([x] =>> H[A,x]) ~> ([x] =>> H[B,x])
9+
}
10+
11+
/** Some HK pattern functor. */
12+
enum ExprF[R[_],I] {
13+
case Const[R[_]](i: Int) extends ExprF[R,Int]
14+
case Neg[R[_]](l: R[Int]) extends ExprF[R,Int]
15+
case Eq[R[_]](l: R[Int], r: R[Int]) extends ExprF[R,Boolean]
16+
}
17+
18+
/** Companion. */
19+
object ExprF {
20+
given hfunctor as HFunctor[ExprF] {
21+
def hmap[A[_], B[_]](nt: A ~> B): ([x] =>> ExprF[A,x]) ~> ([x] =>> ExprF[B,x]) = {
22+
new ~>[[x] =>> ExprF[A,x], [x] =>> ExprF[B,x]] {
23+
def apply[I](fa: ExprF[A,I]): ExprF[B,I] = fa match {
24+
case Const(i) => Const(i)
25+
case Neg(l) => Neg(nt(l))
26+
case Eq(l, r) => Eq(nt(l), nt(r))
27+
}
28+
}
29+
}
30+
}
31+
}

0 commit comments

Comments
 (0)