harrisongrodin / radical-julia Goto Github PK
View Code? Open in Web Editor NEWRadical ideas for the Julia language.
Radical ideas for the Julia language.
A minor suggestion:
In general it is not possible to implement x-y
as x+(-y)
: think of a strict unsigned type, then -y
is not defined (at best one can implicitly convert to another signed type). Mathematically speaking, on the natural numbers, there is no unary minus; -1 is not a natural number; but there still is a binary minus: 2-1 = 1 is well-defined even though 1 is not.
I would therefore instead make binary minus a primitive, and define unary minus via zero(x)-x
Similar for inv(x): there is no inverse of 2 in the integers, but 4/2 = 2 is valid. So inv(x) = one(x)/x
Cross-posted from JuliaLang/julia#5 (comment), andyferris/Traitor.jl#9, and mauro3/SimpleTraits.jl#63.
@HarrisonGrodin The traits write-up is great!
In your vision of traits, would it be possible to dispatch on arrays where all elements in the array have a certain trait?
Here's a minimum working example. All of the lines currently work in Julia except for the last line:
abstract type MyTrait end
struct FooTrait <: MyTrait end
struct BarTrait <: MyTrait end
struct A end
struct B end
struct C end
struct D end
MyTrait(::Type{A}) = FooTrait()
MyTrait(::Type{B}) = FooTrait()
MyTrait(::Type{C}) = BarTrait()
MyTrait(::Type{D}) = BarTrait()
f(x::T) where T = _f(MyTrait(T), x)
_f(::FooTrait, x) = "foo"
_f(::BarTrait, x) = "bar"
_f(::FooTrait, x::AbstractArray) = "foo array"
_f(::BarTrait, x::AbstractArray) = "bar array"
f(A()) # "foo"
f(B()) # "foo"
f(C()) # "bar"
f(D()) # "bar"
MyTrait(::Type{<:AbstractArray{T, N}}) where T where N = MyTrait(T)
f([A(), A()]) # "foo array"
f([B(), B()]) # "foo array"
f([C(), C()]) # "bar array"
f([D(), D()]) # "bar array"
f([A(), B()]) # I want this to return "foo array", but instead it throws "ERROR: MethodError: no method matching MyTrait(::Type{Any})"
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.