Haskell 98 Revised

Ian Lynagh igloo@earth.li
Mon, 5 Nov 2001 13:52:26 +0000


On Mon, Nov 05, 2001 at 05:02:16AM -0800, Simon Peyton-Jones wrote:
> 
> To fix this, it seems to me that all we need do is to add the following
> second clause to L
> 
>     L ({n}:ts) (m:ms)  =  { : (L ts (n:m:ms))      if n > m, (Note 3)
>                        =  { : } : L ts (m : ms)    otherwise
> 
> This makes sure that the {n} case always has an outcome, 
> and implicitly inserts { } where the layout does not increase.

The following definition also handles the case "L (t:ts) []" correctly
and ensures that {n} and <n> are never passed to parse-error:


L (t:ts) []       = L ts []               if t is whitespace
                  = error "lexeme outside of module contents" otherwise
L ({n}:ts) (m:ms) = { : (L ts (n:m:ms))   if n > m
                  = { : } : (L ts (m:ms)) otherwise
L (<n>:ts) (m:ms) = ; : (L ts (m:ms))     if m = n 
                  = } : (L (<n>:ts) ms)   if n < m 
                  = L ts (m:ms)           otherwise 
L (t:ts) (m:ms)   = } : (L (t:ts) ms)     if m /= 0 and parse-error(t) 
L (}:ts) (0:ms)   = } : (L ts ms)
L ({:ts) ms       = { : (L ts (0:ms))
L (t:ts) ms       = t : (L ts ms)
L [] [0]          = []
L [] (m:ms)       = } : L [] ms           if m /= 0



Thanks
Ian