Yet again, another feature blocked on Cabal exact-printing abilities…
hpack worked fine for years. Proves that building tools on top of cabal works fine instead of trying to force the core design to fit your aesthetic can lead to success.
Follow hpack’s lead. I’ve noticed that cabal has a lot of drive-by opinions but not drive-by, mergeable diffs
To be honest, it sounds like you’re describing stack
What killer feature exactly did cabal reimplement? Nix-style builds were proposed and discussed before stack happened afaik (but not implemented in time).
Cabal still refuses to implement the killer feature “install GHC without asking”. And I’m happy it doesn’t.
Support for stackage? Well, that’s maybe the only thing, but in its current form it’s not very usable and boils down to just “cabal downloads a cabal.config for you”. So that hasn’t been grandiously implemented either.
So I really don’t know what you mean. Maybe backpack support? Oh wait, it’s stack that doesn’t support this.
Kinda confused here.
Sorry, I totally skipped your comment about package.yaml
, because that’s not a killer feature, it’s horrendous.
cabal-install and stack are not at different abstraction levels. They never were.
You’re maybe confusing the Setup.hs functionality with cabal-install?
But yes, I agree, cabal-install could also be structured differently. It’s poorly designed. There should be very clear separation between concerns. E.g.
- coming up with a build plan
- executing that build plan
This is implemented in some package managers as output → input pipelines. Every phase could have an output that the next tool consumes. Then you could build high abstraction cli around it more easily.
What is this principle called? People will get annoyed at me for bringing this up again, but let me try: it’s called unix principle.
That would also mean stack wouldn’t have to re-implement half of what is already in cabal-install.
And now to the question: which tool is more likely to ever achieve better such separation? It’s probably cabal-install, because stack firmly believes in batteries-include everything. It’s unlikely it will ever be modular. cabal-install is heading into that direction, very very slowly though. And maybe it’s not enough, but we can hope.
There are actually 3-4 different tools in the Haskell ecosystem, i.e, one is Haskell.Nix and related workflows, another is GHCup, another is Cabal, and the last is Stack.
Each of these tools have their own limitations:
- GHCup, for instance, does not want to build anything other than core Haskell tooling.
- Cabal is a very old tool, and the pace of work (help out!) is slower than many would like.
- Nix-based workflows require learning Nix.
- Stack will install a new GHC every time you change versions, resulting in very slow initial builds, and has an implicit conflict with GHCup.
End of the day, talk to people involved, preferably privately, on how people should go forward with this.
Not at all. Since ghcup follows strictly unix philosophy, it’s easily integratable with even stack. And we did just that by following yet another unix principle (called hooks… e.g. look at git hooks).
There:
- https://docs.haskellstack.org/en/stable/yaml_configuration/#ghc-installation-customisation
- https://www.haskell.org/ghcup/guide/#strategy-2-stack-hooks-new-recommended
Such unix.
…or for those not acquainted with “the Unix philosophy” :
As far as I had read, it seemed that cabal exact-printer was pretty complicated and still pretty far out of reach to be implemented.
I don’t think it’s very complicated; but there are lot of details and constraints to take into account when reworking the parser; starting from correctness (parse everything on Hackage in the same way) and performance (both time and memory). It’s no cowboy job if you allow me.
I have put some effort in understanding what we have and what is missing. If anybody has good engineering skills to offer, they are welcome to get in touch either on GitHub or with a DM.
RE: filewatch, I appreciate there are no current plans as such, but is it true that maintainers have no desire to add it? The thread remains open, and doesn’t contain any real arguments against, just discussions about scope and implementation difficulties. Personally, it’s something I’d love to see.
I do think you make a good point about Oleg’s comment regarding globs and how module lists are critical for other tooling. Sacrificing human ergonomics for machine ergonomics is a good sign that a phase split is needed, and it sounds like cabal sdist
can play that role.
Yeaahhh but stack is kind of weird though! It uses package sets, it downloads ghc and a bunch of stuff . It has two separate places where you specify packages:
package.yaml - where you set dependencies
Stack.yaml - where you specify extra-deps for stuff outside the package set
And it still does not provide a nice stack add <dep>
or stack remove <dep>
or any other convenience commands newcomers want to see when getting into a new language.
I’m talking more about a tool that allows the user to get by largely without having to edit the package config file at all, and that doesn’t do all kinds of extra stuff; something that’s more of a 1 to 1 translation with a cabal file, but that allows the tool to make all the changes to it.
I know the cabal package format provides for a lot of flexibility, but if I didn’t have to go in there to add dependencies, or modify other-modules/exposed-modules, I personally would likely never interface with a cabal file directly.
I’m talking about a tool that automates all those common interactions with the package file so the only thing I ever need to worry about is basically just setting package dependencies.
I know now that all of this functionality can probably be added once exact-printing/parsing is implemented, but I wasn’t sure how far off that was (or previously if exact printing could even remedy all of the concerns, such as globs in exposed/other modules), so I thought, “we just make a tool wraps cabal to get us there more easily, simple!”
The exact-printer issue seems to be a stopper but… Can anyone explain to me what is it and why would be needed for many of the things discussed here? From my perspective, Cabal
library can already parse, modify and write the cabal-spec AST, isn’t it? why something like using globs needs the exact-printer?
Cabal can parse and modify the cabal AST, but writing (print) it is the problem. The AST is abstract and does not contain exact source position information (and perhaps comments are removed too, I’m not sure). So cabal is not able to modify only a part of the file and keep the rest exactly the same.
Here’s the relevant cabal-watch ticket. `cabal watch` command · Issue #5252 · haskell/cabal · GitHub
I agree there’s no strong negatives there, but the response from the author of ghcid, which provides watch
-like functionality very well basically said “there’s no purpose to putting this in cabal,” and made a pretty compelling case as to why.
Making ghcid available as an external subcommand would allow people to type cabal watch
and get the functionality through that unified cli if they really wanted, but from a code standpoint it doesn’t seem to make sense to add a whole bunch of new logic to the cabal-install codebase when it works perfectly well as an external tool, and there’s not really any duplication of code or functionality as a result…
That assumes enough Haskellers thought the work was an improvement to begin with e.g. as noted earlier:
-
Convenience in Haskell: Ergonomics of Cabal - #25 by hasufell
-
Convenience in Haskell: Ergonomics of Cabal - #27 by hasufell
…Cabal is now something more that just a system for simply packing, unpacking and installing Haskell packages - one example being the build
option in the cabal
program, in contrast to other package managers like rpm and dpkg (which have separate rpmbuild or dpkg-deb programs respectively for that purpose), or apk (no such feature).
This would seem to be a useful reduction in complexity for Cabal, and would bring it closer to the SRP. But can enough Haskellers (including the Cabal developers) can be convinced of those long-term benefits to accept the short-term costs of transition to the new arrangement? If not, any such work would be for nothing.
rpm
, dpkg
and apk
are not comparable to Cabal, as they are not language-specific. I would argue that better comparisons would be to tools such as cargo
, pip
and npm
— all of which have rather similar feature-sets and aims to Cabal.
…that looks very much like a call for a SRP-driven “separation of concerns”:
-
cargo
- probably the closest to Cabal, with only one compiler to deal with, and its ownbuild
option. The intended arrival of the GNU Rust compiler in April of next year then poses an interesting question - willcargo
be expected to work with both implementations, or will there be an all-GNU replacement?That will require some effort in either case, but less effort will be needed if
cargo
“externalised” itsbuild
feature, as per the SRP. -
pip
- While still primarily for use with a single-implementation interpreted language, it recently had to be extended to work with “pre-generated” Python-specific byte-code. Presumably the extra code required didn’t all end up inpip
, but also went into new programs - again, guided by the SRP to some extent. -
npm
- a quick search suggest there’s been nobuild
option since version 6.14.18:
Vaguely recalling how often upgrading GHC breaks existing code the Haskell language changes, Cabal being language-specific doesn’t seem all that beneficial:
Worthwhile to recall: Cabal is an acronym for “common architecture for building applications and libraries”. The word build is right there in the name. Cabal-the-library is not a package manager, but it interoperates with one. The one it interoperates with is ghc-pkg
and that is provided by GHC itself. Cabal’s interactions with the ghc package database are intermediated through ghc-pkg, and the need to keep the notions of compiled package descriptions in sync is one significant point of coupling between Cabal and GHC.
cabal-install-the-executable with v1- commands was also not a package manager, in precisely the same way, just a build tool wrapping the build architecture of Cabal-the-library. With v2- commands it got more ambitious and became a project build tool, and extended the package-management of ghc-pkg with a more sophisticated notion of a nix-like “store”.
A useful refactor to promote logical modular division could be to try to pull out the store-interaction code from cabal-install into a library, and perhaps even pull it back into ghc-pkg itself.
May I play devil’s advocate? So far I see the following enhacenments proposed
-
cabal add
command -
cabal remove
command - blob expansion
-
cabal <cmd> --file-watch
command - suport for
yaml
format (ideally in thestack
way)
so, 1., 2. and 3. are (convenient) substitutes for edititng a plain text file… let’s be honest, desiderable but not a big deal.
then, 4. is argubly, not cabal
's duty. You have many tools (including one written in haskell) to configure your feedback loops. Even more, I am pretty sure many editors suport things like “execute cmd on save”.
finally, 5 is quite a point, but I don’t think the .cabal
format is a major stopper as it is very yaml
like.
Are these killer improvements in the developer experience?. Clearly, they make usage easier, but are these inconveniences stoppers for learning Haskell?.. I don’t think so. Probably, a better documentation would help. This initiative explain very well all the problems with cabal’s docs
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