Article View: comp.lang.functional
Article #735Off-side rule and Haskell
From: John C. Peterson
Date: Tue, 15 Jan 1991 02:34
Date: Tue, 15 Jan 1991 02:34
29 lines
1857 bytes
1857 bytes
I'm not very familiar with Miranda, but I can speak up for what Haskell
does with layout, which is our equivalent of the off-side rule.
In Haskell a declaration list is enclosed within curly braces ({ }) and
declarations in the list are separated by semicolon (;). The use of
these can be avoided by using layout (proper indentation of
declarations). Moreover, layout-sensitive and -insentsitive styles of
coding can be freely mixed in a Haskell program.
Layout is not linear (cannot be recognized by regular expressions),
but it is context-free (you can write a push-down automata that
recognizes the layout rule).
In our Haskell compiler, we implement layout as a step between the
lexer and the parser. The lexer and parser are as defined in the
Haskell Report; between them is the layout processor which
inserts additional delimiters into the token stream. The layout
processor has to handle certain tokens differently according to the
syntactic category to which they belong; in general, the layout
processor must understand the matching of all delimiting pairs of
tokens in the language. Haskell treats tab characters correctly.
One advantage of this approach is that the fully delimited program can
be viewed when layout errors occur. Finding and correcting layout
problems is usually trivial.
John Peterson
Yale Haskell Project
peterson-john@cs.yale.edu
Technical Details
Message-ID:
<PETERSON-JOHN.91Jan14213452@object.cs.yale.edu>Path:
arc1-ca.pugleaf.net!utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!yale!cs.yale.edu!peterson-johnShow Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!yale!cs.yale.edu!peterson-john From: peterson-john@cs.yale.edu (John C. Peterson) Newsgroups: comp.lang.functional Subject: Off-side rule and Haskell Message-ID: <PETERSON-JOHN.91Jan14213452@object.cs.yale.edu> Date: 15 Jan 91 02:34:52 GMT Sender: news@cs.yale.edu Distribution: comp Organization: Yale Haskell Project Lines: 29 Nntp-Posting-Host: object.systemsz.cs.yale.edu