August 31, 2026

Haskell for Hobos -- Basic syntax

Don't go thinking that "#" is the comment character. It isn't. It works on line 1 as part of the "shebang" sequence to launch runghc, but only by special magic. The general way to put comments into code is by starting the line with two dashes like this:
-- This is a comment
The other important thing to know up front is that white space has meaning. This has to do with indentation indicating block structure. This is just like Python if you are familiar with things there (if not, never mind).

You will need to make peace with tabs and your editor. What you want is for your editor to never put any tabs whatsoever in the file you are editing at any time for any reason. If you press tab, that may indicate to your editor that you want to indent, but it had better just put some appropriate number of spaces into the file.

I use vim, and you can definitely configure it to do this. If you don't do this, what will happen is that some wacky mix of tabs and spaces will end up in the file. It will look just fine to you, but haskell will be throwing a fit about inconsistent indentation or who knows what. That road yields only misery and wasted time.

You have been warned.


Have any comments? Questions? Drop me a line!

Tom's software pages / tom@mmto.org