Except for one equation, this module provides an implementation of the function L from section 9.3 of the revised Haskell 98 Report. The missing equation is the one that requires interaction with the parser. This means that things like

let x=1 in x+x

will be correctly translated to

let {x=1} in x+x

but things like

let x=1 in x+x

that should be parsed as

let { x=1 } in x+x

will *not* be treated correctly in this implementation.

moduleL(l)whereimportHsTokens(Token(..))default(Int) -- The equations for cases when <n> is the first token:lts0@((Indentn,(p,_)):ts)ms0@(m:ms)|m==n=semip:ltsms0|n<m=vrbracep:lts0msl((Indent_,_):ts)ms=ltsms-- The equations for cases when {n} is the first token:l((Openn,(p,_)):ts) (m:ms)|n>m=vlbracep:lts(n:m:ms)l((Openn,(p,_)):ts) []|n>0=vlbracep:lts[n]l((Openn,(p,_)):ts)ms=vlbracep:vrbracep:l((Indentn,(p,"")):ts)ms-- Equations for explicit braces:l(t1@(Special,(_,"}")):ts) (0:ms)=t1:ltsmsl(t1@(Special,(p,"}")):ts)ms=layout_errorp"unexpected }"++ts-- hmml(t1@(Special,(p,"{")):ts)ms=t1:lts(0:ms) -- The equation for ordinary tokens:l(t:ts)ms=t:ltsms-- Equations for end of file:l[] []=[{-eoftoken-}]l[] (m:ms)=ifm/=0thenvrbraceeof:l[]mselselayout_erroreof"missing } at eof" -- There are the tokens inserted by the layout processor:vlbracep=(Layout,(p,"{"))vrbracep=(Layout,(p,"}"))semip=(Special,(p,";")) --eoftoken = (GotEOF,(eof,""))eof=(-1,-1) -- hmmlayout_errorpmsg=[(ErrorToken,(p,"{-"++msg++"-}"))] -- hmm

Valid HTML?