1
: 약자로것은 내가 타입 별칭이 재귀 문법 설명 할 방법
type FieldValue = Seq[String] :+: String :+: Int :+: Long :+: CNil
type FieldLeaf = FieldValue :+: SubField :+: CNil
type SubField = Seq[Field]
type Field = (String, FieldLeaf)
을, 스칼라 컴파일러 (2.12.1)는 나에게 제공합니다
Error:(14, 25) illegal cyclic reference involving type FieldLeaf
type Field = (String, FieldLeaf)
PS 이 문맥은 재귀 문법을 구문 분석하여 fastparse입니다. (아래 @ OlivierBlanvillain의 대답에 응답)
편집
그 대답은 아름다움의 일이 정말하고 있었고, 난 내가 미래에 대한 기억거야, 찾고 있었던 정확하게.
그러나 다른 이유로,이 특정한 경우에 내가 대신 이러한 정의에 가야했다 : 또한case class Field(name: String, leaf: FieldLeaf)
sealed trait FieldLeaf
sealed trait FieldValue extends FieldLeaf
case class StringsFieldValue(value: Seq[String]) extends FieldValue
case class StringFieldValue(value: String) extends FieldValue
case class IntFieldValue(value: Int) extends FieldValue
case class LongFieldValue(value: Long) extends FieldValue
case class SubField(value: Seq[Field]) extends FieldLeaf
참조 : Instantiate types from recursive type grammar
:
는 작성할 수 있습니다? – Rumid
또한 어쩌면 구조가 있어야하는지, 어쩌면 설계상의 잘못인지 설명 할 수 있습니다. 'Type Subfield'를 없애고'Seq [Field]'를 사용하면 문제를 해결할 수 있지만 더 나은 해결책이있을 수 있습니다 (예 : 추가 클래스 생성). – Rumid
죄송합니다. 죄송합니다. 수입품을 포함시켜야합니다. 나는 간결하게 그들을 제외시켰다. 그것은 쉐이프리스입니다. – eirirlar