[Haskell-beginners] Functors and Applicatives; I'm just not getting it ...

Benjamin Edwards edwards.benj at gmail.com
Sun Oct 19 08:46:46 UTC 2014


The only thing I feel to recommend given the generality of the question is to say: Pick some concrete instances of Functor, and play with them. Write a program with a failing component using 'Maybe' then see how much you can get done without pattern matching. Write a program over some lists and use fmap instead of map. Realise there isn't much more to fmap than a very general signature and some laws. See what the laws mean for the two concrete instances that you just used. Be satisfied. When you get a little further on your journey and see more interesting examples of the class you will see how useful it is. For instance most parser interfaces admit a functor instance. Which means that say you had a language with variable identifiers with a leading '$' sign followed by a string, writing a parser is super simple.  Assume 'stringVar' is a 'Parser String' that parsers an identifier and 'Var' is a new type on strings for wrapping identifiers then Var `fmap` stringVar is a 'Parser Var'. I could offer again that a functor is nothing more than a principled way to change the 'generic type' of things that look like containers of type Foo<T>, not sure if that is helpful, given your previous reading list.

I hope this offers some insight. Haskell, like any learning endeavour requires you to just mess about with it until things start to click. You will miss out on a very rich learning experience if you cast it aside. Good luck!
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/beginners/attachments/20141019/a73a171d/attachment-0001.html>


More information about the Beginners mailing list