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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T22:31:54+00:00 2026-05-19T22:31:54+00:00

Scala has a number of traits that you can use as type classes, for

  • 0

Scala has a number of traits that you can use as type classes, for example Ordered and Numeric in the package scala.math.

I can, for example, write a generic method using Ordered like this:

def f[T <% Ordered[T]](a: T, b: T) = if (a < b) a else b

I wanted to do a similar thing with Numeric, but this doesn’t work:

def g[T <% Numeric[T]](a: T, b: T) = a * b

Why is there an apparent discrepancy between Ordered and Numeric?

I know there are other ways to do this, the following will work (uses a context bound):

def g[T : Numeric](a: T, b: T) = implicitly[Numeric[T]].times(a, b)

But that looks more complicated than just being able to use * to multiply two numbers. Why does the Numeric trait not include methods like *, while Ordered does include methods like <?

I know there’s also Ordering which you can use in the same way as Numeric, see also this answer:

def f[A : Ordering](a: A, b: A) = implicitly[Ordering[A]].compare(a, b)
  • 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-19T22:31:54+00:00Added an answer on May 19, 2026 at 10:31 pm

    Ordered is just a few simple pimped methods that return either Int or Boolean, so no type-trickery is needed.

    Numeric, on the other hand, has methods that return different types depending on the exact subclass used. So while Ordered is little more than a marker trait, Numeric is a fully-featured type class.

    To get your operators back, you can use mkNumericOps (defined in Numeric) on the lhs operand.

    UPDATE

    Miles is quite right, mkNumericOps is implicit, so just importing that instance of Numeric will give you back all the magic…

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

Sidebar

Related Questions

The package scala has a number of classes named Product, Product1, Product2, and so
I have created a project that uses scala that has some abstract classes definitions
As far as I can tell, Scala has definitions for the Enumeration Value class
I am trying to compile a Maven Java/Scala mixed project that has a Scala
So I'm using a graph library that has it's dependencies for Scala listed in
I'm trying to package a scala project into a jar and write properties to
I try to implement some number type and I hit the issue that mynum
The hibernate named query returns a BigDecimal for a column that has datatype NUMBER.
Just wondering if anybody has run Scala app or web-app on Java Real-Time system?
Nullable (C#) has a bit different meaning, but anyway both Option (Scala) and Nullable

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.