Hi, I am trying to implement monoids in factor. A monoid is a set with a binary associative operation (and, depending on the defintiion, a neutral element for it).
Typical examples are numbers (with either addition or multiplication) or sequences (with concatenation). Other examples can be derived from these, since hastables whose values are in a monoid are also naturally a monoid. My implementation is here https://github.com/andreaferretti/factor-work/blob/master/monoid/monoid.factor Using |+| as the word for the operation, one has for instance 3 5 |+| ! gives 8 "hello " "world" |+| ! gives "hello world" H{ { 1 2 } { 3 4 } } H{ { 1 5 } { 5 6 } } |+| ! gives H{ { 1 7 } { 3 4 } { 5 6 } } The issue I have is with quotations. Functions with values in a monoid are also naturally a monoid - in order to sum two functions, apply both and sum the values. So I have the definition M: quotation |+| [ bi |+| ] 2curry ; The problem is that this only works for functions of one argument. For functions of 2 arguments one would have to use M: quotation |+| [ 2bi |+| ] 2curry ; and so on. Unfortunately, there is only a class quotation, which does not seem to distinguish the arity. For comparison, in scala functions have different types based on the arity (such a Function2[A1, A2, B]), and this allows to correctly define |+| - in fact it is a common method in scalaz. Is there anything I can do to make this work regardless of function arity? Also, what about dispatching on both arguments, so that the method only makes sense for a pair of numbers or a pair of quotations, but, say 3 "hi" |+| fails to dispatch? ------------------------------------------------------------------------------ Download BIRT iHub F-Type - The Free Enterprise-Grade BIRT Server from Actuate! Instantly Supercharge Your Business Reports and Dashboards with Interactivity, Sharing, Native Excel Exports, App Integration & more Get technology previously reserved for billion-dollar corporations, FREE http://pubads.g.doubleclick.net/gampad/clk?id=164703151&iu=/4140/ostg.clktrk _______________________________________________ Factor-talk mailing list Factor-talk@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/factor-talk