E179: Match Type Scrutinee Cannot Be Higher-Kinded — match type의 스크루티니는 higher-kinded가 될 수 없음
E179: Match Type Scrutinee Cannot Be Higher-Kinded — match type의 스크루티니는 higher-kinded가 될 수 없음
match type 정의에서 스크루티니(매칭되는 타입)로 higher-kinded 타입을 사용하려 할 때 발생하는 에러예요.
본문
Scala 3의 match type은 스크루티니로 오직 proper type(종류 *의 타입)만 지원해요. higher-kinded 타입(타입 파라미터를 받는 타입, 예: F[_])은 스크루티니로 직접 사용할 수 없어요.
예시 (Example)
object Test:
type HigherKindedMatch[X[_]] = X match
case _ => Int
에러 (Error)
-- [E179] Type Error: example.scala:2:33 ---------------------------------------
2 | type HigherKindedMatch[X[_]] = X match
| ^
| the scrutinee of a match type cannot be higher-kinded
해결 방법 (Solution)
higher-kinded 타입을 타입 파라미터에 적용해서 proper type(종류 *)을 스크루티니로 사용하세요:
object Test:
type AppliedMatch[X[_], A] = X[A] match
case List[a] => Int
case Option[a] => String
또는 특정 적용된 타입에 대해 매칭하세요:
object Test:
type ConcreteMatch[X] = X match
case List[a] => Int
case Option[a] => String
더 알아보기
match type의 스크루티니는 proper type이어야 해요. higher-kinded 타입은 타입 파라미터에 적용해 proper type으로 만든 뒤 매칭하세요.