File tree 1 file changed +31
-0
lines changed 1 file changed +31
-0
lines changed Original file line number Diff line number Diff line change
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
+ }
You can’t perform that action at this time.
0 commit comments