Convenience in Haskell: Ergonomics of Cabal

It was a big barrier to learning haskell for me. As I started to trying to work on projects that required packages, it was really frustrating to get stuck for hours trying to figure out how to get dependencies imported in my project.

I was already intimidated by the language but then to have to make an abrupt pause on actually learning haskell and pivot to taking a deep dive into the cabal docs to do something that should be relatively trivial; it was very discouraging.

Not that good documentation couldn’t have remedied the issue, but having a user friendly tool adds that nice little bow on top that says:
ā€œthis is a mature and easy to use languageā€.

Where as the current state of affairs says:
ā€œHaskell is such a hard language that even using the package manager is tough!ā€. Even with good documentation, having to edit the file directly may still have a similar effect - it could go a long way though im sure.

But in terms of documentation, a simple tutorial that takes you through initializing a cabal project, adding deps to build-depends, and stating the requirement to add every new local haskell file to either other-modules or exposed-modules would probably go a long way all on its own. Maybe I can contribute one for the good of the order. I think I’m decent at writing tutorials

8 Likes

(I think probably 3 and 4 should be 4 and 5?)

3 Likes

Let’s not forget that the title of this thread is ā€˜Convenience in Haskell’. The whole reason I originally started this conversation was because I think these kinds of minor but convenient changes are really helpful for the ecosystem.

6 Likes

Good to hear different points of view. I can somehow empathize with you. I had a hard time trying to understand the stanzas/components in cabal (executable, library, etc…). As far as I know cabal is quite opinionated in this regard, and I think is clearly underdocumented.

This is the point I think is more important. If you try to use a Module not in scope cabal fails with a rather clear message something in the line of:

Module XX.YY belongs to package ā€œpkg-nameā€, you may want to add it to build-depends in your cabal file

I don’t see how something like cabal add would help with this. How much different is from the hypothetical error

Module XX.YY belongs to package ā€œpkg-nameā€, you may want to run cabal add lib:my-package pkg-name

Is it much better? honest question.

That being said, having a good front-page with guides like ā€œHow to do Xā€ would be much better resource than a command line utility.

If you do, consider joining forces with issue #9214 in the cabal repo (linked in my previous post)

Sure!, Actually I disagree with myself in that post :sweat_smile: I just want to play a counterpoint role to really understand if new commands are missing, or good documentation for existing command is.

This is a good point. I don’t totally remember the state of the world when I was learning haskell, but if I recall correctly, I think that error message has improved a lot.

I don’t remember it being stated so clearly when I was learning. But maybe it always was that way - if it really has always had such a clear error message, then that either shows that it’s easy to miss the message, or I was too immature to sit still and read the compiler error (which is totally possible lol).

I think it really is better! There’s so much less room for error here. I know the steps of the ā€œadd it to your build-dependsā€ version should maybe be obvious, but this version avoids assumptions that the user knows:

  1. Which file is the cabal file
  2. What build-depends is
  3. What targets/components are (e.g executable vs lib vs test)
  4. The basic syntax of a cabal file in general

It’s not hard to learn, but it’s a little intimidating. One might argue that users struggling with the above points don’t deserve our sympathies, ā€œjust rtfmā€, but it’s still a detour from getting your project running, and people learning haskell are already juggling so many new concepts in their head, so i could see them struggling here (as I did). Plus the cabal add version probably gets automated into IDE functionality later on anyways - even better!

Ive downloaded Bodigrim’s cabal-add program and it’s been awesome. I use it all the time now, it’s very convenient and nice haha (and I don’t even struggle with using cabal files anymore)

3 Likes

…and it gets better: with the arrival of the new external command system, you can use cabal-add like any other existing cabal option:

# cabal add ...

Moreover, the ECS has the potential to help provide that better user experience while still serving the needs of power uses, by allowing existing integrated options to be ā€œfloated outā€ as their own commands:

  • Power users can then call those specific cabal-$TASK commands directly as needed in their own custom scripts;

  • New users rely on cabal to invoke those commands as needed for the various ā€œcommon tasksā€ , the ones which can be easily automated.

What a nice separation of concerns!

3 Likes