Path: utzoo!attcan!uunet!wuarchive!kuhub.cc.ukans.edu!kinnersley From: kinnersley@kuhub.cc.ukans.edu (Bill Kinnersley) Newsgroups: comp.lang.functional Subject: Re: "Off-side rule" Message-ID: <27854.27905aa5@kuhub.cc.ukans.edu> Date: 13 Jan 91 19:03:33 GMT References: <22307@rouge.usl.edu> <1991Jan10.111559.12440@odin.diku.dk> <27793.278c3bb0@kuhub.cc.ukans.edu> <1991Jan11.100048.3121@odin.diku.dk> Organization: University of Kansas Academic Computing Services Lines: 27 In article , acha@CS.CMU.EDU (Anurag Acharya) writes: : : What is the justification for this "off-side" rule ? The idea of whitespace : having semantics is a potential source of inscrutable bugs and, frankly : speaking, seems to go against the grain of modern programming language : design. The concrete syntax of such a language would no longer be context-free, : let alone LR(1)/LL(1). In fact, I am hard pressed to conceptualize an : efficient tokenizing algorithm for such languages. : : Since this rule has also been incorporated into the design of Haskell, it isn't : just historical and I am sure the designers of Haskell must have had some : reason(s) for this decision. I would like to know what benefit(s) does this : rule provide a language deisgner to trade off against the parsing : inconvenience and inelegance ? : I don't think it's really as bad an idea as you make it sound. At least two other languages use it, ABC and occam. Certainly indentation makes a program more readable, and once you've indented correctly the brackets and braces are unnecessary clutter. What's easier to spot, a missing parenthesis or a missing indentation? It's a lexical problem not a parsing problem, and it's simple. At every newline you have LEX count the leading whitespace, and emit an indent or an outdent every time it changes. --Bill Kinnersley