Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How does Haskell scrap the boilerplate?

Tags:

haskell

I am trying to wrap my head around this article:

http://www.haskell.org/haskellwiki/Scrap_your_boilerplate

Even though I know what fmap is and what a functor is (thanks to "Learn you a haskell for great good"), I am unable to understand this article. Can somebody explain to me in simple terms how Haskell scraps the boilerplate?

like image 868
Salil Avatar asked Sep 12 '11 03:09

Salil


2 Answers

If you're new to haskell, you probably shouldn't worry at all about SYB. It's not something fundamental or even commonly used (I've never used it myself).

SYB is a library package for Haskell, not part of Haskell itself or even one of the base libraries. See here: http://www.cs.uu.nl/wiki/GenericProgramming/SYB

You may want to read through (the last paper in) http://research.microsoft.com/en-us/um/people/simonpj/papers/hmap/

like image 156
sinelaw Avatar answered Nov 04 '22 17:11

sinelaw


http://foswiki.cs.uu.nl/foswiki/GenericProgramming/SYB may be a better resource to read about SYB (a few of the links are broken because some things on haskell.org have changed urls, but the rest work).

To generally answer your question, here's a quote from the main page:

Datatype-generic programming

Datatype-generic programming consists of defining functions on the structure of datatypes, rather than on a datatype itself. In this way, one can define functions that work for many different datatypes.

In SYB, the structure of datatypes is not directly exposed to the programmer. Instead, generic combinators are used to define the generic functions. These combinators are implemented using fundamental functions from the Data and Typeable classes.

like image 37
Amber Avatar answered Nov 04 '22 15:11

Amber