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

The Archive Base Latest Questions

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

I have hit a problem while working with the Units of Measurements functionality in

  • 0

I have hit a problem while working with the Units of Measurements functionality in metascala, defined in the file Units.scala.

For the remainder of this question, I will use a simplified scheme, with only one Unit type, length.

So where in reality a type looks like

Quantity[_1, _0, _0, _0, _0, _0, _0] 
          ^   ^   ^   ^   ^   ^   ^
          |   |   |   |   |   |   |
          | Mass  | Crncy.|  Mol  |
       Length   Time    Temp. Lum.Intensity

this will be sufficient for demonstrating the problem:

Quantity[_1]
          ^
          |
       Length

As soon as the type needs to be inferred, the trouble starts.

Consider this example (also have a look at the code from UnitsTest.scala):

val length: Quantity[_1] = m(5)
val area:   Quantity[_2] = length * length // (1) Works
val dist:   Quantity[_1] = area / length   // (2) Doesn't work!

I get an error in the last line saying:

type mismatch;
  found :
    scalax.units.Units.Quantity[
      scalax.units.Subtractables.-[
        scalax.units.Integers._2,
        scalax.units.Integers._1
      ]
    ]

  required:
    scalax.units.Units.Quantity[
      scalax.units.Integers._1
    ]

It looks like the compiler can’t figure out that the type at hand is equal to Quantity[_1] when “substracting a dimension”, e. g. going from area to dist like in (1):

Quantity[_2 - _1] <<not equal to>> Quantity[_1]

The confusing thing is that it works when “adding a dimension” e. g. going from length to area like in (2):

Quantity[_1 + _1] <<equal to>> Quantity[_2]

(Sorry for not pasting the whole code here, it is just too much. I tried to minimize my example, but I failed. That’s why I’m just linking to it.)

  • 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-26T19:41:56+00:00Added an answer on May 26, 2026 at 7:41 pm

    Type Sub from Subtractable is missing in the MInt trait. A simple definition to make it work would be to perform a negative addition when you want to subtract a type in MSucc and MNeg.

    sealed trait MInt extends Visitable[IntVisitor] with Addable with Subtractable {
      type AddType = MInt
      type SubType = MInt
      type Add[I <: MInt] <: MInt
      type Sub[I <: MInt] <: MInt
      type Neg <: MInt
      type Succ <: MInt
      type Pre <: MInt
    }
    
    final class _0 extends Nat {
      type Add[I <: MInt] = I
      type Sub[I <: MInt] = I#Neg
      type AcceptNatVisitor[V <: NatVisitor] = V#Visit0
      type Neg = _0
      type Succ = MSucc[_0]
      type Pre = Succ#Neg
    }
    
    final class MSucc[P <: Nat] extends Pos {
      type This = MSucc[P]
      type Add[N <: MInt] = P#Add[N]#Succ
      type Sub[N <: MInt] = Add[N#Neg]
      type AcceptNatVisitor[V <: NatVisitor] = V#VisitSucc[P]
      type Neg = MNeg[This]
      type Pre = P
      type Succ = MSucc[This]
    }
    
    final class MNeg[P <: Pos] extends MInt {
      type Add[N <: MInt] = P#Add[N#Neg]#Neg
      type Sub[N <: MInt] = Add[N#Neg]
      type Accept[V <: IntVisitor] = V#VisitNeg[P]
      type Neg = P
      type Succ = P#Pre#Neg
      type Pre = P#Succ#Neg
    }
    

    One more thing, the / method in Quantity should divide its parameters and not multiply them!

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

Sidebar

Related Questions

I have hit upon this problem about whether to use bignums in my language
I am trying to learn ASP.NET MVC and I hit this problem: I have
I'm new to python and have hit a problem with an SQL query I'm
I have hit a classic problem of needing to do a string replace on
I'm onto problem 245 now but have hit some problems. I've done some work
The problem i have is i could DELETE but then when i hit refresh
I'm working through Practical Web 2.0 Appications currently and have hit a bit of
I'm working on this website, and have a little thorn in my side. When
I have implemented Conway's Game of Life problem in Java swing. Everything is working
I've seem to have hit a bug or i have overlooked something. I written

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.