On 07/12/2012, at 10:46 AM, srean wrote:
> 
> Now I have to figure out what polyadic means 

Polymorphic means "independent of data type".
[Actually it means "many shapes" if you translate the Latin directly]

For example STL Vector<T> is polymorphic over data type T.

Polyadic means polymorphic over the data *structure*.

C++ iterator are extensionally polyadic, i.e. you can write
algorithms which are source level independent of the
data structure. For example

        std::accumulate

works with iterators based on both vector and list.

However, this polyadic behaviour, which is the KEY principle
of STL iterators, only holds at the source level. A vector<int>::iterator
and a list<int>::iterator are actually different types. So accumulate
over a vector<int>::iterator is a different function to accumulate
over list<int>::iterator.

Now, in Ocaml, a polymorphic function is intensionally polymorphic.
This means there's one binary function that works with all types.

Streams produced by generators are polyadic in Ocaml and Felix:
they use functional abstraction to hide the data structure  entirely.
This makes them superior to C++ iterators.

Note that despite this higher order independence, Felix streams
(and channels), and only extensionally polymorphic over the
data type: the binary code is repeated for each data type but its
the same for all data structures over a given type.

Felix can actually do intensionally polymorphic functions
as well, provided you "box" you types, i.e. hide them behind
pointers.

The method is as old as the hills and used in C all the time:
use casts and void* and you have polymorphism in C.
Which is how functional programming languages do it :)

Anyhow, somewhere you'll see the claim Felix has polyadic arrays.

This means independent of rank. You can write a map or fold
that works over an array of 1 dimension and it works over
2, 3  .. any number of dimensions. 

You cannot do that in C++...

ACTUALLY it may be possible in C++11.

The challenge amounts to this: suppose you have a vector<double>.
You write some routine like accumulate to add up the doubles.

It won't work over a vector<vector<double>>.
But you CAN write an iterator adaptor that scans all the doubles.
Not too hard.

But it won't work on vector<vector<vector<double>>>.
You can write an iterator adaptor for that too, but it only
works on rank 3 vector.

Can you write one that works on ANY rank?

You can NOT do this in C++90. However in C++11 it may be
possible to do it with template meta-programming thanks to
a couple of new features including variable argument templates
(I'm not sure).

Polyadic arrays are essential for almost all engineering problems.
For a simple example, you study heat transfer in a rod (1 dimension)
by finite element analysis.

Then you rewrite your code for sheets.

Then again, for solids.

That SUCKS. With polyadic arrays, there's no rewrite.
The code works for all 3 cases.

Now think Quantum Chemistry. Do you really want to rewrite
you code if you upgrade from a study of two variables to three?
Or physics, with normalised coordinates.

Of course the most attractive one from a MONEY making
perspective (are you listening Shayne?) is of course MONEY.
The single biggest impediment to financial calculations is the inability
to calculate with more than 2 or 3 variables. This is because you have
to rewrite your code every time. Each extra variable requires an extra
loop. This is why financial modelling uses stuff like NumPy, because the rank
is variable -- the code just isn't statically safe.

Note that array polyadic is just rank independence.
I say "just" because it only handles arrays, arrays of arrays,
etc. General polyadic behaviour generalises over a wider
class of data structure.


--
john skaller
skal...@users.sourceforge.net
http://felix-lang.org




------------------------------------------------------------------------------
LogMeIn Rescue: Anywhere, Anytime Remote support for IT. Free Trial
Remotely access PCs and mobile devices and provide instant support
Improve your efficiency, and focus on delivering more value-add services
Discover what IT Professionals Know. Rescue delivers
http://p.sf.net/sfu/logmein_12329d2d
_______________________________________________
Felix-language mailing list
Felix-language@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/felix-language

Reply via email to