unisonweb / unison

A friendly programming language from the future
https://unison-lang.org
Other
5.73k stars 265 forks source link

Complex formula has operators with too much unindent. #2262

Closed philderbeast closed 2 months ago

philderbeast commented 3 years ago

I'm porting Vincenty's inverse solution to unison that I already have in Haskell and F#. I've added a .flight.Geodesy.Vincenty.inverse function to the codebase with ucm but when I ask to edit it, some math formulae fail to render in the scratch file in a way that compiles. I won't paste the whole function here, just the snippets that are rendered badly. I've shown them as diffs with the edits I had to make to get them accepted by the compiler.

-        A =
-            1.0
-          + (  u²
-            / 16384.0
-            * (4096.0 + (u² * (-768.0 + (u² * (320.0 - (175.0 * u²)))))))
+        A =
+            1.0
+                + (  u²
+                  / 16384.0
+                  * (4096.0 + (u² * (-768.0 + (u² * (320.0 - (175.0 * u²)))))))
-        y =
-            cosσ
-          * (-1.0 + (2.0 * cos²2σm))
-          - (  B
-            / 6.0
-            * cos2σm
-            * (-3.0 + (4.0 * sin²σ))
-            * (-3.0 + (4.0 * cos²2σm)))
+        y =
+            cosσ
+                * (-1.0 + (2.0 * cos²2σm))
+                - (  B
+                  / 6.0
+                  * cos2σm
+                  * (-3.0 + (4.0 * sin²σ))
+                  * (-3.0 + (4.0 * cos²2σm)))

I tried for a minimal reproduction but this was reformatted as a single line addition so I'm not sure why unison is respecting lines of formula in one case and not in the other.

# scratch.u
A =
    1.0
        + 2.0

# ucm
    ⍟ These new definitions are ok to `add`:

      A : Float

.> add A

  ⍟ I've added these definitions:

    A : Float

.> edit A

  ☝️

  I added these definitions to the top of /Users/pdejoux/dev/src/blockscope/flat-earth/scratch.u

    A : Float
    A =
      use Float +
      1.0 + 2.0

  You can edit them there, then do `update` to replace the definitions currently in this namespace.
aryairani commented 2 months ago

I think this has been fixed, @philderbeast.

Currently they render as:

A : Float
A =
  use Float * + - /
  1.0
    + (u²
        / 16384.0
        * (4096.0 + (u² * (-768.0 + (u² * (320.0 - (175.0 * u²)))))))

y : Float
y =
  use Float * + - /
  cosσ
    * (-1.0 + (2.0 * cos²2σm))
    - (B / 6.0 * cos2σm * (-3.0 + (4.0 * sin²σ)) * (-3.0 + (4.0 * cos²2σm)))

Line breaks are still ignored by design, but the unindent seems to be fixed.