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

Proposal: add EnergyTraits #512

Open
mileslucas opened this issue Jan 6, 2022 · 2 comments
Open

Proposal: add EnergyTraits #512

mileslucas opened this issue Jan 6, 2022 · 2 comments

Comments

@mileslucas
Copy link
Contributor

mileslucas commented Jan 6, 2022

I propose adding a dependency to Unitful.jl based on a new trait package EnergyTraits.jl. As a proof of concept, these traits allow functional dispatch on the units involved in the equation E = h * nu = h * c0 / lambda.

I have yet to register this package, because I want to see what the feelings over here are. Part of my idea of making EnergyTraits potentially so powerful is having it work with units out of the box. To that end, I have tried to make the package as lightweight as possible (no dependencies, 1 function, 3 types) and I've created a function that automatically tests the trait interface, so actually adding the code should be very easy.

What would the changes look like?

Well, I took a stab at this already in this snippet https://github.com/JuliaAstro/EnergyTraits.jl/blob/d21a2c46cb430ebc6c758937a1f469bfa046bb5f/test/runtests.jl#L7-L9

I'm not positive how the dimensions cascade (i.e., while they always simplify?). If so, would the above lines be sufficient for all the units? It works in the example in that test file, so I'm eager!

So, would this be a welcome effort in Unitful.jl? I am happy to make the necessary PRs, and add any documentation requested. Thanks for your time!

@mileslucas
Copy link
Contributor Author

Here is a much more fleshed out example: https://github.com/JuliaAstro/Planck.jl/blob/main/src/Planck.jl

@mileslucas
Copy link
Contributor Author

mileslucas commented Jan 6, 2022

After some good discussion with @aplavin on Slack, it seems like a better solution overall for the ecosystem would be a separation of the dimensions and the quantities in unitful (ref #359).

If there was a package like UnitfulDimensions that was pretty light and just contained the dimensions, dispatching on things like frequency or length could be achieved without 100% buy-in to Unitful, as well as simplifying dependencies. In fact, this whole trait system could be incorporated into such a package just to offer multiple styles of dispatching on dimensions.

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

1 participant