Maintaining haskell programs

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

Haha I would be shocked if Haskell ever had anything resembling a programming-style monoculture in my lifetime. That’s kind of the fun part though :grin:

@AntC2 wrote:

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

I’ve started a separate thread, How to learn language extensions, for those who’ve “tuned out” this thread.

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.

My link to the latest docs for FlexibleContexts was indeed correct and nothing to do with FlexibleInstances. Shall we continue in the other thread?

2 Likes

At my last job, we did too - it was great! I really don’t like the style that Ormolu uses, but I like configuring formatters and debating said configuration even less :slight_smile:

4 Likes

I used to really dislike it but now that I’m used to it it’s no longer a question of like or dislike, it just is, and having formatting concerns off my mind is a breath of fresh air!

3 Likes

This was also my experience.

2 Likes

I don’t get the extension/formatting/codestyle/dependencies/strings/etc “choices” problem.

  • You are a sole developer. You use whatever the hell you want.
  • You are a project owner/maintainer. You use whatever you deem necessary to keep your project in a good shape.
  • You are a project contributor. You use whatever they already use in there. Don’t like something – submit a proposal, but the last word is on them.
6 Likes

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