Maintaining haskell programs

While yes BlockArguments does cause some parsing behavior to change, to me it’s a massive net-win overall. I’m afraid to say that your example is just contrived, no one would want to write that code. In fact I have no idea what it’s meant to parse as without BlockArguments. OTOH, the code I do write with BlockArguments to me remains unambiguous, just less $y. I would personally take the now unparseable code and have BlockArguments as the default, but that ship has sailed and the breakage would be too high. Agda got it right here.

7 Likes

For me Fourmolu hit the sweet spot. I also pushed back for the longest time on formatting, and as I think @george.fst said to be at ZuriHac - once you relax and let that go, you stop caring. At least, I did. I find Ormolu a bit too extreme, but

indentation: 2
comma-style: leading
import-export-style: diff-friendly
indent-wheres: true
record-brace-space: false
respectful: true
haddock-style: multi-line
newlines-between-decls: 2
fixities: []
single-constraint-parens: auto

is perfectly acceptable to me.

Honestly having a code formatter has made me more productive, because I can now just throw code at my editor, ignore the context switch about formatting (maybe hit Enter a few times because I know I’ll want something formatted over multiple lines), and then move on with real work.

8 Likes

I don’t understand what that means. What is “take the now unparseable code”?

I meant I would accept the parse error. Essentially I would like BlockArguments on by default, and I would be OK if the example @atravers gave produced a parse error. I’m not actually suggesting this though, because the breakage from changing that default would be too high.

2 Likes

You are a middle manager responsible for a slice of a very large codebase, a codebase that few understand in its entirety, you…

1 Like

While true, I’ve had good luck for doing syntactic linting using tree-grepper. Your linting rule here would be:

tree-grepper -q haskell '((exp_infix (operator) @_op (exp_do)) (#eq? @_op "$")) @e' .
2 Likes

Oh I see, you mean you would be willing to accept that @atraver’s example is unparsable in exchange for having BlockArguments be the default way of parsing. Personally I’ve always been scared of BlockArguments but enough sensible people are in favour of it that I should probably give it another look.

Well, I don’t actually remember saying that, but it certainly sounds plausible! Although despite thinking I didn’t care about formatting, I did actually spend much of late 2020 bringing Fourmolu to life because I just didn’t find Ormolu’s style palatable.

Nowadays, I really don’t ever think about formatting. But it probably helps that the Fourmolu defaults are essentially my personal preferences.

1 Like

…you say “contrived” ; I say “inspired” :-D


Really? I would have thought it would be the logical consequence of allowing a do-block to be the only (i.e. last) argument of a function call - why stop at “just one”/“this special case”?


Surely Agda doesn’t allow things like:

go do ... {- :: M1 A1 -}
   do ... {- :: M2 A2 -}
    ⋮

…if you forget to write a do, what was supposed to be two consecutive blocks will be treated as one!

Oh this is an easy one!

…you give your team budget to do the work needed to wrangle the codebase. Tests, refactoring into smaller components, etc. This isn’t even a technical or Haskell problem when you’re in that failure mode.

Also, some manager somewhere probably messed up to get you in that situation. A large codebase doesn’t have to be tangled together. At scale, you are rewarded for code units aligning with team units (monorepo or not - packages exist). This isn’t novel - Bezos figured that out two decades ago.

Sometimes you gotta go slow in order to go fast.

3 Likes

BlockArguments are not a trivial step forward in the design of Haskell. It is a big step forward. It is not only about dropping the $. Way more than that. It lets you write like so:

{-# language BlockArguments, UnicodeSyntax #-}

example = fmap
  do \x → x^2 + 1
  do [1, 2, 3]

Whenever you need to give an industrial size function a bunch of industrial size arguments, this makes life much easier. Grouping symbols that go in matching twosomes create big cognitive load because humans are bad at finding matching parentheses. You folks tried writing any JavaScript? The amount of parentheses, braces and curlies you must match soon gets overwhelming, it becomes like a mini game. Trading curlies for indentation was a good idea, and trading parentheses for indentation is the natural extension of it that makes Haskell even lighter, even easier to read.

There is also a way to trade braces for indentation — since lists are monoids and monoids are monads, we can again write do.

{-# language BlockArguments #-}

import Control.Monad.Writer

say = tell . pure

example = execWriter @[_] do
  say 'I'
  say '💛'
  say 'U'

This is handy when you have big nested list-like stuff, like say when building aeson Value values by hand, or when writing test suites with tasty. No more pain of replacing comma with bracket and bracket with comma when you want to swap the first line with another line. Compare with the bracket and comma notation:

example' =
  [ 'I'
  , '💛'
  , 'U'
  ]

How many key strokes would it take you to swap the I and the U?

This is also good for the diff size, which makes maintenance easier.

4 Likes

I’m suddenly less inclined to give it a look :sweat_smile:

1 Like

Same here:


…or

example = fmap f m where
  f = \x → x^2 + 1
  m = [1, 2, 3]

…or:

example = 
  ':'  :
  '-'  :
  '/'  :
  []

…but that “goto-goto” bug example still beats them all :-D

1 Like

With the where thing, you had to come up with 2 new names. It creates space for trivial decisions. The need to make trivial decisions makes life harder. Should it be m, or list, or xs? Names are documentation. As Ludwig Wittgenstein spoke:

What can be said at all can be said clearly; and whereof one cannot speak thereof one must be silent.

What I am saying is, you should not write names when they are meaningless.

With the list thing, you will have to tediously indent the colons for it to look good with realistic, uneven data. This is an issue of trailing delimiters. If some items are really short and others really long, trailing punctuation will look bad. I like leading delimiters because of this — when they are leading, they are aligned.

You will also have a hard time building a nested list like this — I think you will have to write some matching delimiters, either brackets or parentheses.

1 Like

What is the «goto-goto» example? Is this addressed to me?

If people have the time to debate the names of local bindings, they must have run out of bugs to remove from their respective codebase/s - well done!


That “goto-goto” example:

https://www.imperialviolet.org/2014/02/22/applebug.html

…which is a poignant example of what happens when syntactic sweetening goes too far - I dare say the majority of us have blundered into this ugly “idiom” enough times to wish vehemently that it didn’t exist.

I apologize for offending Kindaro, but I mean this literally: it would be awesome to see how a small production dialect, presumably a team under kindaro’s control, using assiduous block argument abuse, would evolve.


At this moment, the reason I’m against Lisps are more because I find the parens-infix style, even if you understand how it works, ugly and annoying to read, although I assume with practice you can be accustomed to it. Haskell, on the other hand, with whitespace + infix, can make for extremely readable programs, so any syntactical experimentation, in my view, is welcome.

1 Like

I see Wadler’s Law is popping off in this thread :face_with_hand_over_mouth:

2 Likes

Yes, Wadler’s law:

http://www.informatik.uni-kiel.de/~curry/listarchive/0017.html

…and yet people still keep asking for “niche-syntax” extensions!

But this thread is now well and truly off topic: most of the posts from here onwards:

https://discourse.haskell.org/t/maintaining-haskell-programs/7166/42

should go into their own thread. Alternately, like another recent thread:

https://discourse.haskell.org/t/hasura-migrating-to-rust/6620/114

this one probably should also be locked for the same reasons…

I think the various “off topic” tangents [1] in this thread have been the best part. Linear forums such as Discord are an old medium and letting them go off topic (on a leash) is always a fun way to socialize online. Obviously we need rules. But still :slight_smile:

[1] if you can call them that. Discussing BlockArguments and software management and code formatters sure could be argued to be on topic in a thread about Haskell software maintenance

1 Like