Skip to content

Commit

Permalink
Add generically, rework doctests.
Browse files Browse the repository at this point in the history
  • Loading branch information
Daniel Díaz committed Apr 27, 2024
1 parent e78e315 commit 1ae9593
Show file tree
Hide file tree
Showing 5 changed files with 235 additions and 30 deletions.
202 changes: 202 additions & 0 deletions .github/workflows/haskell-ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,202 @@
# This GitHub workflow config has been generated by a script via
#
# haskell-ci 'github' 'red-black-record.cabal'
#
# To regenerate the script (for example after adjusting tested-with) run
#
# haskell-ci regenerate
#
# For more information, see https://github.com/haskell-CI/haskell-ci
#
# version: 0.17.20240109
#
# REGENDATA ("0.17.20240109",["github","red-black-record.cabal"])
#
name: Haskell-CI
on:
- push
- pull_request
jobs:
linux:
name: Haskell-CI - Linux - ${{ matrix.compiler }}
runs-on: ubuntu-20.04
timeout-minutes:
60
container:
image: buildpack-deps:bionic
continue-on-error: ${{ matrix.allow-failure }}
strategy:
matrix:
include:
- compiler: ghc-9.8.1
compilerKind: ghc
compilerVersion: 9.8.1
setup-method: ghcup
allow-failure: false
- compiler: ghc-9.6.3
compilerKind: ghc
compilerVersion: 9.6.3
setup-method: ghcup
allow-failure: false
fail-fast: false
steps:
- name: apt
run: |
apt-get update
apt-get install -y --no-install-recommends gnupg ca-certificates dirmngr curl git software-properties-common libtinfo5
mkdir -p "$HOME/.ghcup/bin"
curl -sL https://downloads.haskell.org/ghcup/0.1.20.0/x86_64-linux-ghcup-0.1.20.0 > "$HOME/.ghcup/bin/ghcup"
chmod a+x "$HOME/.ghcup/bin/ghcup"
"$HOME/.ghcup/bin/ghcup" install ghc "$HCVER" || (cat "$HOME"/.ghcup/logs/*.* && false)
"$HOME/.ghcup/bin/ghcup" install cabal 3.10.2.0 || (cat "$HOME"/.ghcup/logs/*.* && false)
env:
HCKIND: ${{ matrix.compilerKind }}
HCNAME: ${{ matrix.compiler }}
HCVER: ${{ matrix.compilerVersion }}
- name: Set PATH and environment variables
run: |
echo "$HOME/.cabal/bin" >> $GITHUB_PATH
echo "LANG=C.UTF-8" >> "$GITHUB_ENV"
echo "CABAL_DIR=$HOME/.cabal" >> "$GITHUB_ENV"
echo "CABAL_CONFIG=$HOME/.cabal/config" >> "$GITHUB_ENV"
HCDIR=/opt/$HCKIND/$HCVER
HC=$("$HOME/.ghcup/bin/ghcup" whereis ghc "$HCVER")
HCPKG=$(echo "$HC" | sed 's#ghc$#ghc-pkg#')
HADDOCK=$(echo "$HC" | sed 's#ghc$#haddock#')
# doctest needs ghc and ghc-pkg to be on the path.
echo $(dirname "$HC") >> "$GITHUB_PATH"
echo "HC=$HC" >> "$GITHUB_ENV"
echo "HCPKG=$HCPKG" >> "$GITHUB_ENV"
echo "HADDOCK=$HADDOCK" >> "$GITHUB_ENV"
echo "CABAL=$HOME/.ghcup/bin/cabal-3.10.2.0 -vnormal+nowrap" >> "$GITHUB_ENV"
HCNUMVER=$(${HC} --numeric-version|perl -ne '/^(\d+)\.(\d+)\.(\d+)(\.(\d+))?$/; print(10000 * $1 + 100 * $2 + ($3 == 0 ? $5 != 1 : $3))')
echo "HCNUMVER=$HCNUMVER" >> "$GITHUB_ENV"
echo "ARG_TESTS=--enable-tests" >> "$GITHUB_ENV"
echo "ARG_BENCH=--enable-benchmarks" >> "$GITHUB_ENV"
echo "HEADHACKAGE=false" >> "$GITHUB_ENV"
echo "ARG_COMPILER=--$HCKIND --with-compiler=$HC" >> "$GITHUB_ENV"
echo "GHCJSARITH=0" >> "$GITHUB_ENV"
env:
HCKIND: ${{ matrix.compilerKind }}
HCNAME: ${{ matrix.compiler }}
HCVER: ${{ matrix.compilerVersion }}
- name: env
run: |
env
- name: write cabal config
run: |
mkdir -p $CABAL_DIR
cat >> $CABAL_CONFIG <<EOF
remote-build-reporting: anonymous
write-ghc-environment-files: never
remote-repo-cache: $CABAL_DIR/packages
logs-dir: $CABAL_DIR/logs
world-file: $CABAL_DIR/world
extra-prog-path: $CABAL_DIR/bin
symlink-bindir: $CABAL_DIR/bin
installdir: $CABAL_DIR/bin
build-summary: $CABAL_DIR/logs/build.log
store-dir: $CABAL_DIR/store
install-dirs user
prefix: $CABAL_DIR
repository hackage.haskell.org
url: http://hackage.haskell.org/
EOF
cat >> $CABAL_CONFIG <<EOF
program-default-options
ghc-options: $GHCJOBS +RTS -M3G -RTS
EOF
cat $CABAL_CONFIG
- name: versions
run: |
$HC --version || true
$HC --print-project-git-commit-id || true
$CABAL --version || true
- name: update cabal index
run: |
$CABAL v2-update -v
- name: install cabal-plan
run: |
mkdir -p $HOME/.cabal/bin
curl -sL https://github.com/haskell-hvr/cabal-plan/releases/download/v0.7.3.0/cabal-plan-0.7.3.0-x86_64-linux.xz > cabal-plan.xz
echo 'f62ccb2971567a5f638f2005ad3173dba14693a45154c1508645c52289714cb2 cabal-plan.xz' | sha256sum -c -
xz -d < cabal-plan.xz > $HOME/.cabal/bin/cabal-plan
rm -f cabal-plan.xz
chmod a+x $HOME/.cabal/bin/cabal-plan
cabal-plan --version
- name: checkout
uses: actions/checkout@v3
with:
path: source
- name: initial cabal.project for sdist
run: |
touch cabal.project
echo "packages: $GITHUB_WORKSPACE/source/." >> cabal.project
cat cabal.project
- name: sdist
run: |
mkdir -p sdist
$CABAL sdist all --output-dir $GITHUB_WORKSPACE/sdist
- name: unpack
run: |
mkdir -p unpacked
find sdist -maxdepth 1 -type f -name '*.tar.gz' -exec tar -C $GITHUB_WORKSPACE/unpacked -xzvf {} \;
- name: generate cabal.project
run: |
PKGDIR_red_black_record="$(find "$GITHUB_WORKSPACE/unpacked" -maxdepth 1 -type d -regex '.*/red-black-record-[0-9.]*')"
echo "PKGDIR_red_black_record=${PKGDIR_red_black_record}" >> "$GITHUB_ENV"
rm -f cabal.project cabal.project.local
touch cabal.project
touch cabal.project.local
echo "packages: ${PKGDIR_red_black_record}" >> cabal.project
echo "package red-black-record" >> cabal.project
echo " ghc-options: -Werror=missing-methods" >> cabal.project
cat >> cabal.project <<EOF
EOF
$HCPKG list --simple-output --names-only | perl -ne 'for (split /\s+/) { print "constraints: $_ installed\n" unless /^(red-black-record)$/; }' >> cabal.project.local
cat cabal.project
cat cabal.project.local
- name: dump install plan
run: |
$CABAL v2-build $ARG_COMPILER $ARG_TESTS $ARG_BENCH --dry-run all
cabal-plan
- name: restore cache
uses: actions/cache/restore@v3
with:
key: ${{ runner.os }}-${{ matrix.compiler }}-${{ github.sha }}
path: ~/.cabal/store
restore-keys: ${{ runner.os }}-${{ matrix.compiler }}-
- name: install dependencies
run: |
$CABAL v2-build $ARG_COMPILER --disable-tests --disable-benchmarks --dependencies-only -j2 all
$CABAL v2-build $ARG_COMPILER $ARG_TESTS $ARG_BENCH --dependencies-only -j2 all
- name: build w/o tests
run: |
$CABAL v2-build $ARG_COMPILER --disable-tests --disable-benchmarks all
- name: build
run: |
$CABAL v2-build $ARG_COMPILER $ARG_TESTS $ARG_BENCH all --write-ghc-environment-files=always
- name: tests
run: |
$CABAL v2-test $ARG_COMPILER $ARG_TESTS $ARG_BENCH all --test-show-details=direct
- name: doctests
run: |
$CABAL v2-install $ARG_COMPILER --ghc-options="-rtsopts" doctest --overwrite-policy=always
$CABAL v2-repl all --build-depends=QuickCheck --build-depends=template-haskell --with-ghc=doctest --repl-options='-w -Wdefault'
- name: cabal check
run: |
cd ${PKGDIR_red_black_record} || false
${CABAL} -vnormal check
- name: haddock
run: |
$CABAL v2-haddock --disable-documentation --haddock-all $ARG_COMPILER --with-haddock $HADDOCK $ARG_TESTS $ARG_BENCH all
- name: unconstrained build
run: |
rm -f cabal.project.local
$CABAL v2-build $ARG_COMPILER --disable-tests --disable-benchmarks all
- name: save cache
uses: actions/cache/save@v3
if: always()
with:
key: ${{ runner.os }}-${{ matrix.compiler }}-${{ github.sha }}
path: ~/.cabal/store
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# Revision history for red-black-record

## 2.1.6.0
- Added ToRecord instance for Generically

## 2.1.5.0
- Added cliftA_Record and cliftA2_Record.

Expand Down
10 changes: 9 additions & 1 deletion lib/Data/RBR/Internal.hs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ import Data.Monoid (Endo(..))
import Data.List (intersperse)
import Data.Foldable (asum)
import GHC.TypeLits
import GHC.Generics (D1,C1,S1(..),M1(..),K1(..),Rec0(..))
import GHC.Generics (D1,C1,S1(..),M1(..),K1(..),Rec0(..), Generically(..))
import qualified GHC.Generics as G

import Data.SOP (I(..),K(..),unI,unK,NP(..),NS(..),All,SListI,type (-.->)(Fn,apFn),mapKIK,(:.:)(..),Top)
Expand Down Expand Up @@ -1354,6 +1354,14 @@ class ToRecord (r :: Type) where
default toRecord :: (G.Generic r,ToRecordHelper E (G.Rep r),RecordCode r ~ RecordCode' E (G.Rep r)) => r -> Record I (RecordCode r)
toRecord r = toRecord' unit (G.from r)

instance (
G.Generic r,
ToRecordHelper E (G.Rep r),
RecordCode r ~ RecordCode' E (G.Rep r)) =>
ToRecord (Generically (r :: Type)) where
type RecordCode (Generically (r :: Type)) = RecordCode' E (G.Rep r)
toRecord (Generically r) = toRecord' unit (G.from r)

class ToRecordHelper (start :: Map Symbol Type) (g :: Type -> Type) where
type RecordCode' start g :: Map Symbol Type
toRecord' :: Record I start -> g x -> Record I (RecordCode' start g)
Expand Down
42 changes: 21 additions & 21 deletions red-black-record.cabal
Original file line number Diff line number Diff line change
@@ -1,31 +1,31 @@
cabal-version: 2.0
cabal-version: 3.4
name: red-black-record
version: 2.1.5.0
version: 2.1.6.0
synopsis: Extensible records and variants indexed by a type-level Red-Black tree.

description: A library that provides extensible records and variants,
both indexed by a type-level red-black tree that maps
Symbol keys to value types of any kind.
.
The keys correspond to fields
names in records, and to branch names in variants.
.
At the term level, value types come wrapped in a type
constructor of kind @q -> Type@, where @q@ is the kind of
value types.
.
The records and variants can be converted to and from
regular Haskell datatypes; also to and from the unlabelled
n-ary products and sums of the @sop-core@ package.

license: BSD3
license: BSD-3-Clause
license-file: LICENSE
author: Daniel Diaz
maintainer: [email protected]
category: Data
extra-source-files: CHANGELOG.md,
README.md
build-type: Simple
tested-with: GHC ==9.8.1 || ==9.6.3

source-repository head
type: git
Expand All @@ -49,20 +49,20 @@ library demoted
hs-source-dirs: lib-demoted
default-language: Haskell2010

test-suite doctests
type: exitcode-stdio-1.0
hs-source-dirs: tests
ghc-options: -threaded
main-is: doctests.hs
build-depends: base >= 4.10.0.0 && < 5,
sop-core >= 0.4.0.0 && < 0.6,
red-black-record,
aeson >= 1.4.0.0 && < 1.6,
bytestring >= 0.10,
text >= 1.1,
profunctors >= 5,
doctest >= 0.16.2
default-language: Haskell2010
-- test-suite doctests
-- type: exitcode-stdio-1.0
-- hs-source-dirs: tests
-- ghc-options: -threaded
-- main-is: doctests.hs
-- build-depends: base >= 4.10.0.0 && < 5,
-- sop-core >= 0.4.0.0 && < 0.6,
-- red-black-record,
-- aeson >= 1.4.0.0 && < 3.0,
-- bytestring >= 0.10,
-- text >= 1.1,
-- profunctors >= 5,
-- doctest >= 0.16.2
-- default-language: Haskell2010

test-suite tests
type: exitcode-stdio-1.0
Expand All @@ -74,5 +74,5 @@ test-suite tests
tasty >= 0.10.1.1,
tasty-hunit >= 0.9.2,
red-black-record,
demoted
red-black-record:demoted
default-language: Haskell2010
8 changes: 0 additions & 8 deletions tests/doctests.hs

This file was deleted.

0 comments on commit 1ae9593

Please sign in to comment.