Talk:Map (higher-order function)

Random heading
In paragraph 1: 'They are examples of both catamorphisms and anamorphisms.' What does 'they' refer to?

The code following paragraph 4 ('Map itself may be defined recursively as:') is in Haskell and uses Haskell syntax that would probably need to be looked up. Perhaps a link to some basic Haskell syntax would be useful? (In particular, I imagine that someone used to lisp would need to be informed that (x:xs) is notation for a similar notion to (cons x xs), and so forth.)

In the language comparison paragraph: What is a 'high-level procedural' language? A link to a page that defines the terms used, or an example or two, might help. As it is I have no clue what the phrase means.

In the optimization paragraph: I'm nitpicking, but 'The mathematical basis of maps' is vague. It also does not seem too relevant here. Is this mathematical basis that 'map' represents a functor from (types) to (list types) or something like that? I'm not sure if that's relevant at all (rather than being a complex technical detail, it is a rather simple intuitive fact that goes without saying); if it is, it probably belongs in its own section.

On the 'Haskell's Functor class' paragraph: Again I am inclined to nitpick. 'map is generalized to a polymorphic function called fmap' seems silly, since (1) really the generalization here is along the lines of "map the function on maps associated to one functor. fmap denotes the function on maps associated to any functor." i.e., the statement has very little to do with 'map', and a lot to do with 'fmap' and (2) map is already a polymorphic function. For both of these reasons, I imagine that a 'see also' link with a short blurb would be more appropriate.

Ok, that's all. I imagine some words on how 'map' is used in many cases where a loop would be used in other languages, and how 'map' is easy to turn into parallel code, would make this seem a little less academic.

Thanks for your time. 128.135.100.161 18:05, 11 March 2007 (UTC)

fmap is polytypic not just polymorphic, fixed

 * I fixed this and wrote an example of fmap for a tree.
 * but this needs to be rewritten in a better way in content and in formatting (I gave up to indent the code, sorry, I am bad for that as you can see in this unintended bold face paragraph.)
 * I did a quick correction because it was confusing to talk about polymorphism in such way.
 * I found that it is missing an article for polytypic functions in wikipedia. — Preceding unsigned comment added by Elias (talk • contribs) 23:26, 22 March 2011 (UTC)

From the Dutch translation
I don't know anything about the language in question; I'm just translating naively and loosely (using services like Babelfish). Perhaps some of the changes they applied may be useful.

--

In many programming languages, map is a higher-order function that applies a function to each element of a list. This function is particularly common in functional programming languages, but other languages also (such as high-level procedural languages) have this function or make it possible to define it.

For example, we may define a function f and apply it to each element of a list:




 * (this yields )

The function 'map' can be defined as follows (in Haskell):



The function 'map' can also be written using the higher-order function  and function composition:



Map in certain programming languages
Common Lisp contains a number of functions similar to ; the function which corresponds with the function described here is.

In the Standard Template Library of C++ it is called.

In Haskell, map has been generalized to a polymorphic function, which is a component of the   type class. For each instance of the Functor type class, the   function must satisfy the following laws:


 * (identity)
 * (composition)

--

I am guessing this was just based on an earlier version of the document. But it makes more sense in its organization and I prefer the language and formatting used (when I haven't mauled it by retranslation). (Of course, the notes on optimization in the newer version are interesting and should be kept.)

It's also worth noting the example definition hidden /in a comment/ in paragraph 1: "ex, map f = foldr ( . f) []." Apperently this explains why map is an anamorphism or a catamorphism or something. Perhaps these frightening notions on the mathematical basis of map could be quarantined into their own section? I would like that very much.

Hope this feedback is of some use. Thank you. 128.135.100.161 18:45, 11 March 2007 (UTC)

Map is neither a catamorphisen nor an anamorphism
Map is a structure-preserving function, which is called a homomorphism. A catamorphism tears down a structure, while an anamorphism builds one up. The sentence has to be changed to something like --141.87.9.16 (talk) 06:53, 2 July 2009 (UTC)
 * "They are examples of both catamorphisms and anamorphisms."
 * "Map is an example of a homomorphisms."

I agree with that
more over, if $$f$$ has inverse $$f^{-1}$$ then  is an isomorphism. in Haskell foldr and unfold, may be defined as follows: but the explanation with commuting diagram is more clear if seen as categories.

map is defined in the Prelude as follows:   — Preceding unsigned comment added by Elias (talk • contribs) 00:40, 23 March 2011 (UTC)

Rev_map is curried
On the Optimizations section, the implementation of rev_map is curried, but this is never acknowledged. I'm not going to edit it because I'm still a newbie when it comes to functional programming, but someone should check if what I'm saying here is true and add something like: "Notice that the following implementation is curried (make this word a link to Currying). The next argument would be the list to be mapped." —Preceding unsigned comment added by Nothingist (talk • contribs) 05:47, 4 March 2010 (UTC)

java 8 support for maps
java 8 is planned to support map reduce paradigm. see details at http://kim.saabye-pedersen.org/2013/04/java-8.html — Preceding unsigned comment added by 5.144.55.123 (talk) 20:02, 24 October 2013 (UTC)