Skip to content

FunctorWithIndex for Kleisli (now builds) #19

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 10 additions & 15 deletions .github/workflows/haskell-ci.yml
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
# This GitHub workflow config has been generated by a script via
#
# haskell-ci '--config=cabal.haskell-ci' 'github' 'cabal.project'
# haskell-ci 'github' 'indexed-traversable/indexed-traversable.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.13.20211030
# version: 0.14.2
#
# REGENDATA ("0.13.20211030",["--config=cabal.haskell-ci","github","cabal.project"])
# REGENDATA ("0.14.2",["github","indexed-traversable/indexed-traversable.cabal"])
#
name: Haskell-CI
on:
Expand All @@ -24,6 +24,8 @@ jobs:
linux:
name: Haskell-CI - Linux - ${{ matrix.compiler }}
runs-on: ubuntu-18.04
timeout-minutes:
60
container:
image: buildpack-deps:bionic
continue-on-error: ${{ matrix.allow-failure }}
Expand Down Expand Up @@ -179,6 +181,10 @@ jobs:
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: |
Expand All @@ -205,7 +211,6 @@ jobs:
run: |
touch cabal.project
echo "packages: $GITHUB_WORKSPACE/source/indexed-traversable" >> cabal.project
if [ $((HCNUMVER >= 70400)) -ne 0 ] ; then echo "packages: $GITHUB_WORKSPACE/source/indexed-traversable-instances" >> cabal.project ; fi
cat cabal.project
- name: sdist
run: |
Expand All @@ -219,20 +224,15 @@ jobs:
run: |
PKGDIR_indexed_traversable="$(find "$GITHUB_WORKSPACE/unpacked" -maxdepth 1 -type d -regex '.*/indexed-traversable-[0-9.]*')"
echo "PKGDIR_indexed_traversable=${PKGDIR_indexed_traversable}" >> "$GITHUB_ENV"
PKGDIR_indexed_traversable_instances="$(find "$GITHUB_WORKSPACE/unpacked" -maxdepth 1 -type d -regex '.*/indexed-traversable-instances-[0-9.]*')"
echo "PKGDIR_indexed_traversable_instances=${PKGDIR_indexed_traversable_instances}" >> "$GITHUB_ENV"
rm -f cabal.project cabal.project.local
touch cabal.project
touch cabal.project.local
echo "packages: ${PKGDIR_indexed_traversable}" >> cabal.project
if [ $((HCNUMVER >= 70400)) -ne 0 ] ; then echo "packages: ${PKGDIR_indexed_traversable_instances}" >> cabal.project ; fi
if [ $((HCNUMVER >= 80200)) -ne 0 ] ; then echo "package indexed-traversable" >> cabal.project ; fi
if [ $((HCNUMVER >= 80200)) -ne 0 ] ; then echo " ghc-options: -Werror=missing-methods" >> cabal.project ; fi
if [ $((HCNUMVER >= 80200)) -ne 0 ] ; then echo "package indexed-traversable-instances" >> cabal.project ; fi
if [ $((HCNUMVER >= 80200)) -ne 0 ] ; then echo " ghc-options: -Werror=missing-methods" >> cabal.project ; fi
cat >> cabal.project <<EOF
EOF
$HCPKG list --simple-output --names-only | perl -ne 'for (split /\s+/) { print "constraints: $_ installed\n" unless /^(indexed-traversable|indexed-traversable-instances)$/; }' >> cabal.project.local
$HCPKG list --simple-output --names-only | perl -ne 'for (split /\s+/) { print "constraints: $_ installed\n" unless /^(indexed-traversable)$/; }' >> cabal.project.local
cat cabal.project
cat cabal.project.local
- name: dump install plan
Expand All @@ -251,15 +251,10 @@ jobs:
- name: build
run: |
$CABAL v2-build $ARG_COMPILER $ARG_TESTS $ARG_BENCH all --write-ghc-environment-files=always
- name: tests
run: |
if [ $((HCNUMVER >= 70400)) -ne 0 ] ; then $CABAL v2-test $ARG_COMPILER $ARG_TESTS $ARG_BENCH all --test-show-details=direct ; fi
- name: cabal check
run: |
cd ${PKGDIR_indexed_traversable} || false
${CABAL} -vnormal check
if [ $((HCNUMVER >= 70400)) -ne 0 ] ; then cd ${PKGDIR_indexed_traversable_instances} || false ; fi
if [ $((HCNUMVER >= 70400)) -ne 0 ] ; then ${CABAL} -vnormal check ; fi
- name: haddock
run: |
$CABAL v2-haddock $ARG_COMPILER --with-haddock $HADDOCK $ARG_TESTS $ARG_BENCH all
Expand Down
2 changes: 1 addition & 1 deletion haskell-ci.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/bin/bash
# shellcheck disable=SC2086,SC2016,SC2046
# REGENDATA ("0.13.20211030",["bash","cabal.project"])
# REGENDATA ("0.14.2",["bash","cabal.project"])

set -o pipefail

Expand Down
6 changes: 4 additions & 2 deletions indexed-traversable/indexed-traversable.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -82,12 +82,14 @@ library

if !impl(ghc >=8.0)
build-depends:
base-orphans >=0.8.3 && <0.9
, semigroups >=0.18.4 && <0.21
semigroups >=0.18.4 && <0.21
, transformers-compat >=0.6.6 && <0.8

if (impl(ghc >=7.0) && impl(ghc <7.6))
build-depends: ghc-prim

if (impl(ghc >=7.0) && impl(ghc <7.2))
build-depends: generic-deriving ==1.14.*

if !impl(ghc >=8.10)
build-depends: base-orphans >=0.8.3 && <0.9
7 changes: 6 additions & 1 deletion indexed-traversable/src/WithIndex.hs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import Prelude
import Control.Applicative
(Applicative (..), Const (..), ZipList (..), (<$>), liftA2)
import Control.Applicative.Backwards (Backwards (..))
import Control.Arrow (Kleisli (..))
import Control.Monad.Trans.Identity (IdentityT (..))
import Control.Monad.Trans.Reader (ReaderT (..))
import Data.Array (Array)
Expand Down Expand Up @@ -280,6 +281,10 @@ instance TraversableWithIndex Int ZipList where
itraverse f (ZipList xs) = ZipList <$> itraverse f xs
{-# INLINE itraverse #-}

instance Functor m => FunctorWithIndex a (Kleisli m a) where
imap f (Kleisli p) = Kleisli (\x -> f x <$> p x)
{-# INLINE imap #-}

-------------------------------------------------------------------------------
-- (former) semigroups
-------------------------------------------------------------------------------
Expand All @@ -296,7 +301,7 @@ instance TraversableWithIndex Int NonEmpty where
{-# INLINE itraverse #-}

-------------------------------------------------------------------------------
-- Functors (formely) from transformers
-- Functors (formerly) from transformers
-------------------------------------------------------------------------------

instance FunctorWithIndex () Identity where
Expand Down