Maintaining haskell programs

What I mean to say is that I think you can only have two of these three points:

  • bleeding edge experimental features
  • a guarantee that all your programs will still compile in X years time
  • a simple compiler that can be maintained by a low-budget team

Of course all three points have varying gradations, so it might be possible to strike a better balance than we do now.

6 Likes

That’s a great summary!

I cannot think of any breakage in my code because the use of extensions.

On the other hand I can think of one (minor) breakage that involved no extensions: the split of Monoid into two classes. But this was a very trivial change in my code.

1 Like

Respectfully disagree - to me it sounds like “maintainability would be much better if we all stick with GHC-8.10.7 (or older - whatever’s the latest GHC-7) and whatever Cabal/Stack that accompanies it”.

Sure, if toolchains did not change, and existing packages’ API didn’t change - maintaining Haskell apps would be a breeze. Unfortunately, that’s not the case. “And if wishes were wings - . . .”

39 years of software development make me think that language extensions are a likely source of maintainability issues. It’s analogous to the maintainability issues for C++ (and other “large” languages) for teams above a certain size. Small teams can decide on, and police, the set of language extensions they use. But this doesn’t work so well in large teams, especially if there is a lot of turnover over time.

2 Likes

What about language extensions does this exactly? As a manager or whatever, I guess I see how it can run afoul of the “engineers are cogs who should be able to get run over by buses” philosophy. But from a technical standpoint, I don’t get how a module being able to turn on LambdaCase, ImplicitParams, LinearTypes, DataKinds, TypeFamilies, etc is gonna be any worse than a project having a messy dependency graph or being untestable (way more common of problems + language agnostic).

4 Likes

I agree that messy dependency graphs and untestable code are also likely to make Haskell code unmaintainable, but, as you point out, these are language agnostic. Language extensions, especially if many of them are used inconsistently across a large project, could greatly increase the difficulty of understanding and modifying the code. I suspect that as more and more extensions come into existence, it might even be possible for a large project to become arbitrarily unmaintainable. Lsmor pointed out some specific difficulties.

1 Like

Maybe it would be helpful to give a concrete example of a program that rotted due to using extensions? Because I’ve never seen a concrete example of a GHC extension actually causing maintenance problems.

When I was new to Haskell, extensions were odd. But is there one (even the most onerous) that is actually some scary problem for a professional software developer? They’re well documented, tightly scoped, and the worst case is the code doesn’t compile in most cases (I guess this is where people tell their RecordWildCard shadowing horror stories :laughing:)

And like I said, “more cognitive load” isn’t a maintenance problem. One more new concept/syntax/whatever doesn’t constitute a “maintenance problem.” I can easily flip the arrow and call it an attitude problem.

Haskell does have costs due to its (good imo) willingness to bork backwards compat. Avoid (success at all costs) and whatnot. That is the “maintenance problem” in my eyes. And it’s trivial and mechanical to work through.

2 Likes

Lots of packages were broken for a long time on 9.0 (many even skipped 9.0 altogether) due to the simplified subsumption changes to the RankNTypes extension.

1 Like

In @Underlap assumption (“for teams above a certain size”), this might well be a problem.

Small teams can develop a cohesive communication strategy and establish a set of shared techniques from which to pick from while developing. The bigger the team (or the more fractured the team), the greater the risk of ending up in a Tower of Babel, where developer from team α has problems understanding the lingo of developer from team β.

Code is written once and read many times; friction is a cost.

5 Likes

that is actually some scary problem for a professional software developer

One language extension that terrifies “Probie the software engineer” (but not “Probie the hacker”) is ImportQualifiedPost.

1 Like

Why is that?



Ok, full disclosure, I’m relatively new to Haskell. I don’t have an example project that’s unmaintainable because of extensions. Hence my guarded language (“likely”, “could”).

But my concerns are backed up by some practical experience. I wanted to contribute to a Haskell project (nameless, to protect the innocent) and the first module I opened up used:

{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE TypeFamilies #-}

(other modules used other extensions). I hate guesswork, so I set about reading the docs for the unfamiliar extensions.

Flexible contexts didn’t seem too threatening, except that the docs were for GHC 9.0.1 and the latest docs are much terser (why?). The older docs were in a section that pointed at the paper Type classes: exploring the design space, which looked like a challenging read in itself.

Type families looked harder. The docs linked to three academic papers and then extended over several pages. The Haskell wiki page on type families was a little gentler, but still pretty off-putting.

I dare say if I regarded getting up to speed on each of these extensions as a project in its own right, I could eventually become sufficiently confident that I would then know how to work with the module in question.

Perhaps the solution is education and hiring, so that there is a sufficient pool of developers familiar with the most common extensions. But from my perspective as a seasoned programmer, that just feels like another symptom of the potential for unmaintainability.

5 Likes

ImportQualifiedPost creates a decision where neither choice matters, and yet will consume a person hour or more of the team’s time every time there’s a discussion about using it, as well as more time documenting that decision. Ok, so it only costs a few hundred dollars (which might blow out to one or two thousand dollars depending on team dynamics - I’ve been at places where bikeshedding arguments have gotten out of control), but it doesn’t feel like money well spent.

6 Likes

IME ImportQualifiedPost is fine. You enable it alongside -Wprepositive-qualified-module and you’re back to one choice.

Something like BlockArguments is far more problematic because there’s not even an hlint check for redundant $ with it, so you have potential for discussion in each code review.

5 Likes

What is folks’ opinion on BlockArguments? I am using it, but I sense it could be controversial.

1 Like

If you want to avoid an hour’s discussion on such matters I suggest an opinionated code formatter (at work we use Ormolu, and I’m very happy with it).

3 Likes

As for BlockArguments in particular:

{-# LANGUAGE BlockArguments #-}
module BlockArgsBedlam where

f :: a -> b -> Char
f _ _ = '?'

mt :: IO ()
mt = putChar '~'

mu :: Maybe Bool
mu = Just True

test1 = f do mt

test2 = f do mu

test3 = f do mt do mu

test4 = f do mt $ do mu

…which GHCi rejects:

#  ghci BlockArgsBedlam.hs
GHCi, version 9.4.4: https://www.haskell.org/ghc/  :? for help
[1 of 1] Compiling BlockArgsBedlam  ( BlockArgsBedlam.hs, interpreted )

BlockArgsBedlam.hs:17:14: error:
    • Couldn't match expected type: Maybe Bool -> a0
                  with actual type: IO ()
    • The function ‘mt’ is applied to one value argument,
        but its type ‘IO ()’ has none
      In a stmt of a 'do' block: mt do mu
      In the first argument of ‘f’, namely ‘do mt do mu’
   |
17 | test3 = f do mt do mu
   |              ^^^^^^^^

BlockArgsBedlam.hs:19:14: error:
    • Couldn't match expected type: Maybe Bool -> a1
                  with actual type: IO ()
    • In the first argument of ‘($)’, namely ‘mt’
      In a stmt of a 'do' block: mt $ do mu
      In the first argument of ‘f’, namely ‘do mt $ do mu’
   |
19 | test4 = f do mt $ do mu
   |              ^^
Failed, no modules loaded.
ghci>

So BlockArguments is just another syntactic “sugar rush” which doesn’t scale up for general use:

…less of it is usually better.

1 Like

TBH, the real drawback of language extensions is incessant arguing among engineers / developers over language extensions (which to use, whether they’re a good idea, and how they actually work).

But I agree with @Underlap; we need better documentation, specifically, tutorials, for the language extensions.

Haskell has come a long way from where every feature was essentially just documented by an academic paper, but Haskell documentation is not yet at the level where you can throw a codemonkey at it and get something that works.

Some Haskellers might feel this to be a feature, I feel this to be a bug.

2 Likes

Thank you for relating your experience – this is almost worth a separate thread.

The whole document set got restructured at 9.0, which means a lot of material ended up in unfamiliar (to me) places. (Probably the new structure is more ‘logical’; it’s the changeover that’s leaving people disoriented.) And it’s been tweaked a bit since.

Specifically the docos on FlexibleContexts hasn’t got much terser AFAICT. Are you perhaps confusing with FlexibleInstances? Which is indeed chunky, and rightfully so. I’da thought any project that uses one would use both.

Yep. And it’s not included in GHC2021/nor likely to be included in GHC20XX, so it’s not worth an ‘advanced Haskell’ tutorial that puts all these extensions together into some coherent explanatory whole.

The reason is there’s another approach in the same design space as TypeFamilies. FunctionalDependencies are older, but still widely used, and widely preferred for some purposes. (Although I suspect this is more to do with personal taste and familiarity.)

To achieve any sort of modern Haskell, your project will need one or the other; quite possibly both. (If you try to stick to one in your project, quite possibly some imports will use the other.)

I’d say Haskell is at that ‘awkward age’ between being a wild, experimental teenager and settling down with responsibilities. There isn’t (yet) the sort of corporate monoculture you get in more commercial languages.

5 Likes