# Pattern match on erased HKT

**URL:** <https://users.scala-lang.org/t/pattern-match-on-erased-hkt/12202>\
**Category:** Question\
**Created:** [February 4, 2026, 10:24pm UTC](https://users.scala-lang.org/t/pattern-match-on-erased-hkt/12202 "2026-02-04T22:24:26Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![halotukozak](https://users.scala-lang.org/user_avatar/users.scala-lang.org/halotukozak/32/3308_2.png) [@halotukozak](https://users.scala-lang.org/u/halotukozak)\
**Post date:** [February 4, 2026, 10:24pm UTC](https://users.scala-lang.org/t/pattern-match-on-erased-hkt/12202/1 "2026-02-04T22:24:26Z")

</div>

How to extract Higher Kind Types from erased value?

It doesn’t work

```scala

type ExtractF[F[_], T] = F[T]

inline def check[X] =
  inline compiletime.erasedValue[X] match
    case _: ExtractF[tc, t] => 1
    case _ => 2

@main def main() =
  println(check[List[Int]]) //2
  println(check[Option[Int]]) //2

```

---

<div class="post-metadata">

**Author:** ![bishabosha](https://users.scala-lang.org/user_avatar/users.scala-lang.org/bishabosha/32/2567_2.png) [@bishabosha](https://users.scala-lang.org/u/bishabosha)\
**Post date:** [February 5, 2026, 9:13am UTC](https://users.scala-lang.org/t/pattern-match-on-erased-hkt/12202/2 "2026-02-05T09:13:40Z")

</div>

you can try remixing this with various combination of `compiletime.summonFrom` - e.g. i didnt think far enough ahead to how to do this with poly-kinds:

```auto
scala> trait HKMirror:
     | type TC[_]
     | type Arg
     | type Monotype = TC[Arg]
     | object HKMirror:
     | given [F[_], T] => (HKMirror { type TC = F; type Arg = T }) = new HKMirror { type TC = F; type Arg = T }
     |
// defined trait HKMirror
// defined object HKMirror

scala> type HK_TC[TC0[_]] = HKMirror { type TC = TC0 }
     | inline def check[X](using hkm: HKMirror { type Monotype = X }) =
     | inline compiletime.erasedValue[hkm.type] match
     | case _: HK_TC[tc] => 1
     | case _ => 2
     |
// defined alias type HK_TC[TC0[_$1]] = HKMirror{type TC = TC0}
def check[X](using hkm: HKMirror{type Monotype = X}): Int

scala> def main() =
     | println(check[List[Int]])
     | println(check[Option[Int]])
     |
def main(): Unit

scala> main()
1
1

```
