Path: csiph.com!usenet.pasdenom.info!gegeweb.org!eternal-september.org!feeder.eternal-september.org!mx04.eternal-september.org!.POSTED!not-for-mail From: markspace <-@.> Newsgroups: comp.lang.java.programmer Subject: Re: Dealing with higher order operations coupled with primitives Date: Thu, 21 Jun 2012 21:32:04 -0700 Organization: A noiseless patient Spider Lines: 45 Message-ID: References: <6s2dnZ1-8r4ofH7SnZ2dnUVZ_s6dnZ2d@giganews.com> Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Injection-Date: Fri, 22 Jun 2012 04:32:10 +0000 (UTC) Injection-Info: mx04.eternal-september.org; posting-host="IZQsHU8CwMUPnWgvh4wwWA"; logging-data="23924"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19wLZWInFAoAGdh35D+iesQXt6ll6Nj83M=" User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:13.0) Gecko/20120614 Thunderbird/13.0.1 In-Reply-To: <6s2dnZ1-8r4ofH7SnZ2dnUVZ_s6dnZ2d@giganews.com> Cancel-Lock: sha1:/+czM+i6N0AYN/JA0fsHBwL5Jck= Xref: csiph.com comp.lang.java.programmer:15508 On 6/21/2012 8:08 PM, Aaron W. Hsu wrote: > public class IotaSumReduce { > > public static int sum(int n) { > int res = 0; > for (int i = 0; i < n; i++) res += i; return res; > } This method needed a return value; I assume you meant res. > public class AplIotaSumReduce { > > private static class Sum extends Function { > void apply(AplArray res, AplArray arg) { > Function plus = new AplArray.PlusFunction(); I think we are going to need the definitions of Function, AplArray, AplArray.PlusFunction, etc. I'd prefer not to guess how you are implementing these right now. > res.iota(arg); > res.reduce(plus, res); I think I understand reduction, but shouldn't it return a value? I don't see how you reduce in-place like this; are you over-writing the 0th element or something? > > This program runs much much slower for me. We'll definitely need more code. We're far afield of what Java normally does. Trying to guess at your implementation is counter productive, and standard ways of doing this don't exist afaik, as Java programmers don't normally (ever?) do this sort of thing. I'll agree with others: Haskell/Clojure seem a better fit.