Re: Functions in the relational context

From: Tegiri Nenashi <TegiriNenashi_at_gmail.com>
Date: Fri, 7 Mar 2008 17:00:32 -0800 (PST)
Message-ID: <f50e0abb-19a1-4ad9-b958-3f0a7a51e0ec_at_i29g2000prf.googlegroups.com>


On Mar 7, 12:18 pm, "Yagotta B. Kidding" <y..._at_mymail.com> wrote:
> here are some examples of high-order
> functions:
>
> 1. 'map': map f1 list1 -- applying an arbitrary function to an arbitrary
> list (types have to match naturally)

map Char.toUpper "Hello World"?

big deal:

project_position&output (String(position, character) /\ toUpper(character, output) )

Admittedly, lists are not first class citizens in RM, which makes the query look awkward.

> 3. anonymous function:
> map (2*) [1,2,3]

ditto

> 2. generic left 'fold' used to define other functions:
> sum = foldl(+) 0
> product = foldl (*) 1

Is there foundation for this fold thingy? The way that you have to specify some "initial value" doesn't look very mathematical...

Enough toy examples. How more interesting programs do look like? I googled matrix multiplication:
http://www.cs.auckland.ac.nz/references/haskell/haskell-intro-html/arrays.html this looks even more awful than procedural! It is certainly no match to SQL:

select m1.index1,m2.index2, sum(m1.value*m2.value) from m1,m2 where m1.index2=m2.index1
group by m1.index1,m2.index2

Perhaps you can suggest some other example where nested loops are substituted by elegant combination of fold/map/whatever? Received on Sat Mar 08 2008 - 02:00:32 CET

Original text of this message