
Hello, I have a general question, not specific to Haskell although I am learning Haskell as I ask this question.. Please can someone provide consensus on the most important functional methods in their view. I read somewhere that having map, reduce, filter, mergeAll, and zip pretty much means everything else can be derived. Further, what I specifically want to know is whether flatMap should be included as an implementation in a functional library, or whether it should be excluded because it is derivable using “building block” functions. Hope this makes sense. In languages like JS, there is a lot of resistance to include flatMap in prominent libraries such as underscore and lodash. Am curious to know what the Haskell community view is here, or whether in this community too opinions are widely divided. Alternatives I have seen are: 1). Chaining functions together chain(map(), map() 2). Using reduce() - which seems so versatile like a for loop for anything if really want 3). Using flatten(), or chaining pluck and flatten 4). Using map flatten compact - this gets rid of null, undefined etc in a language like JS too Recently, Reactive extensions have got really popular and it seems increasingly that flatMap is ideal for these situations. Would welcome some general advice and thoughts. If this is off-topic of course, then sorry to have caused any inconvenience. My thoughts are that the Haskell community have the necessary experience regarding functional programming in general to offer opinion. Best regards,

On Saturday, June 7, 2014, Richard Seldon
Hello,
I have a general question, not specific to Haskell although I am learning Haskell as I ask this question..
Please can someone provide consensus on the most important functional methods in their view.
I read somewhere that having map, reduce, filter, mergeAll, and zip pretty much means everything else can be derived.
You might be interested in reading this excellent introductory article on folds, which are Haskell's equivalent to what some languages call reduce: http://www.cs.nott.ac.uk/~gmh/fold.pdf It shows how many of the basic higher-order functions (such as map, filter, etc) can be derived from a fold. e

On Sat, Jun 7, 2014 at 8:40 AM, Erik Price
On Saturday, June 7, 2014, Richard Seldon
wrote: Hello,
I have a general question, not specific to Haskell although I am learning Haskell as I ask this question..
Please can someone provide consensus on the most important functional methods in their view.
I read somewhere that having map, reduce, filter, mergeAll, and zip pretty much means everything else can be derived.
You might be interested in reading this excellent introductory article on folds, which are Haskell's equivalent to what some languages call reduce:
http://www.cs.nott.ac.uk/~gmh/fold.pdf
It shows how many of the basic higher-order functions (such as map, filter, etc) can be derived from a fold.
e
In fact, concatMap (flatMap) is defined like so: -- | Map a function over a list and concatenate the results.concatMap :: (a -> [b]) -> [a] -> [b]concatMap f = foldr ((++) . f) []

On Sat, Jun 7, 2014 at 10:51 AM, Richard Seldon
Hello,
I have a general question, not specific to Haskell although I am learning Haskell as I ask this question..
Please can someone provide consensus on the most important functional methods in their view.
I read somewhere that having map, reduce, filter, mergeAll, and zip pretty much means everything else can be derived.
One of the classic papers that gives a good framing to this question is the bananas lenses paper: http://eprints.eemcs.utwente.nl/7281/01/db-utwente-40501F46.pdf

Hello, Rustom, On 2014-Jul-02, Rustom Mody wrote:
On Sat, Jun 7, 2014 at 10:51 AM, Richard Seldon
wrote: Hello,
I have a general question, not specific to Haskell although I am learning Haskell as I ask this question..
Please can someone provide consensus on the most important functional methods in their view.
I read somewhere that having map, reduce, filter, mergeAll, and zip pretty much means everything else can be derived.
That's a good start, but I think it deals only with applying a function to every element in a list, and while lists are certainly important, there are many other data structures. In Haskell, reduce is called foldl or foldr, depending on the direction. I'm not familiar with mergeAll. There's a nice set of functions for lists in the module Data.List: http://www.haskell.org/ghc/docs/latest/html/libraries/base-4.7.0.0/Data-List... Now what about the functions to be applied to lists? The id, const, compose (.), and flip functions are handy for creating just the function you need. See the Prelude "Miscellaneous functions": http://www.haskell.org/ghc/docs/latest/html/libraries/base/Prelude.html#g:9 So also is partial application, for example, (+ 3) is a function which adds 3 to its argument. Lists are an instance of the Functor class, which defines a method fmap which is a genealization of the map function. http://www.haskell.org/ghc/docs/latest/html/libraries/base-4.7.0.0/Data-Func... Lists are also an instance of the Monad class, which defines generalizations of some of the other functions you mentioned (mapM, filterM, etc.): http://www.haskell.org/ghc/docs/latest/html/libraries/base-4.7.0.0/Control-M...
One of the classic papers that gives a good framing to this question is the bananas lenses paper:
http://eprints.eemcs.utwente.nl/7281/01/db-utwente-40501F46.pdf
_______________________________________________ Beginners mailing list Beginners@haskell.org http://www.haskell.org/mailman/listinfo/beginners
-- Gregory D. Weber, Ph. D. http://mypage.iu.edu/~gdweber/ Associate Professor of Informatics Tel (765) 973-8420 Indiana University East FAX (765) 973-8550
participants (5)
-
Erik Price
-
Gregory Dean Weber
-
Patrick Mylund Nielsen
-
Richard Seldon
-
Rustom Mody