Skip to main content
broken link fixed, cf. https://meta.stackoverflow.com/a/406565/4751173
Source Link
Glorfindel
  • 3.2k
  • 6
  • 26
  • 33

Is SQL basically a domain specific instance of map + fold + filter?

It seems to me that the following SQL:

SELECT name
FROM fruits
WHERE calories < 100 

is just syntactic sugar for the following map + filter + fold operation:

var fruits = [{id : 1, name: 'orange', calories : 100},
    {id : 2, name : 'banana',  calories : 150},
    {id : 3, name: 'apple', calories : '50'}];

fruits.map(function(fruit) { return { name : fruit.name, calories : fruit.calories })
    .filter(function(obj) { return obj.calories < 100 })
    .reduce(function (accumulator, obj) { accumulator + "\n" + val.name; });

Is this coincidence, or is there a sound semantic equivalence that can be proven? How, roughly?

I know in practice SQL has a lot of bells and whistles but at its core is it simply a map-fold-filter operation?

The following article is relevant: http://blogs.msdn.com/b/doriancorompt/archive/2013/01/21/bringing-the-querying-power-of-sql-to-javascript.aspxLink

Is SQL basically a domain specific instance of map + fold + filter?

It seems to me that the following SQL:

SELECT name
FROM fruits
WHERE calories < 100 

is just syntactic sugar for the following map + filter + fold operation:

var fruits = [{id : 1, name: 'orange', calories : 100},
    {id : 2, name : 'banana',  calories : 150},
    {id : 3, name: 'apple', calories : '50'}];

fruits.map(function(fruit) { return { name : fruit.name, calories : fruit.calories })
    .filter(function(obj) { return obj.calories < 100 })
    .reduce(function (accumulator, obj) { accumulator + "\n" + val.name; });

Is this coincidence, or is there a sound semantic equivalence that can be proven? How, roughly?

I know in practice SQL has a lot of bells and whistles but at its core is it simply a map-fold-filter operation?

The following article is relevant: http://blogs.msdn.com/b/doriancorompt/archive/2013/01/21/bringing-the-querying-power-of-sql-to-javascript.aspx

Is SQL basically a domain specific instance of map + fold + filter?

It seems to me that the following SQL:

SELECT name
FROM fruits
WHERE calories < 100 

is just syntactic sugar for the following map + filter + fold operation:

var fruits = [{id : 1, name: 'orange', calories : 100},
    {id : 2, name : 'banana',  calories : 150},
    {id : 3, name: 'apple', calories : '50'}];

fruits.map(function(fruit) { return { name : fruit.name, calories : fruit.calories })
    .filter(function(obj) { return obj.calories < 100 })
    .reduce(function (accumulator, obj) { accumulator + "\n" + val.name; });

Is this coincidence, or is there a sound semantic equivalence that can be proven? How, roughly?

I know in practice SQL has a lot of bells and whistles but at its core is it simply a map-fold-filter operation?

The following article is relevant: Link

Tweeted twitter.com/#!/StackProgrammer/status/608737073122713600
edited title
Link

Are (basic) SQL queries semantically equivalent to Higher Order Functions?

Source Link

Are SQL queries semantically equivalent to Higher Order Functions?

Is SQL basically a domain specific instance of map + fold + filter?

It seems to me that the following SQL:

SELECT name
FROM fruits
WHERE calories < 100 

is just syntactic sugar for the following map + filter + fold operation:

var fruits = [{id : 1, name: 'orange', calories : 100},
    {id : 2, name : 'banana',  calories : 150},
    {id : 3, name: 'apple', calories : '50'}];

fruits.map(function(fruit) { return { name : fruit.name, calories : fruit.calories })
    .filter(function(obj) { return obj.calories < 100 })
    .reduce(function (accumulator, obj) { accumulator + "\n" + val.name; });

Is this coincidence, or is there a sound semantic equivalence that can be proven? How, roughly?

I know in practice SQL has a lot of bells and whistles but at its core is it simply a map-fold-filter operation?

The following article is relevant: http://blogs.msdn.com/b/doriancorompt/archive/2013/01/21/bringing-the-querying-power-of-sql-to-javascript.aspx