laLayout l (s:ss) (t1@(l1, n1, w1, c1) :
                   t2@(l2, n2, w2, c2) : ts)

   | w1 `elem` [Lof, Llet, Lwhere] && w2 /= Llbrace
   = t1 :
     (l1, n1, Llbrace, "{") :
     t2 :
     laLayout l2 (n2:s:ss) ts 

   | l1 == l
   = t1 :
     laLayout l (s:ss) (t2:ts)

   | n1 > s
   = t1 :
     laLayout l1 (s:ss) (t2:ts)

   | n1 == s
   = (l1, n1, Lsemi, ";") :
     t1 :
     laLayout l1 (s:ss) (t2:ts)

   | n1 < s
   = (l1, n1, Lrbrace, "}") :
     laLayout l ss (t1:t2:ts)
laLayout l (s:ss) (t1@(l1, n1, w1, c1) :
                   t2@(l2, n2, w2, c2) : ts)

   | w1 `elem` [Lof, Llet, Lwhere] && w2 /= Llbrace
   = t1 :
     (l1, n1, Llbrace, "{") :
     t2 :
     laLayout l2 (n2:s:ss) ts 

   | l1 == l
   = t1 :
     laLayout l (s:ss) (t2:ts)

   | n1 > s
   = t1 :
     laLayout l1 (s:ss) (t2:ts)

   | n1 == s
   = (l1, n1, Lsemi, ";") :
     t1 :
     laLayout l1 (s:ss) (t2:ts)

   | n1 < s
   = (l1, n1, Lrbrace, "}") :
     laLayout l ss (t1:t2:ts)
laLayout l (s:ss) (t1@(l1, n1, w1, c1) :
                   t2@(l2, n2, w2, c2) : ts)

   | w1 `elem` [Lof, Llet, Lwhere] && w2 /= Llbrace
   = t1 :
     (l1, n1, Llbrace, "{") :
     t2 :
     laLayout l2 (n2:s:ss) ts 

   | l1 == l
   = t1 :
     laLayout l (s:ss) (t2:ts)

   | n1 > s
   = t1 :
     laLayout l1 (s:ss) (t2:ts)

   | n1 == s
   = (l1, n1, Lsemi, ";") :
     t1 :
     laLayout l1 (s:ss) (t2:ts)

   | n1 < s
   = (l1, n1, Lrbrace, "}") :
     laLayout l ss (t1:t2:ts)