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

  • Home
  • SEARCH
  • 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 8958231
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T15:09:53+00:00 2026-06-15T15:09:53+00:00

I am trying to create a wrapper for certain Types used in my program.

  • 0

I am trying to create a wrapper for certain Types used in my program. I also want all of these types to have a compare Method by implementing the trait Ordered[T]. I am having a problem making a compare method that determines that the type being compared implicitly implements Ordred[T].

Current Attempt:

case class Value[T](someType: T) extends Ordered[T] {

  def matches(otherType: T): Boolean = {
    if(someType.getClass == otherType.getClass)
      true
    else false
  }

  override def toString() = {
    someType.toString
  }

  def compare(other: T): Int = {
    implicitly[Ordered[T]] compare other
  }
}

object Value {
  implicit def intVal(some: Int) = new Value[Int](some) {
    def compare(other: Int): Int = someType compare other
  }
  implicit def doubleVal(some: Double) = new Value[Double](some) {
    def compare(other: Double): Int = someType compare other
  }
  implicit def stringVal(some: String) = new Value[String](some) {
    def compare(other: String): Int = someType compare other
  }
  implicit def boolVal(some: Boolean) = new Value[Boolean](some) {
    def compare(other: Boolean): Int = someType compare other
  }
  implicit def dateVal(some: Date) = new Value[Date](some) {
    def compare(other: Date): Int = someType.compareTo(other)
  }
}

This is the structure I would like but I keep getting the error:

Could not find value for implicit parameter e: Ordered[T]

Is there some syntax that I’m missing?

  • 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-15T15:09:55+00:00Added an answer on June 15, 2026 at 3:09 pm

    Ordered is not a typeclass, but a trait, that classes or other traits inherit from to be orderable. So you can’t implicitly get an instance of Ordered. You have to modify your type parameter to make shure, that A extends Ordered[A] or can be viewed as one (<% is a view bound and means there exists an implicit conversion from A to Ordered[A]) and then you can simply call compare:

    case class Value[A <% Ordered[A]](value: A) extends Ordered[Value[A]] {
      def compare(other: Value[A]) = value compare other.value
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following directory c:/files and I'm trying to create a wrapper function
I'm trying to create a wrapper around a logging method (Debug.Log) in Unity3d. What
I've been trying to create a wrapper function that takes all the function properties
I am trying to create a website where I have .wrapper that runs vertical
I'm trying to create an NSTimer using a wrapper method, so that I can
I'm trying to create a template wrapper class which inherits from its template parameter
I was trying to create a python wrapper for an tk extension, so I
I am trying create a delegate representation of constructor by emitting a Dynamic Method,
Trying to create a macro which can be used for print debug messages when
I am trying to write T4 template to create wrapper classes for classes created

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.