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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T02:51:43+00:00 2026-05-28T02:51:43+00:00

I have the following definitions: trait Xode[+R] { type S = Option[R] } case

  • 0

I have the following definitions:

trait Xode[+R] {
  type S = Option[R]
}
case class AXode(a: Int) extends Xode[Int]
case class BXode(b: String) extends Xode[String]

object xtore {
  private var m: Map[Xode[_], Xode[_]#S] = Map()

  def put[A <: Xode[_]](k: A)(v: A#S) {
    m += k -> v    
  }  
}

When executing the following, no error is raised, although I expect AXode#S to be Option[Int].

xtore.put(AXode(5))(Some("apples")) // <-- no error

What might happen is that A is inferred to be Xode[_], and then Xode[_]#S gets to be Option[_]. Could I express my intention with type parameters?

When implemented with R being an abstract type member instead of a type parameter, it works as expected. Or dependent method types and typing v: k.S also helps. Is there any other construct?

  • 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-28T02:51:44+00:00Added an answer on May 28, 2026 at 2:51 am

    Some (maybe slightly wrong explanation)

    X[_] means X[Any]. In particular your map does not relate the value types to the key types over the wild-carded argument to the Xode type constructor. In addition in put, scalac can widen the type of A to Xode[Any] if it needs to. Disclaimer: I’m not 100% sure about what I’m writing

    Code that passes the question

    The following rejects xtore.put(AXode(5))(Some("apples")) and accepts xtore.put(AXode(5))(Some(0)). Note that you also need to capture the type parameter of Xode as opposed to the Xode[_] version in the OP. I don’t understand it completely and there might be a simpler solution.

      def put[A,B[X] <: Xode[X]](k: B[A])(v: B[A]#S) {
        m += k -> v    
      }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following class definitions in c++: struct Foo { int x; char
I have following mapping definitions: <class name=Role table=Role optimistic-lock=version > <id name=Id type=Int32 unsaved-value=0
I have the following definitions: template<typename T1, typename T2> class Test2 { public: static
I have the following configuration: @Aspect public class MyAspect { @Around(@annotation(SomeAnnotation)) public Object myMethod(ProceedingJoinPoint
Suppose we have following code defined in tester.py class Tester( object ): def method(
Given the following class definitions: public class BaseClass { public string SomeProp1 { get;
I have the following definitions. interface IWeapon {} class Warrior { [Inject] public IEnumerable<IWeapon>
I have the following recursive type definitions in C and I am wondering how
Lets say we have the following two class definitions. #include <iostream> #include <array> class
I am using EF with the following definitions: public class StoredFile { public int

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.