Comments (7)
I have never seen a “type piracy warning”, can you elaborate on that?
The first edconvert
methods can be simplified as follows:
edconvert(::dimtype(Unitful.Density), x::DimensionlessQuantity, e::DensityConcentration) = x * 1u"kg/L"
But I agree that this should work with the macro. I will implement it so that @eqrelation
can be used with DimensionlessQuantity
.
from unitfulequivalences.jl.
#7 implements the necessary dimtype
method.
One thing that is still missing for dimensionless quantities to work correctly is support for plain numbers: Support for plain numbers is now included in #7 as well.uconvert(u"kg/L", 5u"mm/m", DensityConcentration())
works, but uconvert(u"kg/L", 5, DensityConcentration())
does not. I will implement that as well. Note that the conversion to plain numbers already works: uconvert(NoUnits, 5u"kg/L", DensityConcentration())
from unitfulequivalences.jl.
Many thanks for implementing this!
And thanks for telling me about DimensionlessQuantity
. I was looking for something like this to use as you mentioned, but somehow I missed it.
As for the type piracy, the warning I get is "An imported function has been extended without using module defined typed arguments.", which shows up in julia-vscode/StaticLint.jl as "TypePiracy".
I just learned about this so I will just point to two places that explain it better: julialang docs: Avoid type piracy and discourse: Clarification on type piracy.
So I agree that my extension to dimtype
is a type piracy since both types I use are defined in other modules, but the following extensions use the type DensityConcentration
, which is defined in my module, but they still give me this warning:
edconvert(d::dimtype(Unitful.Density), x::Unitful.DimensionlessQuantity, e::DensityConcentration) = x * 1u"kg/l"
edconvert(d::dimtype(NoDims), x::Unitful.Density, e::DensityConcentration) = x * 1u"L/kg"
Anyways, I will try out now with the direct relation that you implemented and get back here to let you know.
from unitfulequivalences.jl.
Ah, I guess I need to wait till the pull-request is closed, no worries. And I like that you proposed to make the definition of DimensionlessQuantity
in Unitful.jl
consistent with the others.
from unitfulequivalences.jl.
Thanks, I know about type piracy but did not know that there are linters who warn about it.
However, the edconvert
methods are not type piracy (since you own DensityConcentration
), so I wonder why you get a warning for them. Maybe the linter doesn’t recognise that DensityConcentration
is a type from your module, since its definition is obfuscated by the @equivalence
macro? Is the warning fixed by defining the DensityConcentration
struct yourself instead of using the macro?
from unitfulequivalences.jl.
Is the warning fixed by defining the DensityConcentration struct yourself instead of using the macro?
If I define it directly then the warning disappears.
from unitfulequivalences.jl.
If I define it directly then the warning disappears.
One more reason to remove the @equivalence
macro 😄
from unitfulequivalences.jl.
Related Issues (8)
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 unitfulequivalences.jl.