FizzBuzz in Haskell


/ Published in: Haskell
Save to your folder(s)

The dread FizzBuzz question -- really, a test if your average programmer knows his or her FOR loops. The spec is that you're counting from 1 to 100. Your program should print out "fizz" if the index is divisible by three, and "buzz" if it's divisible by five, and "fizzbuzz" if it's divisible by both.

I have a couple different versions in this code: first, a few functions just fizzing or buzzing. Second, a generalization which allows any standard message against any divisor. Third, a purely functional version that zips two lists together (giving us free concatenation for "fizzbuzz"). Fourth, a list comprehension and lastly, a monadic version that calls a pure function that uses guards.

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.