jolin-io / wheretraits.jl Goto Github PK
View Code? Open in Web Editor NEWtraits for julia: dispatch on whatever you want using where syntax
Home Page: https://schlichtanders.github.io/WhereTraits.jl/dev
License: MIT License
traits for julia: dispatch on whatever you want using where syntax
Home Page: https://schlichtanders.github.io/WhereTraits.jl/dev
License: MIT License
as nightly was failing for unclear reasons it was taken out from the CI
somewhen nightly should again be put to WhereTraits.jl CI
It seems like I am dispatching on a trait (singular) not traits (plural). Is @trait
a better name?
there was the wish to add more complex examples, which makes sense to do
First of all. Great package! The dispatch in Julia is truly great, and this extension makes it even better. I was playing around with the package and I realize that it didn't seem to work with keyword arguments, e.g:
@traits bestprice(b; units) where {units == "cm"} = b
Returns the error
LoadError: MethodError: Cannot `convert` an object of type Symbol to an object of type Expr
Closest candidates are:
convert(::Type{Expr}, ::ExprParsers.ExprParsed) at ~/.julia/packages/ExprParsers/snVTb/src/ExprParsers.jl:135
convert(::Type{T}, ::T) where T at /opt/julia-1.7.1/share/julia/base/essentials.jl:218
Expr(::Any...) at /opt/julia-1.7.1/share/julia/base/boot.jl:263
in expression starting at In[107]:3
The very same code works if I do bestprice(b, units)
. Is this behavior intended? Is there a way around it?
This issue is used to trigger TagBot; feel free to unsubscribe.
If you haven't already, you should update your TagBot.yml
to include issue comment triggers.
Please see this post on Discourse for instructions and more details.
If you'd like for me to do this for you, comment TagBot fix
on this issue.
I'll open a PR within a few hours, please be patient!
It would be nice if this package was available via the general package registry, to make it easy to use from packages.
What the title says, mostly; I was interested in using this while writing a package of mine, but the compilation time was just a touch over what I'd be willing to add to a package. A useful tool here.
There appears to be some runtime overhead from using this package, it's not especially onerous, but it's definitely present:
julia> using WhereTraits, BenchmarkTools
julia> @traits f(x) = x
julia> @btime f(1);
22.215 ns (0 allocations: 0 bytes)
compare against
julia> g(x) = x;
julia> @btime g(1);
1.356 ns (0 allocations: 0 bytes)
Doing some inspection, I think this is due to the conflict resolution system which should be resolved at compile time instead of runtime. Is there anything we can do about this?
It should be worth in your "other traits packages" section to also reference the work of Taine Zhao (aka thautwarm ) in MLStyle.jl , more precisely :
IMO among the 3 others traits pkgs , 2.5 are quite data oriented , while yours is more functional oriented thru dispatch and matches very closely this work
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.