tweag / ormolu

A formatter for Haskell source code
https://ormolu-live.tweag.io
Other
938 stars 83 forks source link

Support for literate Haskell #1081

Open Alecton4 opened 6 months ago

Alecton4 commented 6 months ago

Is your feature request related to a problem? Please describe. Looks like ormolu does not support literate Haskell, see details.

Describe the solution you'd like Able to format literate Haskell.

Describe alternatives you've considered N/A

Additional context I'm new to Haskell so not familiar with the tooling. I guess there's certain reasons we do not support literate Haskell? If so, are there other tools can be used?

amesgen commented 6 months ago

Thanks for the suggestion! I think implementing support for Literate Haskell should be feasible (ie as supported by the unlit program shipped with GHC), such that eg

# A Literate Haskell File

Some imports

> import B
> import A

Very interesting code:

> data A   =   B

is formatted to

# A Literate Haskell File

Some imports

> import A
> import B

Very interesting code:

> data A = B

Is that what you are having in mind?

Alecton4 commented 6 months ago

@amesgen Yes! Formatting the code parts in literate Haskell is exactly what I mean, sorry for not clearly specifying it. BTW, may I ask the reason why this snippet

> import A
> import B

should be formatted to this one?

> import B
> import A
amesgen commented 6 months ago

Ah, thanks for pointing that out, that was just a mistake, it should be exactly reversed, I edited the comment :+1: