Skip to content

Instantly share code, notes, and snippets.

@exaexa
Created November 19, 2020 16:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save exaexa/9920eb85d2bd20f4c575f2f1d307ae96 to your computer and use it in GitHub Desktop.
Save exaexa/9920eb85d2bd20f4c575f2f1d307ae96 to your computer and use it in GitHub Desktop.
data WithIndents a = Line a | Indent | Dedent deriving Show
unindent [0] [] = []
unindent (_:xs) [] = Dedent:unindent xs []
unindent is@(i:it) ss@((ci,s):st)
| ci>i = Indent : unindent (ci:is) ss
|ci==i = Line s : unindent is st
| ci<i = Dedent : unindent it ss
demo = unindent [0] [(0,"foo"),(2,"bar"),(1,"gah"),(1,"another")]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment