Giter Club home page Giter Club logo

Comments (1)

shwestrick avatar shwestrick commented on May 25, 2024 1

Revisiting this now that smlfmt is quite a bit more mature.

Re: don't move independent code? I think in practice this is really really difficult to accomplish without making huge sacrifices to average code readability.

As for our current handling of infix expressions, I think it's generally pretty good, but could use some improvements. Here's the current output for the above example:

val _ =
  f x
  +
  case g x of
    nil => 0
  | x :: xs => x + List.length xs

Here's also a real-world example from the smlfmt source, showing a fairly complex expression with multiple occurrences of an infix operator <&>:

val checker =
at #left equal_tok <&> at #right equal_tok
<&> at #delims (Seq.equal equal_tok)
<&>
at #elems (Seq.equal
(at #lab equal_tok <&> at #colon equal_tok <&> at #ty equal_ty))

This generally seems pretty good, but I think it could be improved. For example, here's an instance I find tricky to parse because it's easy to miss the <&> at #delims ... buried in the middle:

val checker =
at #exp equal_exp <&> at #handlee equal_tok
<&>
at #elems (Seq.equal
(at #pat equal_pat <&> at #arrow equal_tok
<&> at #exp equal_exp)) <&> at #delims (Seq.equal equal_tok)
<&> at #optbar (equal_op equal_tok)

I would prefer for it to be formatted like this.

val checker =
  at #exp equal_exp <&> at #handlee equal_tok
  <&>
  at #elems (Seq.equal
    (at #pat equal_pat <&> at #arrow equal_tok
     <&> at #exp equal_exp))
  <&> at #delims (Seq.equal equal_tok)  (* on its own line *)
  <&> at #optbar (equal_op equal_tok)

This seems doable. One idea to try: ensure that, as soon as an element of an infix-chain requires a new-line to align, then all later <op> <exp> ... elements of the chain will be put on their own new-line as well.

from smlfmt.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.