Path: dp-news.maxwell.syr.edu!spool.maxwell.syr.edu!news-spur1.maxwell.syr.edu!news.maxwell.syr.edu!wns14feed!worldnet.att.net!199.45.49.37!cyclone1.gnilink.net!spamkiller2.gnilink.net!gnilink.net!trndny01.POSTED!9244eeff!not-for-mail
From: "David Cressey" <dcressey@verizon.net>
Newsgroups: comp.databases.theory
References: <1149302073.665332.55470@i40g2000cwc.googlegroups.com>   <1149473583.137221.224950@g10g2000cwb.googlegroups.com>   <CUYgg.2121$LN1.271@trndny01> <1149532272.555992.105140@i39g2000cwa.googlegroups.com>
Subject: Re: Aggregation (with GBY) is Relational Division
Lines: 91
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2800.1409
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1409
Message-ID: <mZ3hg.2193$LN1.351@trndny01>
Date: Tue, 06 Jun 2006 00:26:58 GMT
NNTP-Posting-Host: 71.127.7.224
X-Complaints-To: abuse@verizon.net
X-Trace: trndny01 1149553618 71.127.7.224 (Mon, 05 Jun 2006 20:26:58 EDT)
NNTP-Posting-Date: Mon, 05 Jun 2006 20:26:58 EDT
Xref: dp-news.maxwell.syr.edu comp.databases.theory:41046


"Marshall" <marshall.spight@gmail.com> wrote in message
news:1149532272.555992.105140@i39g2000cwa.googlegroups.com...
> David Cressey wrote:
> > "Marshall" <marshall.spight@gmail.com> wrote in message
> >
> > > Actually, I had kind of a jolt reading something Bob Badour
> > > wrote recently about defining aggregates as either a fold
> > > or an expression written in terms of folds. (He did not use
> > > the term "fold".)  Thus, avg(x) can be defined as simply
> > > sum(x) / count().
> >
> > I disagree.  avg(x) can be defined as simply sum(x) / count(x).
> >
> > This may seem like nitpicking.  I think it's reasonably important.
> >
> > If you do   select avg(x), sum(x)/count(*), sum(x)/count(x)  from
some_view
> >
> > you are going to get a difference when there are rows in the view that
> > contain NULL in the x column.  Try it and see.
>
> .... yeah, I see what you mean. If I define it as sum(x) / count(),
> then I'm not counting and summing the same things.
>
> Compared with sum(x) / count(x), in which the sum and
> the count *are* of the same thing. So this *isn't* just an
> issue with SQL's mixing of empty-set semantics and
> unknown semantics.
>
>
> > This relates to a comment about managing missing data in SQL that I
didn't
> > take very much to heart.
> >
> > PS:  can you point me to a web site that will explain "fold" to me?
>
> I did a bit of searching and came up with a short intro:
>
> http://www.cse.unsw.edu.au/~en1000/haskell/hof.html
>
> The functional languages don't have the RA, but they do have
> map, filter, and fold. Not as good, but closer than anything
> else.
>
> Fold is simply inserting a binary operator "in between" the elements
> in a collection. Usually an ordered, collection, alas. Since it's an
> ordered collection, they have to do the extra work to take order
> into account, so you have both foldl and foldr, depending on
> whether you start at the "left" end of the list or the "right".
> (Beginning
> vs. end.)
>
> Interestingly, the obvious conclusion about the type of the function
> being folded is that it should be
>
> 'a, 'a -> 'a
>
> a simple binary function on a single domain.
>
> But in fact, the most general version of the function is
>
> 'a, 'b -> 'b
>
> For example, we can reverse a list using fold.
>
> Given a function append(element, list) that
> returns a list like the one it is passed, but with element tacked
> on the end, we can fold append over a list and reverse it.
>
> foldl(append, [], [1, 2, 3])
>
> returns [3, 2, 1]
>
> Fold depends on being able to separate the first element of a list
> from the rest, and on the ability to recognize an empty list, but
> I don't think it needs anything else.
>
>
> Marshall
>

Marshall,

Thanks for the info on fold.  I think I'm going to try to learn this one.
It looks useful.

So fold needs car, cdr, and nil,  but nothing else.  Hmmmmmmm.......



