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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T18:31:41+00:00 2026-05-26T18:31:41+00:00

I am looking for recommendations of providing a class manifest in an array instantiation.

  • 0

I am looking for recommendations of providing a class manifest in an array instantiation. I have refactored this code (which compiles fine):

trait Ref[A]
trait Struct[A] {
  val arr = new Array[Ref[A]](1)
}

to this:

trait Ref[S <: Sys[S], A]
trait Sys[Self <: Sys[Self]] {
  type R[A] <: Ref[Self, A]
}

trait Struct[S <: Sys[S], A] {
  val arr = new Array[S#R[A]](1)
}

This fails with message "cannot find class manifest for element type S#R[A]"

So how would I solve this?

  • 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-26T18:31:42+00:00Added an answer on May 26, 2026 at 6:31 pm

    Your problem is that Array being invariant in its type parameter, requires a precise type argument. Your definition of type R in Sys is only providing an upper bound.

    You can fix the problem at the definition site by replacing the upper bound on R with an equality,

    trait Ref[S <: Sys[S], A]
    trait Sys[Self <: Sys[Self]] {
      type R[A] = Ref[Self, A]        // '=' not '<:'
    }
    
    trait Struct[S <: Sys[S], A] {
      val arr = new Array[S#R[A]](1)  // OK
    }
    

    Alternatively, if you’d prefer to leave R[A] open in Sys you can specify the equality constraint at the use site via a refinement, like so,

    trait Ref[S <: Sys[S], A]
    trait Sys[Self <: Sys[Self]] {
      type R[A] <: Ref[Self, A]       // Back to an upper bound
    }
    
    trait Struct[S <: Sys[S] { type R[A] = Ref[S, A] }, A] {
    //                       ^^^^^^^^^^^^^^^^^^^^^^^^^
    //                       Assert the equality via a refinement
      val arr = new Array[S#R[A]](1)  // OK
    }
    

    If you can’t pin down type R in either of these ways, then you have no option but to provide the ClassManifest explicitly yourself,

    trait Ref[S <: Sys[S], A]
    trait Sys[Self <: Sys[Self]] {
      type R[A] <: Ref[Self, A]
    }
    
    trait Struct[S <: Sys[S], A] {
      implicit val rM : ClassManifest[S#R[A]] // Provided manifest later ...
      val arr = new Array[S#R[A]](1)  // OK 
    }
    
    class SomeSys extends Sys[SomeSys] {
      type R[A] = Ref[SomeSys, A]
    }
    
    val s = new Struct[SomeSys, Int] {
      val rM = implicitly[ClassManifest[SomeSys#R[Int]]]
      //                                ^^^^^^^^^^^^^^
      //                                Precise type known here
    }
    

    Which of these to pick depends very much on your larger context.

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

Sidebar

Related Questions

I am looking for recommendations on using VIM as an IDE. I generally code
Looking to do a bit of refactoring... Using NHibernate I have this query currently
Looking for recommendations for a control which make can do spell checking for various
I have written c# code which utilizes the HtmlAgilityPack library in order to scrape
Quick question, looking for some recommendations. I have a site that will be requesting
We have some code that must access low level windows XP os calls which
Does anyone have experience testing Android apps on various devices? I'm looking for recommendations
I'm looking for tools and recommendations on how to manage binaries artifacts which together
I’m looking for recommendations and best practices for applying signed assemblies in an organization
I'm looking for recommendations for a Wiki that can be deployed on Heroku.

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.