Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6163257
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T21:47:45+00:00 2026-05-23T21:47:45+00:00

The following pseudo-Scala yields an illegal cyclic reference error: trait GenT[A] trait T extends

  • 0

The following pseudo-Scala yields an “illegal cyclic reference” error:

trait GenT[A]
trait T extends GenT[T#A] {
  type A
}

Questions: Why is this illegal? Is there a fundamental problem with soundness, or is it a limitation of the Scala type system? Is there a work-around?

My intent is to create a trait T with a type member A that can be lifted on demand to a type parameter via the super-trait GenT[A]. One application might be the expression of constraints, for example

def foo[A, S1 <: GenT[A], S2 <: GenT[A]] ...

This could be used as if it were def foo[S1 <: T, S2 <:T] ... with the constraint that S1#A == S2#A.

If the technique were possible, it might also help for the question: How to specialize on a type projection in Scala?

Note: I could use GenT instead of T everywhere, but I’m trying to avoid that because it would cause lots of type parameters to spread across all my code “infectiously”.

The two questions below seem similar but are about a different type of cyclic reference:

  • Scala: working around the "illegal cyclic reference"
  • How to define a cyclic type definition?
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T21:47:45+00:00Added an answer on May 23, 2026 at 9:47 pm

    In your initial example you can break the cycle by introducing an auxiliary type inbetween GenT[A] and T,

    trait GenT[A]
    trait TAux { type A }
    trait T extends TAux with GenT[TAux#A]
    

    But from your motivating example I don’t think you need to go down this route. The constraint you’re after can be expressed directly using a refinement,

    trait T { type A }
    def foo[A0, S1 <: T { type A = A0 }, S2 <: T { type A = A0 }] ...
    

    Also bear in mind that you can surface a type member as a type parameter via a type alias,

    trait T { type A }
    type TParam[A0] = T { type A = A0 }
    def foo[A0, S1 <: TParam[A0], S2 <: TParam[A0]] ...
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Trying to figure out this pseudo code. The following is assumed.... I can only
My prototypical example is the following pseudo-code: var kind = ...; ... var type
I have the following pseudo-SQL schema: table flight id int primary key date timestamp
I want your suggestion on the following pseudo-code. Please suggest how could I improve
Could someone help me translate the following pseudo-code into code understood by Helicon Tech's
I want to build the following pseudo query Select a From APDU a where
I can drop a SqlServer Backup Device using SQL-DMO using the following pseudo-code: SQLDMO.SQLServer2
<xsl:template match=element[child]> The above works. What is the real syntax for the following pseudo-syntax?
Please consider the following fork() / SIGCHLD pseudo-code. // main program excerpt for (;;)
I have the following piece of pseudo-C/Java/C# code: int a[]= { 30, 20 };

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.