background: I just quite recently went to a two-week workshop on this topic at the University of Santa Cruz:
http://arts.ucsc.edu/programs/wacm
We were taught in Common Lisp but I did my projects in Clojure. The professors showed some amazing stuff, including very sophisticated harmonizers and counterpoint generators (e.g. Gradus Ad Parnassum in code, for those of you with a music theory background). I had the most hacker knowledge of anyone there, I think; most everyone else had a strong background in music but little or nothing in terms of code.
I also built a video series on making music with CoffeeScript and JavaScript, in 2012, and a very effective breakbeat improviser in Ruby, way back in 2008. I'm not 100% satisfied with the video series, but you can see it at singrobots.com if you're curious, and I did a presentation on the breakbeat improviser which was very well-received:
http://www.infoq.com/presentations/archaeopteryx-bowkett
Kind of ancient history, though, so this next thing is more up to date. You can see a kind of rave-o-matic bassline improviser in Clojure, which is to say Clojure/Overtone code which cooks up original syncopated basslines, on GitHub:
https://github.com/gilesbowkett/markov-bass-lines
That's one of the things I wrote at this workshop. If you're interested in this stuff I HIGHLY recommend attending next year (if they continue to run it!). I might go back for a second round myself. It was a phenomenal experience.
Anyway, to finish up that blatant self-promotion bit, if you're interested in a book like this, which you'd have to pay for, but which would give you examples in Clojure, Ruby, and JavaScript (and/or CoffeeScript) instead of Haskell, my email is gilesb@gmail.com.