Skip to content

Define vsepHard #237

@michaelpj

Description

@michaelpj

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.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions