Today, I learned Haskell doesn’t like tabs. Haskell apparently uses some syntax conventions to connote things like blocks. I was working my way through a Haskell tutorial when I found the following snippet of code kept getting compiler errors:
fails main = do putStr "You are? " name <- getLine greet name
Turns out you can also enclose a block in angle brackets so this code worked
compiles main = do { putStr "You are? "; name <- getLine; greet name }
Then it dawned on me. My TextMate Haskell setting were showing
1
|
Hard Tabs
|
instead of
1
|
Soft Tabs
|
with spaces. Flipping it to use spaces made the same code pass compilation.
compiles main = do putStr "You are? " name <- getLine greet name
Experimenting with lining up the arguments after the do showed that all of the statements had to line up vertically. Thus this reasonable looking syntax would fail:
fails main = do putStr "You are? " name <- getLine greet name
I’m still very much at the beginnings of digging into Haskell, but it’s nice to play around with a language purely for intellectual curiosity.