Hacker News new | ask | show | jobs
by hzhou321 4090 days ago
Generics as in current C++ and Java are still tied to the low level data types. They merely extended from single data type to a collection of data types (that fits certain strict condition).

Now look at our natural language, "eat" for example, you can suddenly say "the sky dog eats the sun" out of the blue and people will start to make that sentence work (which is the ancient Chinese referring to eclipse). Here the vocabulary word "eat" can be defined at any time of history, but not being confined by the definition at any time. The use of words leads definition rather than the other way around.

Let's look at the word "fold", which works on list. Now I have an array or a hash or a matrix, and I am thinking that I need some kind of operation similar to "fold" on a list. Do you just write "fold add array|hash|matrix" then work out the detail implementation (probably at a much later stage)? If you do, you are treating fold as a vocabulary word and you are doing vocabulary lead programing.

Yes, in the case of "fold", it describes a composition type of meaning. How about "pick", "find" or "eat"?

I guess what I am trying to differentiate is meaning and implementation. Larry Wall's favorite idiom is there is more than one way to do it, I think it fits what I mean. it is the meaning, and way is the implementation. In current programming practice, most people only focuses on how it is done, but neglects the meaning. I actually heard many complaints from programmers against Perl exactly because of this "there's more than one way to do it" attitude, how about you?

1 comments

This is a problem already solved by typeclasses in Haskell; http://hackage.haskell.org/package/base-4.8.0.0/docs/Data-Fo...

You can write your own instances of Foldable to add implementations of the "vocabulary" word fold.

How is this different from what you're proposing? It sounds almost like you want the compiler to figure out an instance of Foldable (or, say, Edible) for you, but computers simply don't work that way (then again, GHC can derive Foldable sometimes!).