Closed tonyhffong closed 9 years ago
This looks good, although I haven't quite grasped all its implications. One nit-pick, should it be:
@traitimpl Tr{ Array{T,N} -> {T,T} } begin
f{T}( x::Array{T,1}, y::T ) = sum(x)+y
end
julia these days don't like the :( {T,T} )
construct:
WARNING: deprecated syntax "{a,b, ...}".
Use "Any[a,b, ...]" instead.
But you raised an interesting point, in the opposite direction: would it be easier to read if we make the parameter in parenthesis or square bracket? Tr{ X(Y) }
or Tr{ X[Y] }
You're right about the warning. I was already in the {}
means Tuple{}
future but this is too ugly:
@traitimpl Tr{ Array{T,N} -> Tuple{T,T} } begin
f{T}( x::Array{T,1}, y::T ) = sum(x)+y
end
Concerning your question, I think the {}
are the right choice though as they are similar to type-parameters.
Very experimental. Do not merge.
Just trying to get this out to get some feedback.
The key new thing is that trait definition allows another layer of curly, i.e.
So that any datatype supplied must be parametric. How do we get
Y
in actual usage? we have two choicesX.parameters
X.parameters
I'm not sure which one is more kosher, and how to switch to the other one if we want to (a syntax issue).
Also,
istrait
currently cannot successfully test if a parametric datatype can satisfy a trait. There is still work to do.I have made a simple "Nullable monad" example using this framework.