Repository navigation
Description
This repository intends to create a new Quickstart and User guide for the Cabal build tool. The Cabal team acknowledges that the current state of documents, located at cabal.readthedocs.io, serves more as a reference, and less as a guide for getting started or gathering intuition about how to effectively use the tool on projects. We would like to change this.
Tools
Rust has had a very successful, community-driven book built on mdbook, which allows users to contribute markdown to a codebase which may be compiled into a nice, legible and locally hostable book format. I propose we adopt this style, and contribute the missing content for this book in that format.
Content
There are two major areas of content that I'd like to cover:
- Quickstart. How does a user come up to speed in as quickly a manner as possible, such that they can get hacking with minimal fuss. The sample out line for this content would look something like the following:
- Installation
- Creating a project from scratch
- Working with an existing project, considering existing tooling like
stack, or otherwise. - Hello world! Building and running a small project to output. This section would probably list a small subset of useful commands.
- User guide. Given a sample project, with a contrived object, how would the user go about:
- Creating the project from scratch. Discussing naming conventions, the anatomy of a simple
.cabaland its components/vocabulary/syntax at a high level - Modifying a project: adding modules exposed or otherwise, adding dependencies, warnings, etc etc. at a high level, and discussing good practice for naming conventions and managing bounds.
- Building a project: this section could discuss the basic commands used to build a project once a selection of modules has been described, and mention
cabal.projectand localcabal.projectconfiguration commands, syntax, and multiproject management. Here, we could add some content regarding remote source repositories like git. - Testing a project
- Benchmarking a project
- Profiling a project
- Working with extra-build-tools and the more exotic parts of the
.cabalecosystem - How to package a project and work with Hackage to release
Goals
The goals of this project, in my opinion, should achieve the following:
- We want a quick reference to cite to beginners for getting up and running with a project that prints "Hello, World!" in as few commands as possible.
- We want a user-guide that can serve as a hand-holding exercise for beginners and more casual haskellers, who can follow along with a relatively simple, contrived project that slowly builds up some complexity into something publishable by the end.
- We want to delineate best practices for maintaining a cabal file, so that there is less confusion
- We want to show people how to publish and release.
- We would like people to walk away with a general understanding of how to do the most fundamental aspects of project maintenance, ranging from module additions, to testing, benchmarking, and profiling, as well as an understanding of how to work in general with dependencies, bounds, and remote source repos.
- We should aim to be as friendly and high level as possible, while also achieving these goals.
I'm interested to hear from @JonathanLorimer, @Mikolaj, @fgaz, @gbaz, and anyone else who has time to hash out an outline for this book. I'd love to have a public record here of our discussions for posterity.
Activity
JonathanLorimer commentedon Jun 11, 2021
Here are my initial thoughts:
I would love to have an involved role in this, and will spend some time over the weekend putting together my thoughts and suggestions.
soupi commentedon Jun 11, 2021
I'm very happy to see this initiative!
Do you think setting up CI for a cabal project is something that should be covered in this guide as well?
Another thing I'd be really happy to see is information on how to compile a Haskell project that can be deployed/run on other computers, maybe using static compilation and musl, ghc-musl, AppImage, or something else.
Here are a couple more articles that could be use as inspiration (they use
stackthough):emilypi commentedon Jun 11, 2021
@JonathanLorimer To your first point, absolutely. I think the more we can make a distinction between what documentation is useful for the better. The fact that the purpose of the docs on readthedocs is ambiguous is a big part of the problem. When we pipe new users to it, it's functionally useless for autodidactism! Re: Kowainik and School of FP, great finds. I'm happy to lean on them for inspiration.
@soupi Absolutely. CI is fundamental to building a project and effectively testing it as it scales. Regarding static builds, I leave that to folks who have more experience with it.
soupi commentedon Jun 11, 2021
Let me elaborate why I think static builds is an important addition: a common problem that I have is that I run ubuntu 20.04 and I want my Haskell program to run on a remote linux box that has an older version of ubuntu. This linux box is often too weak to be able to successfully compile my programs, so I need to compile it on my computer and run the executable on the remote computer. This often fails because of glibc version mismatch. This issue will also pop-up when trying to provide an executable project for download of course.
Over the years I've learned tricks to deal with it using static compilation. First with static-haskell-nix, and later with ghc-musl and even later with AppImage and hsinstall. But there may be other options I'm not aware of.
I don't know if this is something that many people run into, but I ran into it fairly early and I have a feeling there are more people that have run into it. So I would be really happy if this tutorial could address this issue, whether using static builds or not.
emilypi commentedon Jun 11, 2021
@soupi I'm happy for you to write a blurb about it, but consider scope: if we have to introduce several new tools to work it in, it may be out of scope for this being a Cabal user guide, whereas it may be more appropriate for future Haskell Book endeavors that will come down the line. I leave it up to you and other people more familiar with it to hash it out. I will not block the contributions if people write it, and it's justified! 😄
AlistairB commentedon Jun 11, 2021
I think a small note on stack vs cabal would be good somewhere in the guide. As this is a very common question from beginners. Ie. something like:
gbaz commentedon Jun 11, 2021
Disagree. This is a cabal user guide. If someone is reading it, that would be because they've already made a choice. That material is suitable elsewhere, but this guide is explicitly for a particular tool and it is important to keep its focus narrow and laser-like to be effective.
JonathanLorimer commentedon Jun 11, 2021
I know the
Haskell Schoolinitiative by the Haskell Foundation has a blog section, separate to their "lessons" where they are going to go into greater depth on particular subjects. If mdbook supports it, I think a blog post about cabal vs stack and static builds would be both considerate and helpful! But I agree that we should elide excessive content, so as not to overwhelm those just looking to "get started" with cabal.AlistairB commentedon Jun 11, 2021
I would argue that understanding alternatives to cabal is good for cabal users. It's fine if the comparison is a bit biased towards cabal. As an example I found
reqcomparing itself to alternatives very useful when selecting a http request library (this comparison has been removed in master though for some reason).More generally I think it is good for Haskell users. Perhaps this guide isn't the place? But I think it should be documented somewhere as it is key information that users currently need to get explained (in a biased way) in various Haskell forums. The standard answer to the question for beginners is 'just use stack'. A more nuanced comparison to link to would probably help cabal get users IMO.
emilypi commentedon Jun 12, 2021
@AlistairB this could be an interesting addendum, and I'm imagining a table of comparisons between things like Stack, Bazel, Hadrian, and so on. However, I do think this user guide should focus on the tool in and of itself before considering its pros and cons with other tools. It does impose a burden, wherein we have to hope that at least a few contributors are familiar with both tools in order to maintain the documentation if Stack ever changes our comparison table, and I would hope that we could come up with something Cabal-centric first, before imposing that burden.
Mikolaj commentedon Jun 12, 2021
Great ideas. I think it's fine to have an optional fluff introduction that discusses the context of cabal, such as GHC, ghcup and other ways to get cabal, Hackage, haddock, stack/LTS, CI, portability/static compilation, etc. and links to separate articles or appendixes or outside references about them. Just make sure it's in italics and otherwise obviously skippable for a person that googles for how-to-do-x and that the most common workflow howtos are at the start, perhaps in TL;DR version, again linking to a section describing the same in detail. Ideally the context fluff and the TL;DR versions would be immutable as tools change (e.g., the CI landscape changes often), while the in-detail articles would play the catch-up game.
One more note to put in the fluff: the text tries to be up to date wrt newest published cabal version (if you agree that's the right policy; let's link to download for that version) and doesn't branch out into how it was done previously (with a possible exception of "since 3.4" or "deprecated" or similar annotations, but I think even those fit more a command reference, not a user guide).
Lastly, I'm personally a fan of copy-paste programming and especially copy-paste learning, so I would not avoid front-loading the reader with a large .cabal file (to be copy-pasted from the guide, or even better, generated easily from
cabal init) and then, slowly, as needed, guiding the user through modifying the file, explaining bits and pieces on the way. Just comfort the user that it's fine not to understand everything from the start. This is in contrast to a long series of larger and larger toy .cabal files, or fragments thereof. IMHO it's easier to modify a section of the file than to create a new section (panic! where? at the start? in the middle of another section? use colon? comma? is whitespace meaningful?).JonathanLorimer commentedon Jun 13, 2021
I took a first run at coming up with a content structure.This was informed by @emilypi 's original post as well as the existing cabal user guide, kowainik's blog post, and school of fp's blog post. I created a summary of the topics covered by all three here.
With regards to emily's original post, I figure the
New To Cabalsection will function as the quick start guide, and theLeveling Upsection will be the user guide, andGetting Fancycan dive into more advanced and less common use cases. I tried to come up with fun names, that are less charged thanBeginnerIntermediateandAdvanced. I also feel like the names I chose work semantically, I consider myself not-a-beginner but I could see myself using theNew to Cabalsection if I haven't bootstrapped a project in a while. All that said, I am not attached to these names and they could just as well be labelledQuick StartandUser Guide.I think that a single example project can live in this repo, and we can use different directories to demonstrate the progression of the project as the cabal setup is expanded and improved. I was thinking that these different stages could correspond to different sections of the guide (i.e. a directory called
0_Initthat just has a minimal cabal setup, then1_BasicPackagethat has basic package properties, then2_Librarythat includes a library and some source code, etc etc)Content
Preamble
cabal-install,Cabal, and.cabalfiles)New To Cabal
cabal initcabal init --interactiveLeveling Up
Getting Fancy
Assumptions
Ideas For Appendices
yaxu commentedon Jun 15, 2021
For me this starts in the wrong place. The outlines look like a cabal package developer guide, rather than a cabal user guide. Before I want to initialise and develop a new package, I want to install an existing one.
For me programming and using a library are not separate activities. I spend a lot of time working in ghci, as an 'end-user programmer'. To do this I want to install some libraries and use them together, to explore some idea. That said, some of those libraries I might be developing, and will want to re-install many times in the process of doing that.
I can do
cabal install --libto install or upgrade a library in this case, but I find that if I take this approach, quite soon everything breaks. From my perspective things break because cabal is buggy, but others tell me that it's because I'm not supposed to use cabal in this way. I wonder if there is a philosophical difference here..My big worry is that while the v1- commands work well for me, the v2- commands in general are not designed for my approach to using haskell. I'd be very happy if I could finally work out how to use the v2- commands to do what I want, though.
addendum
Lets have a look at the webpage for pip: https://pip.pypa.io/en/stable/
I click on 'quickstart' and get instructions for how to install and use pip to install some libraries. Once I do that I can jump into ipython and start exploring them. Great!
I'd find it a bit distressing if step one was "create a python project from scratch". Even if I click on "Python packaging user guide", the first tutorial is how to install packages, not how to make them.
gbaz commentedon Jun 15, 2021
@yaxu I wish we could write a good users guide for the workflow you describe. But as you well know, until some additional work is done on cabal proper, that v2 workflow will not be nearly as seamless as you want!
I think we should try to provide two quickstarts though, one with the package/application oriented workflow, and one with an exploratory/hacking workflow. The latter can explain making use of
cabal repl --build-dependsfor experimenting, as well as the use of cabal.project workflows for exploratory coding in a defined environment rather than app/lib development. Whencabal envfunctionality is folded into cabal-install (which I understand is now on the table) we can update that section to describe the newer/cleaner workflows now possible.rd-- commentedon Jun 16, 2021
Hello
I'm in the same position as @yaxu, i.e. my work is almost all done in the interpreter (ghci).
And I have the exact same problem, I can't work out how to get v2- to install a set of loosely inter-connected libraries and have them appear in ghci (and ghc --make).
So far I've just kept using v1- but I know at some point that won't work anymore.
It'd be super helpful to have a transition guide for this kind of work.
For instance, at the moment the way I update an existing library is to run "cabal v1-build && cabal v1-copy && cabal v1-register"
v2- doesn't seem to have either copy or register? It's not clear what to do instead.
Best,
Rohan
Ps. I recently tried to setup a system using v1- with ghc-8.10.5 and cabal-3.4.0 and it failed, with the error mentioned at:
haskell/cabal#7244
I'm a bit worried v1- will stop working before I can work out how to use v2- and I'll be stuck.
23 remaining items
Mikolaj commentedon Jun 19, 2021
A good example is the old and trusty https://github.com/haskell-CI/haskell-ci for Travis with its interactive tool that generates a Travis script that uses cabal for the heavy lifting. I'm not up to date with others (AppVeyor, github, etc.) or perhaps there is (going to be) a universal one somewhere?
rd-- commentedon Jun 22, 2021
Hello again,
Looking further into this I'm still not sure
cabal replis always a solution.One reason is that it's very slow, which is a problem if you have small haskell programs that you need to run in an interactive context.
ghciisn't terribly fast, but it's "responsive".One-fifth of a second is acceptable latency for "Select Menu Item -> Get Output" and on, whereas three seconds isn't really.
So I think a section on "How to install libraries so they can be loaded by ghci (and located by ghc --make)" would still be very useful!
Also (and I very, very much appreciate all the excellent things cabal does, it's wonderful!) I do think that for certain people in certain situations it's still nice to be able to think about Cabal as a program that's used to install Haskell libraries.
So it'd be nice to have a section in the manual that tells people how to use it that way.
Best,
Rohan
Mikolaj commentedon Jun 22, 2021
Is there a cabal issue about that? I'd like to understand why
cabal replis so much slower and why people use it by invoking it repeatedly, instead of having a long running, say, GHC API process that consumes expressions.rd-- commentedon Jun 22, 2021
I don't know if there's an issue. I did look now and couldn't see one, but there's 1414 open issues (eek!) so I might've missed it...
I don't actually use
cabal replyet, but it was suggested above as a replacement for ghci so I was looking into it.And mostly I do work in Emacs, with a long running connection to ghci.
But not always, so it's nice to have scripts that do useful things and run fast.
It does seems like (hopefully) some form of
cabal-envmay be the way forwards.But maybe this does mean, in relation to the outline @JonathanLorimer sent above, that it might be nice to have a distinct section in "New To Cabal" for this, instead of just having "Cabal Repl".
(Or perhaps making that section cover both cases and calling it something else? It's a little complicated because it's not only about the "interpreter", it's also related to whether you can use
ghc --maketo build a very simple program, or if you need to usecabalthere as well).Best,
Rohan
yaxu commentedon Jun 22, 2021
@rd-- Yes the startup delay is enough of a reason to stick with the v1- commands for me.
Perhaps there should be a transition section of the user guide that covers aspects not currently supported by v2-, that are covered by v1-, and explains how utilities like ghc-pkg relate to the different versions?
fendor commentedon Jun 22, 2021
@Mikolaj Some meta issue is here: haskell/cabal#6977
Mikolaj commentedon Jun 22, 2021
@fendor: thank you. The issue suggests the slowness comes from filesystem usage and lays out a path to working exclusively in-memory in such situations. I bumped priority of the issue, given that we'd love to get rid of v1-. Contributions are very welcome.
Edit: however, /tmp on Linux boxes is usually a virtual file system, that is, in-memory. So I'm not 100% sure of the diagnosis. May be the fs-like bookkeeping and lots of memory allocations for the files is enough of a drag (and OS syscalls and inter-process communications at various stages).
Edit2: @fgaz explains more in the issue, in particular, caching is needed.
Mikolaj commentedon Jun 22, 2021
@JonathanLorimer and dear users, from our brainstorming on IRC and haskell/cabal#6977, it seems, if
cabal replis too slow for a use case,cabal envis the best future bet (the prototype for now, the official thing once it's merged into cabal). Feedback would be very much appreciated (haskell/cabal#6481).JonathanLorimer commentedon Jun 22, 2021
I am going to add a chapter for
Cabal Envthat will remain incomplete until the feature is officially merged. I am happy to add a section in theCabal Replthat addresses slowness on startup and points toghci.I think that the cabal user guide is not necessarily the correct place for deep treatment of cabal-alternatives as they pertain to specific workflow needs (startup speeds etc.), but rather it should focus on the kinds of workflows that cabal can offer or how cabal could fit into ones workflow. Additionally I am wary to direct users to
v1commands in this guide, since they are being deprecated.rd-- commentedon Jun 22, 2021
@Mikolaj : I've left feedback (very positive!) for
cabal-envat haskell/cabal#6481 Thanks again for pointing me to it.@JonathanLorimer : A chapter on
cabal envsounds perfect. I think so long as there is a link that people can be directed to for instructions on "How to install a library so ghc/ghci can load it" then that will be perfect!I do think it's important that the manual not make it seem as if using cabal to install libraries for ghc/ghci is a particularly eccentric thing to want to do though, or that it's "for beginners" who will eventually move on to more serious things.
I think it's just a different way of working, c.f. https://discourse.haskell.org/t/state-of-the-cabal-q1-q2-2021/2548/36 (and https://mail.haskell.org/pipermail/haskell-cafe/2021-March/133676.html which that quotes).
JonathanLorimer commentedon Jun 22, 2021
@rd--
100% agree on this.
Mikolaj commentedon Jun 22, 2021
@rd--: I'm happy we are finding common ground.
To reiterate: the v1- workflow leads to cabal hell (a kind of DLL hell; users getting used to it and then as their project grows suddenly getting impossible to resolve conflicts regularly). This is why we strive to convert as many users as possible to v2- and (with
cabal env) minimize the impossible to replace remnants of v1- workflow and be very careful not to advertise them as an alternative to v2- for compiling a project (a very common workflow) or for any other workflow that doesn't need it. Thank you for cooperating with us in this long term and, so far, quite bumpy mission. I hope it's clear your (and other similar) use case is not frowned upon in any way --- however, as long as it's prone to cabal hell, we're going to be suspicious and difficult. :)Mikolaj commentedon Jun 23, 2021
BTW, it seems this will be (quite late) addressed by the new guide: haskell/cabal#6104 (Documentation: v1 to v2 migration guide). I guess we should close that ticket once the guide has a preliminary release.
Edit: I've also found a whole
cabal envproject page here: https://github.com/haskell/cabal/projects/10 and I've opened one about replacing v1- in hackage codebase (not needed for the guide, I think, but a part of the context of removing v1-) https://github.com/haskell/cabal/projects/12JonathanLorimer commentedon Jun 26, 2021
I am closing this issue because of #3 , If anyone wants new content to be included, or existing content to be altered, please submit a separate issue! Thank you to everyone who provided feedback!