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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T00:43:53+00:00 2026-06-10T00:43:53+00:00

I want to take this pattern: def accept[T](a: RList[T]) = true def accept[T, V](a:

  • 0

I want to take this pattern:

 def accept[T](a: RList[T]) = true
 def accept[T, V](a: RList[T], b: RList[V])(implicit ev: a.S =:= b.S) = true
 def accept[T, V, Q](a: RList[T], b: RList[V], c: RList[Q])(implicit ev: a.S =:= b.S, ev2: b.S =:= c.S) = true

but have it accept a KList, instead of manually overriding for all arities. Basically I want to say, “Take any number of RLists, that have the same S member type”

RList is a trait, that contains a type S. (For more background on an RList and why I’m doing this, see: Constrain function based on origin (Path Dependent type? Type Generation?))

  • 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-10T00:43:54+00:00Added an answer on June 10, 2026 at 12:43 am

    It looks like what you are doing is just trying to get the compiler to check that the types agree, since your methods ALWAYS return true.

    Can you perhaps, instead of making methods which accept an arbitrary number of these, accept a “List of RLists” which is guaranteed to have S all matching?

    Here is how such a list might be constructed:

    package rl {
    
    // A simplified version of your RList:
    trait RList[T] {
      type S
      def data: List[T]
    }
    
    // A list of RLists which have identical S
    sealed trait RListList 
    
    // RListNil is an empty list
    trait RListNil extends RListList {
      def ::[H <: RList[_]](h: H) = rl.::[h.S,H,RListNil](h, this)
    }
    // there is exactly one RListNil
    case object RListNil extends RListNil
    
    // List can be a cons cell of lists sharing the same S
    final case class ::[S, H <: RList[_], T <: RListList](head: H, tail: T) extends RListList {
    
      // We only allow you to cons another to this if we can find evidence that the S matches
      def ::[H2 <: RList[_]](h: H2)(implicit ev: =:=[h.S,S]) = rl.::[S,H2,::[S,H,T]](h, this)
    }
    

    Now, if we try to construct a RListList that doesn’t have all the S types agreeing, the compiler will catch us:

    object RListTest {
    
      val list1 = new RList[Int] { type S = String; def data = List(1,2,3,4) }
      val list2 = new RList[String] { type S = String; def data = List("1","2","3","4") }
      val list3 = new RList[Double] { type S = Float; def data = List(1.1,2.2,3.3,4.4) }
    
      val listOfLists1 = list1 :: RListNil // fine
      val listOfLists2 = list2 :: listOfLists1 // still fine, since list1 and list2 have the same S
      val listOfLists3 = list3 :: listOfLists2 // compiler error: Cannot prove that java.lang.String =:= Float
    
    }
    

    This is using dependent method types, which means you need to use scala 2.10 or you need to compile with the -Ydependent-method-types switch in 2.9.x

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

Sidebar

Related Questions

I know it is quite subjective, but I also want to take this opportunity
Anyone want to take a stab at why this bookmarklet fails in IE8? It
This should be an absurdly easy task: I want to take each line of
This is probably crazy. I want to take the idea of Dependency Injection to
This is strange. In the news details page, I want to take a few
i want to use stripes in our new project. This will take care of
What I want to do is take a numpy array like this: [[1, 2,
I want to take advantage of DateTimePicker 's date validation, but the calendar seemed
I want to take data entered in this format: John Smith 123 Fake Street
What I want to do is take a certain stock pattern (defined as a

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.