You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository has been archived by the owner on Feb 7, 2019. It is now read-only.
I'm thinking how to express a commutative monoid using this framework.
For a monoid, I can do this:
@traitdef Monoid{X} beginmempty( ::X ) -> X
mappend( X, X ) -> X
end
immutable Sum{T<:Number}
value::Tendmempty{T<:Number}( ::Type{Sum{T}} ) =Sum{T}( zero(T) )
mappend{T<:Number}( a::Sum{T}, b::Sum{T} ) =Sum{T}(a.value+b.value)
At the interface level, a commutative monoid is indistinguishable from a regular monoid. The only difference is an assertion that the mappend function for X commutes.
An approach is to whitelist X this way:
@traitdef CommutativeMonoid{X} <:Monoid{X}begin@constraintsbegin
X <:Sum||
X <:Product||
X <:MeanWeightedendend
or via some registration function so that we can add to the whitelist when packages introduce new types. It has a touch of code smell, so I want to create this issue for comments and ideas.
The text was updated successfully, but these errors were encountered:
I'm thinking how to express a commutative monoid using this framework.
For a monoid, I can do this:
At the interface level, a commutative monoid is indistinguishable from a regular monoid. The only difference is an assertion that the
mappend
function forX
commutes.An approach is to whitelist
X
this way:or via some registration function so that we can add to the whitelist when packages introduce new types. It has a touch of code smell, so I want to create this issue for comments and ideas.
The text was updated successfully, but these errors were encountered: