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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T17:35:36+00:00 2026-06-14T17:35:36+00:00

I have a couple of functions whose only parameter requirement is that it has

  • 0

I have a couple of functions whose only parameter requirement is that it has some sort of collection that is also growable (i.e. it could be a Queue, List, PriorityQueue, etc.), so I attempted to create the following type alias:

type Frontier = Growable[Node] with TraversableLike[Node, Frontier]

to use with function definitions like so:

def apply(frontier: Frontier) = ???

but the type alias returns the error “Illegal cyclic reference involving type Frontier.” Is there any way to get around the illegal cyclic reference to use the type alias or something similar to it?

One solution is to use the following:

def apply[F <: Growable[Node] with TraversableLike[Node, F]](f: F) = ???

but this seems to add unnecessary verbosity when the function definition is doing seemingly the exact same thing as the type alias. The type is also used in other places, so a type alias would greatly increase readability.

  • 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-06-14T17:35:38+00:00Added an answer on June 14, 2026 at 5:35 pm

    From section 4.3 of the spec:

    The scope rules for definitions (§4) and type parameters (§4.6) make
    it possible that a type name appears in its own bound or in its
    right-hand side. However, it is a static error if a type alias refers
    recursively to the defined type constructor itself.

    So no, there’s no way to do this directly, but you can accomplish much the same thing with a type parameter on the type alias:

    type Frontier[F <: Frontier[F]] = Growable[Int] with TraversableLike[Int, F]
    

    Now you just write your apply like this:

    def apply[F < Frontier[F]](frontier: F) = ???
    

    Still a more little verbose than your hypothetical first version, but shorter than writing the whole thing out.

    You could also just use the wildcard shorthand for an existential type:

    type Frontier = Growable[Node] with TraversableLike[Node, _]
    

    Now your first apply will work as it is. You’re just saying that there has to be some type that fits that slot, but you don’t care what it is.

    In this case specifically, though, is there a reason you’re not using Traversable[Node] instead? It would accomplish practically the same thing, and isn’t parameterized on its representation type.

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

Sidebar

Related Questions

I have some code in a couple of different functions that looks something like
I have a couple of functions inside a class that essentially do the same
I have a C program with a couple of static functions that are not
I have a couple of functions that perform HTTP POST/GET/HEAD requests. For the POST
I have a couple functions like this: object obj.getChild(childIndex) int obj.numChildren() So I am
I have the following couple of C pre-processor macros for creating test functions: //
I have couple of dozen pieces of data that I need to save and
I have couple questions regarding some C++ rules. Why am I able to call
I have couple resource DLLs that I currently load when application starts using following
I have a PHP array that I'd like to duplicate but only copy elements

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.