Tuesday 19 August 2014

Data.List

I'm reading through Learn You a Haskell's section on Data.List at the moment, and fiddling around with rewriting some of the functions. 

Some are harder than others. 
transpose :: [[a]] -> [[a]] 
This one was very hard indeed. After an entire day of bashing my head against the wall, I discovered a few things I didn't know about Haskell syntax before. 

For instance, I used to think that at the end of the list, there were infinite : [] : [] : [] and so you go because if xs in (x : xs) could be infinite, why not : []? 

Things I try to do for each of the functions I'm rewriting: 

  1. I try to figure out the type on my own. So far, this one seems to go fine.
  2. I write it / bash my head against the wall. 
  3. I import QuickCheck, and write a test to compare my version versus the Data.List version. e.g. 
    • testx a l = x a l === Data.List.x a l 
    • It is incredibly handy not to have to write something to test your functions on. When I was learning C, that was rather annoying. 

No comments:

Post a Comment