[Haskell-beginners] question on layout

George Huber geohuber at verizon.net
Tue Jun 16 19:41:01 EDT 2009


Hi,

This is more of a philosophical question then anything else. 

Recently I posted a question (see " exercise 3.10 in YAHT") and now 
Rolle is encountering what appears to be the same error (see "hci 
reports "The last statement in a 'do'    construct must be an 
expression" error").  In both cases the responses have been something on 
the order of "must be the indentation". 

So...my questions are:

(1) what was the driving force behind using white-space to denote code 
blocks?  From a beginners perspective (especially coming from a strong C 
/ C++ background) this seems to add to the learning curve for the 
language, and can add a good deal of frustration.

(2) I know using layout is optional -- we can curly braces and 
semicolons (not sure what this method is called correctly), but in the 
books and sources that I have looked at this seems to be mentioned in 
passing, so I'm guessing "good haskell format" is to use layout.  And if 
this is true, is there any reason for this?  better performance? easier 
parsing?

(3) Finally, is there a book or online reference that uses curly braces 
and semicolons from the start -- maybe introducing the concept of layout 
after all the language syntax is firmly grounded?


George.

PS -- For those of you that answered my first post, I sort-of solved my 
problem.  From your conviction that there was not an error in the 
function (even though this is where the compiler was claiming it to be), 
I moved stuff around in the source file while not touching the function 
itself and the error disappeared.  Not a satisfactory solution I know, 
but for now it will do till I get the syntax of Haskell down.  Thanks 
for everyone's help.

George



More information about the Beginners mailing list