Return-Path: X-Original-To: apmail-commons-dev-archive@www.apache.org Delivered-To: apmail-commons-dev-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id D58467428 for ; Thu, 15 Dec 2011 13:20:50 +0000 (UTC) Received: (qmail 19832 invoked by uid 500); 15 Dec 2011 13:20:50 -0000 Delivered-To: apmail-commons-dev-archive@commons.apache.org Received: (qmail 19726 invoked by uid 500); 15 Dec 2011 13:20:50 -0000 Mailing-List: contact dev-help@commons.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: "Commons Developers List" Delivered-To: mailing list dev@commons.apache.org Received: (qmail 19718 invoked by uid 99); 15 Dec 2011 13:20:50 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 15 Dec 2011 13:20:50 +0000 X-ASF-Spam-Status: No, hits=2.2 required=5.0 tests=HTML_MESSAGE,RCVD_IN_DNSWL_LOW,SPF_NEUTRAL X-Spam-Check-By: apache.org Received-SPF: neutral (athena.apache.org: local policy) Received: from [209.85.212.43] (HELO mail-vw0-f43.google.com) (209.85.212.43) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 15 Dec 2011 13:20:42 +0000 Received: by vbbfq11 with SMTP id fq11so4879973vbb.30 for ; Thu, 15 Dec 2011 05:20:20 -0800 (PST) MIME-Version: 1.0 Received: by 10.52.20.209 with SMTP id p17mr3057293vde.60.1323955220598; Thu, 15 Dec 2011 05:20:20 -0800 (PST) Sender: jcarman@carmanconsulting.com Received: by 10.220.2.138 with HTTP; Thu, 15 Dec 2011 05:20:20 -0800 (PST) Received: by 10.220.2.138 with HTTP; Thu, 15 Dec 2011 05:20:20 -0800 (PST) In-Reply-To: References: <4EDC0593.5070200@dia.uniroma3.it> <4EE545AE.1020906@dia.uniroma3.it> <4EE61054.3090906@dia.uniroma3.it> <4EE78CEC.3090403@dia.uniroma3.it> <4EE895F4.9050802@dia.uniroma3.it> Date: Thu, 15 Dec 2011 08:20:20 -0500 X-Google-Sender-Auth: rFwRMEHluz62LBaAdtphbtDjtZ0 Message-ID: Subject: Re: [Graph] On graph weight type(s) From: James Carman To: Commons Developers List Content-Type: multipart/alternative; boundary=20cf307d05cc9f513f04b421585c --20cf307d05cc9f513f04b421585c Content-Type: text/plain; charset=ISO-8859-1 We may be modeling the domain properly with all of this terminology, but is this going to be understandable to the common user? On Dec 15, 2011 7:38 AM, "Matthew Pocock" wrote: > Hi, > > On 15 December 2011 11:35, James Carman > wrote: > > > > public interface BinaryOperation > > { > > public T execute(T operand1, T operand2); > > } > > > > Perhaps we can come up with an interface that combines the two > > aspects. I'm trying to think of mathematically what that would be > > called. By the way, what do you need to know "HasZero"? A sum > > operation has to have a "zero", doesn't it? > > > The mathematical hierarchy goes: semigroup -> monoid. > > http://en.wikipedia.org/wiki/Semigroup > http://en.wikipedia.org/wiki/Monoid > > You don't need a full group here as you are only interested in a single > operation, not a pair of interacting operations. There are several > JVM-hosted libraries that model this hierarchy to a greater or lesser > degree. scalaz uses: > > trait Semigroup[S] { > def append(s1: S > < > http://scalaz.googlecode.com/svn/continuous/latest/browse.sxr/scalaz/Semigroup.scala.html#22357 > >, > s2: => S): S < > http://scalaz.googlecode.com/svn/continuous/latest/browse.sxr/scalaz/Semigroup.scala.html#22357 > > > } > > trait Zero[Z] { > val zero: Z < > http://scalaz.googlecode.com/svn/continuous/latest/browse.sxr/scalaz/Zero.scala.html#22160 > > > } > > trait Monoid[M] extends Zero > < > http://scalaz.googlecode.com/svn/continuous/latest/browse.sxr/scalaz/Zero.scala.html#17945 > >[M] > with Semigroup < > http://scalaz.googlecode.com/svn/continuous/latest/browse.sxr/scalaz/Semigroup.scala.html#15476 > >[M] > > > http://scalaz.googlecode.com/svn/continuous/latest/browse.sxr/scalaz/Semigroup.scala.html > > http://scalaz.googlecode.com/svn/continuous/latest/browse.sxr/scalaz/Zero.scala.html > > http://scalaz.googlecode.com/svn/continuous/latest/browse.sxr/scalaz/Monoid.scala.html > > If you're not used to reading scala, here's the essentially equivalent > definitions in Java: > > public interface Semigroup { > public S append(S s1, S s2); > } > > public interface Zero { > > public Z zero(); > } > > public interface Monoid extends > Zero< > http://scalaz.googlecode.com/svn/continuous/latest/browse.sxr/scalaz/Zero.scala.html#17945 > >, > Semigroup< > http://scalaz.googlecode.com/svn/continuous/latest/browse.sxr/scalaz/Semigroup.scala.html#15476 > > > > > > So, given that you have Ordering already (or is that Comparator?), > I'd say that Weight is defined as: > > // insert comments here about the consistency of append and compare > public interface Weight extends Monoid, Ordered > > Of course, a sensible default implementation of Weight would delegate to > Monoid and Ordered instances and you can then pray to the gods of hotspot > to inline this all away. > > public Weight weight(Monoid m, Ordered o) { > new Weight() { > public W zero() { return m.zero(); } > ... > } > } > > Matthew > > -- > Dr Matthew Pocock > Integrative Bioinformatics Group, School of Computing Science, Newcastle > University > mailto: turingatemyhamster@gmail.com > gchat: turingatemyhamster@gmail.com > msn: matthew_pocock@yahoo.co.uk > irc.freenode.net: drdozer > skype: matthew.pocock > tel: (0191) 2566550 > mob: +447535664143 > --20cf307d05cc9f513f04b421585c--