Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

improve type stability? #109

Open
stevengj opened this issue Feb 7, 2017 · 5 comments
Open

improve type stability? #109

stevengj opened this issue Feb 7, 2017 · 5 comments

Comments

@stevengj
Copy link
Collaborator

stevengj commented Feb 7, 2017

Currently, it seems like most of the operations are type-unstable:

julia> using SIUnits, SIUnits.ShortUnits, Base.Test

julia> @inferred 1m
ERROR: return type SIUnits.SIQuantity{Int64,1,0,0,0,0,0,0,0,0} does not match inferred return type Union{Int64,SIUnits.SIQuantity{T<:Number,m,kg,s,A,K,mol,cd,rad,sr}}
 in error(::String) at ./error.jl:21
 in error(::String) at /Applications/Julia-0.5.app/Contents/Resources/julia/lib/julia/sys.dylib:?

julia> x = 1m
1 m

julia> @inferred x*x
ERROR: return type SIUnits.SIQuantity{Int64,2,0,0,0,0,0,0,0,0} does not match inferred return type Union{Int64,SIUnits.SIQuantity{T<:Number,m,kg,s,A,K,mol,cd,rad,sr}}
 in error(::String) at ./error.jl:21
 in error(::String) at /Applications/Julia-0.5.app/Contents/Resources/julia/lib/julia/sys.dylib:?

It seems like there is enough information available to determine these exponents at compile time.

@stevengj
Copy link
Collaborator Author

stevengj commented Feb 7, 2017

I was playing around with it, and generated functions seem capable of doing this nicely.

@timholy
Copy link
Collaborator

timholy commented Feb 7, 2017

This already works today in Unitful, which has many other nice goodies besides.

@stevengj
Copy link
Collaborator Author

stevengj commented Feb 7, 2017

Ah, I see... I guess SIUnits is obsolete then?

@timholy
Copy link
Collaborator

timholy commented Feb 7, 2017

It still works and remains an impressive package, but

  • Unitful was written at a time it could take advantage of newer features of Julia (SIUnits accomplished amazing things at an early stage of Julia's evolution)
  • @ajkeller34 has put, and continues to put, a lot of active maintenance into Unitful
  • there's only so much manpower

@stevengj
Copy link
Collaborator Author

stevengj commented Feb 7, 2017

Sure, but it would be nice if packages that are superseded by newer packages would be clearly marked as such, e.g. on pkg.julialang.org and in the first sentence of the README.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants