Re: [julia-users] Re: ANN: SimpleTraits.jl

2016-09-17 Thread Eric Forgy
Thanks Mauro and Tim. This looks really clever +1


Re: [julia-users] Re: ANN: SimpleTraits.jl

2016-09-15 Thread Mauro
On Thu, 2016-09-15 at 01:19, Jeffrey Sarnoff wrote:
> Thanks for updating your work.
> If there is a form that allows a function to be defined that has
> multidispatch over trait and also over type, please provide an example.
> (If it is already there, please direct me to that example).

Yep, that was missing in the docs, thanks!  I added a section with
example here:
https://github.com/mauro3/SimpleTraits.jl#details-of-method-dispatch

Basically, dispatch first happens on the types as usual.  If the method
thus selected is a trait-method then trait dispatch kicks in.  This is
how it naturally happens with Tim's trick but also how it makes most
sense (to me).

> On Wednesday, September 14, 2016 at 6:04:04 AM UTC-4, Mauro wrote:
>>
>> There is --at times-- some interest on this list about traits, enough
>> that I thought the noise to announce the registration of this traits
>> package is warranted.  In brief, traits group types into sets
>> independent of the type hierarchy and let functions dispatch on those
>> traits instead of on types.
>>
>> The package can be found here:
>>   https://github.com/mauro3/SimpleTraits.jl
>>
>> SimpleTraits.jl provides macros to automate *Tim's trait trick*.  A
>> brief example (more can be found in the README):
>>
>>   using SimpleTraits
>>   # define a trait:
>>   @traitdef IsNice{X}
>>
>>   # add some types to the trait:
>>   @traitimpl IsNice{Int}
>>   @traitimpl IsNice{String}
>>
>>   # define a function dispatching on this trait and its negation:
>>   @traitfn f{X;  IsNice{X}}(x::X) = "Very nice!"
>>   @traitfn f{X; !IsNice{X}}(x::X) = "Not so nice!"
>>
>>   # use that function like any other function
>>   f(5) # => "Very nice!"
>>   f("a") # => "Very nice!"
>>   f(6.0) # => "Not so nice!"
>>
>>
>> Tim Holy, indeed the inventor of the trick named after him, uses
>> SimpleTraits in the overhaul of his Images.jl package [1,2] (and was who
>> prodded me to register SimpleTraits.jl).  The "blurb" in my README is:
>>
>>   Tim Holy endorses SimpleTraits, a bit: "I'd say that compared to
>>   manually writing out the trait-dispatch, the "win" is not enormous,
>>   but it is a little nicer." I suspect that — if you don't write
>>   Holy-traits before breakfast — your "win" should be greater ;-)
>>
>> [1] https://github.com/timholy/Images.jl/issues/542
>> [2] https://github.com/JuliaImages/ImageAxes.jl
>>


[julia-users] Re: ANN: SimpleTraits.jl

2016-09-14 Thread Jeffrey Sarnoff
Thanks for updating your work.
If there is a form that allows a function to be defined that has 
multidispatch over trait and also over type, please provide an example.
(If it is already there, please direct me to that example).

On Wednesday, September 14, 2016 at 6:04:04 AM UTC-4, Mauro wrote:
>
> There is --at times-- some interest on this list about traits, enough 
> that I thought the noise to announce the registration of this traits 
> package is warranted.  In brief, traits group types into sets 
> independent of the type hierarchy and let functions dispatch on those 
> traits instead of on types. 
>
> The package can be found here: 
>   https://github.com/mauro3/SimpleTraits.jl 
>
> SimpleTraits.jl provides macros to automate *Tim's trait trick*.  A 
> brief example (more can be found in the README): 
>
>   using SimpleTraits 
>   # define a trait: 
>   @traitdef IsNice{X} 
>
>   # add some types to the trait: 
>   @traitimpl IsNice{Int} 
>   @traitimpl IsNice{String} 
>
>   # define a function dispatching on this trait and its negation: 
>   @traitfn f{X;  IsNice{X}}(x::X) = "Very nice!" 
>   @traitfn f{X; !IsNice{X}}(x::X) = "Not so nice!" 
>
>   # use that function like any other function 
>   f(5) # => "Very nice!" 
>   f("a") # => "Very nice!" 
>   f(6.0) # => "Not so nice!" 
>
>
> Tim Holy, indeed the inventor of the trick named after him, uses 
> SimpleTraits in the overhaul of his Images.jl package [1,2] (and was who 
> prodded me to register SimpleTraits.jl).  The "blurb" in my README is: 
>
>   Tim Holy endorses SimpleTraits, a bit: "I'd say that compared to 
>   manually writing out the trait-dispatch, the "win" is not enormous, 
>   but it is a little nicer." I suspect that — if you don't write 
>   Holy-traits before breakfast — your "win" should be greater ;-) 
>
> [1] https://github.com/timholy/Images.jl/issues/542 
> [2] https://github.com/JuliaImages/ImageAxes.jl 
>