Comments (8)
Hi @ipsq! IIRC, Libra did something like that. That would also be a way to support #13. I've actually been leaning toward removing any requirements on N
in the class itself, and possibly factoring out the numeric operations into an implicit class, making the core Quantity
a bit leaner.
from coulomb.
I'd be all for it. We are using some optimized numeric types in conjunction with refined
skipping heavy calculations when the type system offers certain guarantees.
from coulomb.
this generalization raises a couple questions I don't have obvious answers for. Taking the basic numeric operators +, -, *, /
as an example, the proper typelevel/algebra
type classes would be:
+
: AdditiveSemigroup-
: AdditiveGroup*
: MultiplicativeSemigroup/
: MultiplicativeGroup
Currently, the implicit data structure that represents unit definitions encodes the conversion coefficients for derived units via a Rational
. That integrates well enough with pretty much any data type adhering to the spire/Numeric
type class, since these are all scalar numerics themselves.
However, the more general type classes above will admit types that aren't themselves scalar. Complex numbers and matrices, for example. These two examples at least have a well-defined notion of what it means to be multiplied by a scalar but I'm not sure all examples of MultiplicativeSemigroup, etc, support a definition scalar multiplication.
It also raises the question of whether 'scalar conversion coefficient' is even the right type. If my multiplicative semigroup is Complex
, does that imply I should be using unit definitions where the conversion coefficient is also complex? Likewise for matrices?
Are your custom types representations of scalar numeric types?
Another example: I currently make use of the spire/Numeric
type for guaranteeing that I can convert between types. This is to allow things like mixing numeric types in unit expressions, paralleling the way one can do 3 + 3.14
. However, more general type classes like AdditiveGroup
do not support this guarantee, so I'd also either have to restrict this feature, or provide another typeclass that will allow such conversions. Restricting them might not be a bad policy, but it's a change from the current behavior.
from coulomb.
@ipsq my original concept, IIRC, was that if someone wanted to use a new kind of numeric type, the approach would be to define a corresponding spire/Numeric
typeclass instance for it. Is that something that would work for your custom types?
from coulomb.
I'm not even sure "scalar numeric" is quite sufficient - the field integers mod n, for prime n
is a field but it's not obvious to me whether it's well defined to declare a unit system over that.
from coulomb.
I think I have worked out how to make progress with this. I'm making some calls to things like uc.n1.plus(value, uc.cv21(rhs.value))
and I've already abstracted the conversion with cv21
in a way that allows for specialization. I just need do the same thing with n1.plus
- turn that into uc.plus
, and then I can specialize rules in the right way.
I'll try to work on this soon
from coulomb.
@ipsq I have pushed a pr for this, as a core refactoring for 0.4.x
#66
coulomb core logic is now fully algebra-ized, and completely decoupled from Numeric.
from coulomb.
Closing this with #66, feel free to re-open if it isn't meeting people's needs
from coulomb.
Related Issues (20)
- scalacheck property testing starting to flake HOT 4
- Remove dependency on spire HOT 8
- port build from sbt to mill? HOT 8
- upgrading to sbt 1.5.0 breaks the build HOT 1
- Scalar operations HOT 2
- Snapshot publish failed on scala 3 branch HOT 2
- Scala 3 tests are not running on JS or Native HOT 2
- scala3 questions HOT 5
- mdoc:fail behaving weirdly HOT 5
- Consider supporting Scala Native HOT 4
- Links to source code from API docs not working HOT 9
- DeltaUnit for YearsBC not resolving offset correctly? HOT 8
- Support for millisecond base time unit HOT 1
- 2 Issues: Simplifying and exporting time units HOT 10
- toInstant doesnt compile for millisecond Long timestamp HOT 3
- Documentation tweaks HOT 1
- migrate to s01.oss.sonatype.org HOT 1
- Simplifying coulomb operation signatures HOT 15
- Compiler crash I can't localize
- constant-factor syntax support depends on scala 3.4 (?) HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from coulomb.