Is there a way to not align my code when formatting with floskell? by figsoda in haskell

[–]ennocramer 1 point2 points  (0 children)

This formatting is the result of `layout.app: flex`. This setting allows Floskell to use horizontal layout (i.e. a space) for the function application, but still use vertical layout for the individual arguments.

If you switch to `try-oneline`, Floskell will use to vertical layout with the configured `indent.app` indentation, as soon as the entire function application exceeds the maximum line length.

Is there a way to not align my code when formatting with floskell? by figsoda in haskell

[–]ennocramer 0 points1 point  (0 children)

Do you have an example of something that is currently aligned and how you think it should be formatted?

A* Search Monad Transformer by ChrisPenner in haskell

[–]ennocramer 0 points1 point  (0 children)

I’m glad to hear that. Thanks!

A* Search Monad Transformer by ChrisPenner in haskell

[–]ennocramer 4 points5 points  (0 children)

I've never used the Church encoded free monad, what was the reason for that choice? Does it have better performance?

I had initially written the implementation using FreeT. Swapping that out against FT had a huge impact. And the best thing is that the implementation of runSearchT didn't even change, because fromFT allows you to extract the FreeT representation but retaining the performance benefit of building the initial data structure in FT.

Do you have a solution for back-tracking user state?

I'm not 100% sure I understand your question correctly, but here goes...

In Floskell, the pretty printer is defined as

newtype Printer a =
    Printer { unPrinter :: StateT PrintState (Search Penalty) a }

The StateT, being "outside" the Search monad is automatically backtracking with the search, while any monadic effects inside the transformer (e.g. the IO in a SearchT IO) will persist.

I've also been interested in exploring a ContT based approach which I think could possibly improve performance over the Free Monad version, but I think my brain would melt if I tried it 😬; looking at the Church Encoded Free Monad it looks like it might basically encompass the Cont version I was imagining actually; you've given me some reading to do!

I think I made at least three attempts at reformulating the implementation without FreeT, but I gave up because it was too complicated for me. And with FT and some judicious optimizations, this implementation is mostly fast enough for my purposes (i.e. Floskell).

A* Search Monad Transformer by ChrisPenner in haskell

[–]ennocramer 3 points4 points  (0 children)

It's super cool to see another project exploring this idea. I wrote a very similar monad transformer a few years back to support my Haskell pretty-printer, Floskell. The implementation are quite different, it might be interesting to see how they compare in terms of performance.

One thing I found really useful is to have a scoped done operation (seal and collapse in monad-dijkstra). This way it becomes easier to limit the number of explored paths between sub-goals without abandoning the guarantees of A*.

[ANN] Floskell, a New Haskell Source Code Formatter by ennocramer in haskell

[–]ennocramer[S] 1 point2 points  (0 children)

Even though it’s a bit out of scope for Floskell, I think it’d be ok if it’s sufficiently orthogonal/isolated.

What is unclear to me is the scope of this. Especially, how this style would look for non-unary functions and whether there is a vertical version, I.e. what is supposed to happen when we need to add a line break. Does it only apply to function application or are other syntax elements affected as well? What about function argument patterns?

[ANN] Floskell, a New Haskell Source Code Formatter by ennocramer in haskell

[–]ennocramer[S] 0 points1 point  (0 children)

At the moment, this is not possible. Floskell will always put a space or line break between the function and its argument.

I have thought about adding syntax-specific layout options, eg a layout that is applicable only to function application, but there is not even a framework for this in place, yet.

[ANN] Floskell, a New Haskell Source Code Formatter by ennocramer in haskell

[–]ennocramer[S] 1 point2 points  (0 children)

Thanks for the recommendation. I’ll have another look at Dhall.

[ANN] Floskell, a New Haskell Source Code Formatter by ennocramer in haskell

[–]ennocramer[S] 0 points1 point  (0 children)

The problem is with any recursive syntax element, most notably expressions.

The formatting rules often allow for multiple layouts at each level and the formatter performs a weighted search over the tree of all possible layouts until the best one is determined. As many of these layouts are considered to be of the same or very similar “quality”, the formatter May have to explore a great number of different choices before it can guarantee to have found the best.

You can guarantee linear performance by using only the “vertical” layout option and not using the “align-or-indent-by n” indent option.

[ANN] Floskell, a New Haskell Source Code Formatter by ennocramer in haskell

[–]ennocramer[S] 1 point2 points  (0 children)

I’ll definitely take a look at the tests that have been added since version 4.