Talk:Map (higher-order function)
From Wikipedia, the free encyclopedia
[edit] 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)
[edit] 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:
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) []
[edit] Map in certain programming languages
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)