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 6608723
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T19:38:23+00:00 2026-05-25T19:38:23+00:00

With this piece of code: trait B[T] trait C[T] class A[T] extends B[A[C[T]]] I

  • 0

With this piece of code:

trait B[T]
trait C[T]
class A[T] extends B[A[C[T]]]

I get the following error:

error: class graph is not finitary because type parameter T is expansively recursive
       class A[T] extends B[A[C[T]]]
               ^

Can someone explain what the error message is about, why T is infinitely recursive and why the following code works?

class A[T] extends B[A[T]]
  • 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-25T19:38:24+00:00Added an answer on May 25, 2026 at 7:38 pm

    From the Scala 2.9 specification (note that this is in the Change Log as a change that was introduced in 2.4, so it’s not a “new restriction” in 2.9):

    The implementation of subtyping has been changed to prevent infinite
    recursions. Termination of subtyping is now ensured by a new
    restriction of class graphs to be finitary.

    Kennedy and Pierce explain why infinitary class graphs are a problem:

    Even disregarding subtyping, infinite closure presents a problem for
    language implementers, as they must take care not to create type
    representations for supertypes in an eager fashion, else non-
    termination is the result. For example, the .NET Common Language
    Runtime supports generic instantiation and generic inheritance in
    its intermediate language targeted by C. The class loader maintains a
    hash table of types currently loaded, and when loading a new type it
    will attempt to load its supertypes, add these to the table, and in
    turn load the type arguments involved in the supertype.

    Fortunately, as Kennedy and Pierce point out, there’s a convenient way to check whether a class graph is infinitary. I’m using their definitions throughout this answer.

    First I’ll make your type variables distinct for clarity:

    trait B[X]
    trait C[Y]
    class A[Z] extends B[A[C[Z]]]
    

    Next we construct the type parameter dependency graph using Kennedy and Pierce’s definition. The only declaration that’s going to add edges to the graph is the last one, for A. They give the following rules for building the graph:

    For each declaration C <X̄> <:: T and each subterm D<T̄> of T, if T_j = X_i add a non-expansive edge C#i → D#j; if X_i is a proper subterm of T_j add an expansive edgeC#i → D#j

    So first we look at Z and C[Z], which gives us a non-expansive edge from Z to Y. Next Z and A[C[Z]] gives us an expansive edge from Z to Z, and Z and B[A[C[Z]]] gives us an expansive edge from Z to X:

    Graph for the bad version

    I’ve indicated non-expansive edges with dashed arrows and expansive edges with solid ones. We have a cycle with an expansive edge, which is a problem:

    Infinitary class tables are characterized precisely by those graphs
    that contain a cycle with at least one expansive edge.

    This doesn’t happen for class A[Z] extends B[A[Z]], which has the following graph:

    Graph for the good version

    See the paper for a proof that a class table is infinitary iff it’s expansive.


    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This piece of code gives a syntax error at the colon of elif process.loop(i,
This piece of code used to work in MVC 1 but it does not
This piece of code is working fine with normal php: <?php function barber($type) {
Why this piece of code does not work? How to set the length of
Consider this piece of code: public abstract class Validator { protected Validator() { }
I have this piece of code: $(#faq).click(function () { var url = $.get(faq, {
Consider this piece of code: class A { void methodX() { // snip (1
Consider this piece of code: (defvar lst '(1 1)) (defmacro get-x (x lst) `(nth
I have this piece of code: <script language=javascript type=text/jscript> document.write(<img src='http://dm.leadgenesys.com/jpgp.lgt?en=P.........TP_Q=&amp;ur=' + escape(document.referrer) +
Running this piece of code will print null public class Weird { static class

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.