Talk:Map (higher-order function)

Latest comment: 11 years ago by 5.144.55.123 in topic java 8 support for maps

Random heading

edit

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)Reply

fmap is polytypic not just polymorphic, fixed

edit
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 (talkcontribs) 23:26, 22 March 2011 (UTC)Reply

From the Dutch translation

edit

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:

f x = x + 3
map f [1,2,3] (this yields [4,5,6])

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

map f [] = []
map f (x:xs) = f x : map f xs

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

map = foldr ((:).f) []

Map in certain programming languages

edit

Common Lisp contains a number of functions similar to map; the function which corresponds with the function described here is mapcar.

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

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

fmap id = id (identity)
fmap (f . g) = fmap f . fmap g (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)Reply

Map is neither a catamorphisen nor an anamorphism

edit

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)Reply

I agree with that

edit

more over, if   has inverse   then map f is an isomorphism. in Haskell foldr and unfold, may be defined as follows:

 foldr op e = g where g (x:xs) = x `op` (g xs)
 unfold p hd tl = f 
    where f [] = []
          f  x = if p x then [] else hd x : f (tl x)

but the explanation with commuting diagram is more clear if seen as categories.

map is defined in the Prelude as follows: map f xs = [f x|x<-xs] — Preceding unsigned comment added by Elias (talkcontribs) 00:40, 23 March 2011 (UTC)Reply

Rev_map is curried

edit

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 (talkcontribs) 05:47, 4 March 2010 (UTC)Reply

java 8 support for maps

edit

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)Reply