[Haskell-beginners] Most important Functional Methods
Gregory Dean Weber
gdweber at iue.edu
Thu Jul 3 18:32:38 UTC 2014
Hello, Rustom,
On 2014-Jul-02, Rustom Mody wrote:
> On Sat, Jun 7, 2014 at 10:51 AM, Richard Seldon <arcseldon at gmail.com> 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.htmlhttp://www.haskell.org/ghc/docs/latest/html/libraries/base-4.7.0.0/Data-List.html
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-Functor.html
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-Monad.html
>
>
> 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 at 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
More information about the Beginners
mailing list