22 Apr 2007
Haskell Code Number One
So I decided to stop reading tutorials and actually try to apply some of what I’ve been learning and write my own program. I’ve been musing about doing a massively multiplayer online space strategy game so I decided to start defining simple base for that and build from there.
Functional programming is… well it’s neat. And different. I fought for a long time with almost every data definition and function I wrote, but as the hours wore on it started to feel more and more natural and I went back and re-factored a bunch of my code. In no time flat I had everything up and working great. One little problem. Something felt wrong. I wrote a function to recursively blast alterations into my list and when I checked it out it looked like it wasn’t freeing memory and keeping a copy of each list ever touched. Bummer.
I dropped into #haskell and asked for advice. Man. I got so many things I didn’t understand thrown at me, also a few compliments. Apparently for a first solo Haskell project, my code was far more Haskell like than expected. Anyways, I had a bunch of things pointed out to me to fix or improve and was introduced to the concept of thunks. Haskell has lazy computation which means it only evaluates things when it needs to. Thunks as I understand are partially evaluated computations which sit around taking up ram waiting to be useful again.
Pretty sure I have to go back to trying to learn monads better to fix it though.