hpack-dhall: hpack's dhalling

[ bsd3, development, library, program, public-domain ] [ Propose Tags ]

Work with hpack's top-level fields in a Dhall record with the following executables;

  • with dhall-hpack-cabal write the .cabal for a .dhall package description.

  • with dhall-hpack-dhall show the package description expression, with imports resolved.

  • with dhall-hpack-json show the package description as JSON.

  • with dhall-hpack-yaml show the package description as YAML.


[Skip to Readme]

Modules

[Index] [Quick Jump]

Downloads

Maintainer's Corner

Package maintainers

For package maintainers and hackage trustees

Candidates

  • No Candidates
Versions [RSS] 0.1.0, 0.2.0, 0.3.0, 0.4.0, 0.5.0, 0.5.1, 0.5.2, 0.5.3, 0.5.4, 0.5.5, 0.5.6, 0.5.7
Change log changelog.md
Dependencies aeson, aeson-pretty, base (>=4 && <5), bytestring, dhall (>=1.18.0), dhall-json (>=1.2.4), filepath, hpack (>=0.31.0), megaparsec (>=7.0.1), microlens, optparse-applicative, prettyprinter, text, transformers, yaml [details]
License BSD-3-Clause
Copyright © 2018 Phil de Joux, © 2018 Block Scope Limited
Author
Maintainer Phil de Joux <phil.dejoux@blockscope.com>
Category Development
Home page https://github.com/blockscope/hpack-dhall#readme
Bug tracker https://github.com/blockscope/hpack-dhall/issues
Source repo head: git clone https://github.com/blockscope/hpack-dhall
Uploaded by philderbeast at 2018-10-29T19:45:17Z
Distributions
Executables dhall-hpack-yaml, dhall-hpack-json, dhall-hpack-dhall, dhall-hpack-cabal
Downloads 4143 total (43 in the last 30 days)
Rating (no votes yet) [estimated by Bayesian average]
Your Rating
  • λ
  • λ
  • λ
Status Docs available [build log]
Last success reported on 2018-10-29 [all 1 reports]

Readme for hpack-dhall-0.4.0

[back to package description]

hpack-dhall

Build Status hackage release Dependencies of latest version on Hackage

Haskell package descriptions in Dhall.

This package named hpack-dhall as described in package.dhall.

{ name =
    "hpack-dhall"
...
, library =
    { exposed-modules = "Hpack.Dhall" }
, executables =
    { dhall-hpack-cabal = ...
    , dhall-hpack-json = ...
    , dhall-hpack-yaml = ...
    , dhall-hpack-dhall = ...
    }
}

This .cabal creating executable can be run over its own package description;

> stack install --stack-yaml=stack-8.4.4.yaml
...
Copied executables to /.../hpack-dhall/__bin:
- dhall-hpack-cabal
- dhall-hpack-dhall
- dhall-hpack-json
- dhall-hpack-yaml

> __bin/dhall-hpack-cabal package.dhall
hpack-dhall.cabal is up-to-date

> __bin/dhall-hpack-cabal --force package.dhall
generated hpack-dhall.cabal

Using one of the golden tests for example, there are executables to show the dhall with the imports made as well as json and yaml equivalents;

> __bin/dhall-hpack-dhall test/golden/hpack-dhall-cabal/empty-package.dhall
{ name = "empty-package" }

> __bin/dhall-hpack-json test/golden/hpack-dhall-cabal/empty-package.dhall
{
    "name": "empty-package"
}

> __bin/dhall-hpack-yaml test/golden/hpack-dhall-cabal/empty-package.dhall
name: empty-package

By going from hpack package fields to cabal package properties, we are not required to state what can be inferred or defaulted, easing the burden of completing a package description by hand. For example other-modules can be inferred by taking the set difference between modules on disk and the set of exposed-modules.

By using an hpack-like Dhall dialect here rather than the YAML of hpack we're able to;

  • Add types to the fields.
  • Safely import from other *.dhall files.
  • Use functions.

Imports and Functions

With this safer and more capable alternative input format for hpack, we're able to simply describe the package and by using imports and functions we can do more such as configuring linting;

> cat default-extensions.dhall
{ default-extensions =
    [ "DataKinds"
    , "DeriveFunctor"
    ...
    , "TupleSections"
    , "UndecidableInstances"
    ]
}

> cat hlint.dhall
    let Prelude/List/map =
          https://raw.githubusercontent.com/dhall-lang/Prelude/35deff0d41f2bf86c42089c6ca16665537f54d75/List/map

in  let defs = ./default-extensions.dhall

in  let f = λ(s : Text) → "-X" ++ s

in  { arguments = Prelude/List/map Text Text f defs.default-extensions }

> dhall-to-yaml < ./hlint.dhall > ./.hlint.yaml

> cat .hlint.yaml
arguments:
- -XDataKinds
- -XDeriveFunctor
...
- -XTupleSections
- -XUndecidableInstances

We can pull those same default-extensions into a package description;

> cat package.dhall
    let defs = ./defaults.dhall

in    defs
    ⫽ ./default-extensions.dhall
    ⫽ { name =
          "flight-units"
    ...
      , github =
          "blockscope/flare-timing/units"
    ...
      , dependencies =
            defs.dependencies
          # [ "numbers"
            , "fixed"
            , "bifunctors"
            , "text"
            , "formatting"
            , "uom-plugin"
            , "siggy-chardust"
            ]
    ...
      }

Formatting

We can consistently format package.dhall and other *.dhall imports using dhall;

> stack install dhall --stack-yaml=stack-dhall.yaml
> __bin/dhall format --inplace package.dhall