Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@roosemberth
Copy link

@roosemberth roosemberth commented Nov 26, 2022

Motivation for this MR

Every time I start working in a new Haskell project, I find myself in this
repository's README, copy one of the provided examples, but spend most of the
time removing keys I don't need. I think a simple example one can simply
'copy over' is both useful to making the tool accessible to beginners and
a practical base for experienced developers to build on.

Changes in this MR

This MR adds a short and simple example, matching the default cabal init
'Library and Executable' generation (app and test directories with
Main.hs inside them and library inside src).

Signed-off-by: Roosembert Palacios <[email protected]>
@roosemberth roosemberth marked this pull request as ready for review November 26, 2022 07:28
@roosemberth
Copy link
Author

@sol Gentle ping ^^

The following `package.yaml` describes a project with a library under `src`, an executable under `app/Main.hs` and tests under `test/Main.hs`:

```yaml
name: mylib
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps my-package would be a better dummy name, as this will produce a Cabal file for a package with more than a library component.


The following `package.yaml` describes a project with a library under `src`, an executable under `app/Main.hs` and tests under `test/Main.hs`:

```yaml
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would include spec-version: 0.36.0, to ensure modern behaviour.

name: mylib

dependencies:
- base >= 4.9 && < 5
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the basis for these bounds? The generated Cabal file will specify cabal-version: 1.12 which might imply base >= 4.4 (GHC 7.2.1 came with Cabal-1.12.0).

library:
source-dirs: src

executable:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

While executable: { ... } is strictly minimal, perhaps executables: { my-exe: { ... } } would be more useful?

- mylib

tests:
spec:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps my-test-suite or my-package-test (given what cabal init would suggest) would be a better dummy name than spec?

main: Main.hs
source-dirs:
- test
- src
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For a minimal example, why include src as a source directory for the source code of a test suite application (also given what cabal init would suggest)?

- test
- src
dependencies:
- QuickCheck
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For a minimal example, I would expect a dependency on the package itself but not QuickCheck.


## Examples

The following `package.yaml` describes a project with a library under `src`, an executable under `app/Main.hs` and tests under `test/Main.hs`:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think, strictly, (if you follow my other suggestions below):

... a package with a main library with source code under directory `src`, an
executable named `my-exe` with source code under `app`, and a test suite named
`my-test-suite` with source code under `test`:

at the Singapore Haskell meetup: http://typeful.net/talks/hpack

## Examples

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It may be worth acknowledging in the introduction that users of Stack have access to templates for projects that include package.yaml files, but users of Cabal (the tool) may find the minimal example useful.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants