A few days ago I was bored and stumbled across https://hackerrank.com. It’s a nice site for a programmer wanting to kill some time getting some rest from Serious Tasks. When I got even more tired and stupid, I found a task which perfectly suited my mood: FizzBuzz challenge.
Here it goes:
Write a program that prints (to STDOUT) the numbers from 1 to 100. But for multiples of three print “Fizz” instead of the number and for the multiples of five print “Buzz”. For numbers which are multiples of both three and five print “FizzBuzz”.
Pretty easy, huh? Not when you try to squeeze this task into as few characters as possible. Here comes fun!
Disclaimer: this post describes experience of a Happstack newbie.
A very simple (but already useful!) server in Happstack may be written like this:
import Control.Monad (when)
main = do
args <- getArgs
when (length args < 2) $ error "Usage: ./HelloHTTP <a directory to serve>"
simpleHTTP nullConf $ serveDirectory EnableBrowsing ["index.htm"] (head args)
This has been pretty sufficient for my simple home page for some time, but now I want logging about who is visiting the page.
Let’s do this!
There is a lot of Haskell OpenGL tutorials on the web introducing to basic OpenGL drawing in Haskell. I’ve read about a dozen of them, but none are highlighting an important issue right: how to react to user’s input? The tutorials either omit this topic, or fall back to ugly and non-idiomatic
IORefs to return data from callbacks (even the Haskell wiki goes this way). Although there is a much nicer way to handle GLUT/GLFW callbacks which is explained below.