Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Define vsepHard #237

Open
michaelpj opened this issue Feb 28, 2023 · 0 comments
Open

Define vsepHard #237

michaelpj opened this issue Feb 28, 2023 · 0 comments

Comments

@michaelpj
Copy link

Define

vsepHard :: [ Doc a ] -> Doc a
vsepHard = concatWith (\x y -> x <> hardline <> y)

This is a missing function. We have n-ary concatenation functions for various separators: non-breaking spaces, breaking spaces, lines, softlines... but not hardlines.

vsepHard is useful when you have things that you just never want to lay out on a single line. For example, in a programming language you might define let-bindings like so

let 
  x = 1
  y = 2
in t

I always want the x and y bindings to be on separate lines. A more sophisticated version might use flatAlt to use a different syntax when grouped, but I think the simple approach of "just always break" is often useful.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant