kan-extensions 5.0.2 → 5.1
raw patch · 13 files changed
+337/−111 lines, 13 filesdep +profunctorsdep +transformers-compatdep ~basedep ~freenew-uploaderPVP ok
version bump matches the API change (PVP)
Dependencies added: profunctors, transformers-compat
Dependency ranges changed: base, free
API changes (from Hackage documentation)
- Control.Comonad.Density: instance Control.Comonad.Comonad (Control.Comonad.Density.Density f)
- Control.Comonad.Density: instance Data.Functor.Extend.Extend (Control.Comonad.Density.Density f)
- Control.Comonad.Density: instance GHC.Base.Functor (Control.Comonad.Density.Density f)
- Control.Monad.Co: instance Control.Comonad.Comonad w => GHC.Base.Applicative (Control.Monad.Co.CoT w m)
- Control.Monad.Co: instance Control.Comonad.Comonad w => GHC.Base.Monad (Control.Monad.Co.CoT w m)
- Control.Monad.Co: instance Data.Functor.Extend.Extend w => Data.Functor.Bind.Class.Apply (Control.Monad.Co.CoT w m)
- Control.Monad.Co: instance Data.Functor.Extend.Extend w => Data.Functor.Bind.Class.Bind (Control.Monad.Co.CoT w m)
- Control.Monad.Co: instance GHC.Base.Functor w => GHC.Base.Functor (Control.Monad.Co.CoT w m)
- Control.Monad.Codensity: instance Data.Functor.Bind.Class.Apply (Control.Monad.Codensity.Codensity f)
- Control.Monad.Codensity: instance GHC.Base.Applicative (Control.Monad.Codensity.Codensity f)
- Control.Monad.Codensity: instance GHC.Base.Functor (Control.Monad.Codensity.Codensity k)
- Control.Monad.Codensity: instance GHC.Base.Monad (Control.Monad.Codensity.Codensity f)
- Data.Functor.Coyoneda: instance (GHC.Base.Functor f, GHC.Classes.Eq (f a)) => GHC.Classes.Eq (Data.Functor.Coyoneda.Coyoneda f a)
- Data.Functor.Coyoneda: instance (GHC.Base.Functor f, GHC.Classes.Ord (f a)) => GHC.Classes.Ord (Data.Functor.Coyoneda.Coyoneda f a)
- Data.Functor.Coyoneda: instance (GHC.Base.Functor f, GHC.Show.Show (f a)) => GHC.Show.Show (Data.Functor.Coyoneda.Coyoneda f a)
- Data.Functor.Kan.Lan: instance GHC.Base.Functor (Data.Functor.Kan.Lan.Lan f g)
- Data.Functor.Kan.Ran: instance GHC.Base.Functor (Data.Functor.Kan.Ran.Ran g h)
- Data.Functor.Yoneda: instance GHC.Classes.Eq (f a) => GHC.Classes.Eq (Data.Functor.Yoneda.Yoneda f a)
- Data.Functor.Yoneda: instance GHC.Classes.Ord (f a) => GHC.Classes.Ord (Data.Functor.Yoneda.Yoneda f a)
+ Control.Comonad.Density: instance forall k (f :: k -> *). Control.Comonad.Comonad (Control.Comonad.Density.Density f)
+ Control.Comonad.Density: instance forall k (f :: k -> *). Data.Functor.Extend.Extend (Control.Comonad.Density.Density f)
+ Control.Comonad.Density: instance forall k (f :: k -> *). GHC.Base.Functor (Control.Comonad.Density.Density f)
+ Control.Monad.Co: instance forall k (w :: * -> *) (m :: k -> *). Control.Comonad.Comonad w => GHC.Base.Applicative (Control.Monad.Co.CoT w m)
+ Control.Monad.Co: instance forall k (w :: * -> *) (m :: k -> *). Control.Comonad.Comonad w => GHC.Base.Monad (Control.Monad.Co.CoT w m)
+ Control.Monad.Co: instance forall k (w :: * -> *) (m :: k -> *). Data.Functor.Extend.Extend w => Data.Functor.Bind.Class.Apply (Control.Monad.Co.CoT w m)
+ Control.Monad.Co: instance forall k (w :: * -> *) (m :: k -> *). Data.Functor.Extend.Extend w => Data.Functor.Bind.Class.Bind (Control.Monad.Co.CoT w m)
+ Control.Monad.Co: instance forall k (w :: * -> *) (m :: k -> *). GHC.Base.Functor w => GHC.Base.Functor (Control.Monad.Co.CoT w m)
+ Control.Monad.Codensity: instance forall k (f :: k -> *). Data.Functor.Bind.Class.Apply (Control.Monad.Codensity.Codensity f)
+ Control.Monad.Codensity: instance forall k (f :: k -> *). GHC.Base.Applicative (Control.Monad.Codensity.Codensity f)
+ Control.Monad.Codensity: instance forall k (f :: k -> *). GHC.Base.Monad (Control.Monad.Codensity.Codensity f)
+ Control.Monad.Codensity: instance forall k1 (k2 :: k1 -> *). GHC.Base.Functor (Control.Monad.Codensity.Codensity k2)
+ Data.Functor.Coyoneda: instance (GHC.Base.Functor f, Data.Functor.Classes.Eq1 f) => Data.Functor.Classes.Eq1 (Data.Functor.Coyoneda.Coyoneda f)
+ Data.Functor.Coyoneda: instance (GHC.Base.Functor f, Data.Functor.Classes.Eq1 f, GHC.Classes.Eq a) => GHC.Classes.Eq (Data.Functor.Coyoneda.Coyoneda f a)
+ Data.Functor.Coyoneda: instance (GHC.Base.Functor f, Data.Functor.Classes.Ord1 f) => Data.Functor.Classes.Ord1 (Data.Functor.Coyoneda.Coyoneda f)
+ Data.Functor.Coyoneda: instance (GHC.Base.Functor f, Data.Functor.Classes.Ord1 f, GHC.Classes.Ord a) => GHC.Classes.Ord (Data.Functor.Coyoneda.Coyoneda f a)
+ Data.Functor.Coyoneda: instance (GHC.Base.Functor f, Data.Functor.Classes.Show1 f) => Data.Functor.Classes.Show1 (Data.Functor.Coyoneda.Coyoneda f)
+ Data.Functor.Coyoneda: instance (GHC.Base.Functor f, Data.Functor.Classes.Show1 f, GHC.Show.Show a) => GHC.Show.Show (Data.Functor.Coyoneda.Coyoneda f a)
+ Data.Functor.Coyoneda: instance Data.Functor.Classes.Read1 f => Data.Functor.Classes.Read1 (Data.Functor.Coyoneda.Coyoneda f)
+ Data.Functor.Day: cayley :: Procompose (Cayley f p) (Cayley g q) a b -> Cayley (Day f g) (Procompose p q) a b
+ Data.Functor.Day: dayley :: Category p => Procompose (Cayley f p) (Cayley g p) a b -> Cayley (Day f g) p a b
+ Data.Functor.Kan.Lan: instance forall k (f :: k -> *) (g :: k -> *). GHC.Base.Functor (Data.Functor.Kan.Lan.Lan f g)
+ Data.Functor.Kan.Ran: instance forall k (g :: k -> *) (h :: k -> *). GHC.Base.Functor (Data.Functor.Kan.Ran.Ran g h)
+ Data.Functor.Yoneda: instance (Data.Functor.Classes.Eq1 f, GHC.Classes.Eq a) => GHC.Classes.Eq (Data.Functor.Yoneda.Yoneda f a)
+ Data.Functor.Yoneda: instance (Data.Functor.Classes.Ord1 f, GHC.Classes.Ord a) => GHC.Classes.Ord (Data.Functor.Yoneda.Yoneda f a)
+ Data.Functor.Yoneda: instance (Data.Functor.Classes.Read1 f, GHC.Base.Functor f) => Data.Functor.Classes.Read1 (Data.Functor.Yoneda.Yoneda f)
+ Data.Functor.Yoneda: instance Data.Functor.Classes.Eq1 f => Data.Functor.Classes.Eq1 (Data.Functor.Yoneda.Yoneda f)
+ Data.Functor.Yoneda: instance Data.Functor.Classes.Ord1 f => Data.Functor.Classes.Ord1 (Data.Functor.Yoneda.Yoneda f)
+ Data.Functor.Yoneda: instance Data.Functor.Classes.Show1 f => Data.Functor.Classes.Show1 (Data.Functor.Yoneda.Yoneda f)
Files
- .gitignore +19/−0
- .travis.yml +118/−82
- CHANGELOG.markdown +9/−0
- include/kan-extensions-common.h +19/−0
- kan-extensions.cabal +20/−5
- src/Control/Comonad/Density.hs +3/−0
- src/Control/Monad/Co.hs +4/−1
- src/Control/Monad/Codensity.hs +4/−1
- src/Data/Functor/Coyoneda.hs +69/−10
- src/Data/Functor/Day.hs +12/−2
- src/Data/Functor/Kan/Lan.hs +3/−0
- src/Data/Functor/Kan/Ran.hs +5/−2
- src/Data/Functor/Yoneda.hs +52/−8
.gitignore view
@@ -1,4 +1,5 @@ dist+dist-newstyle docs wiki TAGS@@ -11,3 +12,21 @@ *.hi *~ *#+.stack-work/+cabal-dev+*.chi+*.chs.h+*.dyn_o+*.dyn_hi+.hpc+.hsenv+.cabal-sandbox/+cabal.sandbox.config+*.prof+*.aux+*.hp+*.eventlog+cabal.project.local+cabal.project.local~+.HTF/+.ghc.environment.*
.travis.yml view
@@ -1,108 +1,144 @@-# This file has been generated -- see https://github.com/hvr/multi-ghc-travis+# This Travis job script has been generated by a script via+#+# runghc make_travis_yml_2.hs '-o' '.travis.yml' '--irc-channel=irc.freenode.org#haskell-lens' '--no-no-tests-no-bench' '--no-installed' 'cabal.project'+#+# For more information, see https://github.com/hvr/multi-ghc-travis+# language: c sudo: false +git:+ submodules: false # whether to recursively clone submodules++notifications:+ irc:+ channels:+ - "irc.freenode.org#haskell-lens"+ skip_join: true+ template:+ - "\x0313kan-extensions\x03/\x0306%{branch}\x03 \x0314%{commit}\x03 %{build_url} %{message}"+ cache: directories:- - $HOME/.cabsnap - $HOME/.cabal/packages+ - $HOME/.cabal/store before_cache: - rm -fv $HOME/.cabal/packages/hackage.haskell.org/build-reports.log- - rm -fv $HOME/.cabal/packages/hackage.haskell.org/00-index.tar+ # remove files that are regenerated by 'cabal update'+ - rm -fv $HOME/.cabal/packages/hackage.haskell.org/00-index.*+ - rm -fv $HOME/.cabal/packages/hackage.haskell.org/*.json+ - rm -fv $HOME/.cabal/packages/hackage.haskell.org/01-index.cache+ - rm -fv $HOME/.cabal/packages/hackage.haskell.org/01-index.tar+ - rm -fv $HOME/.cabal/packages/hackage.haskell.org/01-index.tar.idx + - rm -rfv $HOME/.cabal/packages/head.hackage++addons:+ apt:+ packages: &apt_packages+ - ghc-ppa-tools+ - alex-3.1.7+ - happy-1.19.5+ matrix: include:- - env: CABALVER=1.18 GHCVER=7.4.2- compiler: ": #GHC 7.4.2"- addons: {apt: {packages: [cabal-install-1.18,ghc-7.4.2,alex-3.1.4,happy-1.19.5], sources: [hvr-ghc]}}- - env: CABALVER=1.18 GHCVER=7.6.3- compiler: ": #GHC 7.6.3"- addons: {apt: {packages: [cabal-install-1.18,ghc-7.6.3,alex-3.1.4,happy-1.19.5], sources: [hvr-ghc]}}- - env: CABALVER=1.18 GHCVER=7.8.4- compiler: ": #GHC 7.8.4"- addons: {apt: {packages: [cabal-install-1.18,ghc-7.8.4,alex-3.1.4,happy-1.19.5], sources: [hvr-ghc]}}- - env: CABALVER=1.22 GHCVER=7.10.1- compiler: ": #GHC 7.10.1"- addons: {apt: {packages: [cabal-install-1.22,ghc-7.10.1,alex-3.1.4,happy-1.19.5], sources: [hvr-ghc]}}- - env: CABALVER=1.22 GHCVER=7.10.3- compiler: ": #GHC 7.10.3"- addons: {apt: {packages: [cabal-install-1.22,ghc-7.10.3,alex-3.1.4,happy-1.19.5], sources: [hvr-ghc]}}- - env: CABALVER=1.24 GHCVER=8.0.2- compiler: ": #GHC 8.0.2"- addons: {apt: {packages: [cabal-install-1.24,ghc-8.0.2,alex-3.1.4,happy-1.19.5], sources: [hvr-ghc]}}- - env: CABALVER=2.0 GHCVER=8.2.1- compiler: ": #GHC 8.2.1"- addons: {apt: {packages: [cabal-install-2.0,ghc-8.2.1,alex-3.1.4,happy-1.19.5], sources: [hvr-ghc]}}- - env: CABALVER=head GHCVER=head- compiler: ": #GHC head"- addons: {apt: {packages: [cabal-install-head,ghc-head,alex-3.1.4,happy-1.19.5], sources: [hvr-ghc]}}+ - compiler: "ghc-7.4.2"+ # env: TEST=--disable-tests BENCH=--disable-benchmarks+ addons: {apt: {packages: [*apt_packages,cabal-install-2.0,ghc-7.4.2], sources: [hvr-ghc]}}+ - compiler: "ghc-7.6.3"+ # env: TEST=--disable-tests BENCH=--disable-benchmarks+ addons: {apt: {packages: [*apt_packages,cabal-install-2.0,ghc-7.6.3], sources: [hvr-ghc]}}+ - compiler: "ghc-7.8.4"+ # env: TEST=--disable-tests BENCH=--disable-benchmarks+ addons: {apt: {packages: [*apt_packages,cabal-install-2.0,ghc-7.8.4], sources: [hvr-ghc]}}+ - compiler: "ghc-7.10.3"+ # env: TEST=--disable-tests BENCH=--disable-benchmarks+ addons: {apt: {packages: [*apt_packages,cabal-install-2.0,ghc-7.10.3], sources: [hvr-ghc]}}+ - compiler: "ghc-8.0.2"+ # env: TEST=--disable-tests BENCH=--disable-benchmarks+ addons: {apt: {packages: [*apt_packages,cabal-install-2.0,ghc-8.0.2], sources: [hvr-ghc]}}+ - compiler: "ghc-8.2.2"+ # env: TEST=--disable-tests BENCH=--disable-benchmarks+ addons: {apt: {packages: [*apt_packages,cabal-install-2.0,ghc-8.2.2], sources: [hvr-ghc]}}+ - compiler: "ghc-8.4.1"+ env: GHCHEAD=true+ addons: {apt: {packages: [*apt_packages,cabal-install-head,ghc-8.4.1], sources: [hvr-ghc]}}+ - compiler: "ghc-head"+ env: GHCHEAD=true+ addons: {apt: {packages: [*apt_packages,cabal-install-head,ghc-head], sources: [hvr-ghc]}} allow_failures:- - env: CABALVER=head GHCVER=head-+ - compiler: "ghc-8.4.1"+ - compiler: "ghc-head" before_install:- - unset CC- - export HAPPYVER=1.19.5- - export ALEXVER=3.1.4- - export PATH=~/.cabal/bin:/opt/ghc/$GHCVER/bin:/opt/cabal/$CABALVER/bin:/opt/happy/$HAPPYVER/bin:/opt/alex/$ALEXVER/bin:$PATH+ - HC=${CC}+ - HCPKG=${HC/ghc/ghc-pkg}+ - unset CC+ - ROOTDIR=$(pwd)+ - mkdir -p $HOME/.local/bin+ - "PATH=/opt/ghc/bin:/opt/ghc-ppa-tools/bin:$HOME/local/bin:$PATH"+ - HCNUMVER=$(( $(${HC} --numeric-version|sed -E 's/([0-9]+)\.([0-9]+)\.([0-9]+).*/\1 * 10000 + \2 * 100 + \3/') ))+ - echo $HCNUMVER install:- - cabal --version- - echo "$(ghc --version) [$(ghc --print-project-git-commit-id 2> /dev/null || echo '?')]"- - if [ -f $HOME/.cabal/packages/hackage.haskell.org/00-index.tar.gz ];- then- zcat $HOME/.cabal/packages/hackage.haskell.org/00-index.tar.gz >- $HOME/.cabal/packages/hackage.haskell.org/00-index.tar;- fi- - travis_retry cabal update- - "sed -i 's/^jobs:.*$/jobs: 2/' $HOME/.cabal/config"- - cabal install --only-dependencies --enable-tests --enable-benchmarks --dry -v > installplan.txt- - sed -i -e '1,/^Resolving /d' installplan.txt; cat installplan.txt+ - cabal --version+ - echo "$(${HC} --version) [$(${HC} --print-project-git-commit-id 2> /dev/null || echo '?')]"+ - BENCH=${BENCH---enable-benchmarks}+ - TEST=${TEST---enable-tests}+ - HADDOCK=${HADDOCK-true}+ - INSTALLED=${INSTALLED-true}+ - GHCHEAD=${GHCHEAD-false}+ - travis_retry cabal update -v+ - "sed -i.bak 's/^jobs:/-- jobs:/' ${HOME}/.cabal/config"+ - rm -fv cabal.project cabal.project.local+ # Overlay Hackage Package Index for GHC HEAD: https://github.com/hvr/head.hackage+ - |+ if $GHCHEAD; then+ sed -i.bak 's/-- allow-newer:.*/allow-newer: *:base, *:template-haskell, *:ghc, *:Cabal/' ${HOME}/.cabal/config -# check whether current requested install-plan matches cached package-db snapshot- - if diff -u installplan.txt $HOME/.cabsnap/installplan.txt;- then- echo "cabal build-cache HIT";- rm -rfv .ghc;- cp -a $HOME/.cabsnap/ghc $HOME/.ghc;- cp -a $HOME/.cabsnap/lib $HOME/.cabsnap/share $HOME/.cabsnap/bin $HOME/.cabal/;- else- echo "cabal build-cache MISS";- rm -rf $HOME/.cabsnap;- mkdir -p $HOME/.ghc $HOME/.cabal/lib $HOME/.cabal/share $HOME/.cabal/bin;- cabal install --only-dependencies --enable-tests --enable-benchmarks;- fi+ echo 'repository head.hackage' >> ${HOME}/.cabal/config+ echo ' url: http://head.hackage.haskell.org/' >> ${HOME}/.cabal/config+ echo ' secure: True' >> ${HOME}/.cabal/config+ echo ' root-keys: 07c59cb65787dedfaef5bd5f987ceb5f7e5ebf88b904bbd4c5cbdeb2ff71b740' >> ${HOME}/.cabal/config+ echo ' 2e8555dde16ebd8df076f1a8ef13b8f14c66bad8eafefd7d9e37d0ed711821fb' >> ${HOME}/.cabal/config+ echo ' 8f79fd2389ab2967354407ec852cbe73f2e8635793ac446d09461ffb99527f6e' >> ${HOME}/.cabal/config+ echo ' key-threshold: 3' >> ${HOME}/.cabal.config -# snapshot package-db on cache miss- - if [ ! -d $HOME/.cabsnap ];- then- echo "snapshotting package-db to build-cache";- mkdir $HOME/.cabsnap;- cp -a $HOME/.ghc $HOME/.cabsnap/ghc;- cp -a $HOME/.cabal/lib $HOME/.cabal/share $HOME/.cabal/bin installplan.txt $HOME/.cabsnap/;- fi+ cabal new-update head.hackage -v+ fi+ - grep -Ev -- '^\s*--' ${HOME}/.cabal/config | grep -Ev '^\s*$'+ - "printf 'packages: \".\"\\n' > cabal.project"+ - cat cabal.project+ - if [ -f "./configure.ac" ]; then+ (cd "." && autoreconf -i);+ fi+ - rm -f cabal.project.freeze+ - cabal new-build -w ${HC} ${TEST} ${BENCH} --project-file="cabal.project" --dep -j2 all+ - rm -rf "."/.ghc.environment.* "."/dist+ - DISTDIR=$(mktemp -d /tmp/dist-test.XXXX) # Here starts the actual work to be performed for the package under test; # any command which exits with a non-zero exit code causes the build to fail. script:- - cabal configure --enable-tests -v2 # -v2 provides useful information for debugging- - cabal build # this builds all libraries and executables (including tests)- - cabal test- - cabal bench || true # expected result: these will crash- - cabal sdist || true # tests that a source-distribution can be generated+ # test that source-distributions can be generated+ - (cd "." && cabal sdist)+ - mv "."/dist/kan-extensions-*.tar.gz ${DISTDIR}/+ - cd ${DISTDIR} || false+ - find . -maxdepth 1 -name '*.tar.gz' -exec tar -xvf '{}' \;+ - "printf 'packages: kan-extensions-*/*.cabal\\n' > cabal.project"+ - cat cabal.project -# Check that the resulting source distribution can be built & installed.-# If there are no other `.tar.gz` files in `dist`, this can be even simpler:-# `cabal install --force-reinstalls dist/*-*.tar.gz`- - SRC_TGZ=$(cabal info . | awk '{print $2;exit}').tar.gz &&- (cd dist && cabal install --force-reinstalls "$SRC_TGZ") -notifications:- irc:- channels:- - "irc.freenode.org#haskell-lens"- skip_join: true- template:- - "\x0313kan-extensions\x0f/\x0306%{branch}\x0f \x0314%{commit}\x0f %{message} \x0302\x1f%{build_url}\x0f"+ # build & run tests, build benchmarks+ - cabal new-build -w ${HC} ${TEST} ${BENCH} all++ # cabal check+ - (cd kan-extensions-* && cabal check)++ # haddock+ - rm -rf ./dist-newstyle+ - if $HADDOCK; then cabal new-haddock -w ${HC} ${TEST} ${BENCH} all; else echo "Skipping haddock generation";fi++# REGENDATA ["-o",".travis.yml","--irc-channel=irc.freenode.org#haskell-lens","--no-no-tests-no-bench","--no-installed","cabal.project"] # EOF
CHANGELOG.markdown view
@@ -1,3 +1,12 @@+5.1 [2018.01.28]+----------------+* Make `Density`, `Codensity`, `Kan` and `Lan` polykinded.+* Add `Eq1`, `Ord1`, `Read1` and `Show1` instances for `Coyoneda` and `Yoneda`.+* Change contexts of `Eq` and `Ord` instances of `Coyoneda` and `Yoneda`+ (and the `Show` instance for `Coyoneda`) to require lifted class instances,+ e.g. `Eq1 f, Eq a`.+* Allow `free-5`.+ 5.0.2 ----- * Added `hoistCoyoneda`
+ include/kan-extensions-common.h view
@@ -0,0 +1,19 @@+#ifndef MIN_VERSION_base+#define MIN_VERSION_base(x,y,z) 1+#endif++#ifndef MIN_VERSION_mtl+#define MIN_VERSION_mtl(x,y,z) 1+#endif++#if MIN_VERSION_base(4,9,0)+#define LIFTED_FUNCTOR_CLASSES 1+#else+#if MIN_VERSION_transformers(0,5,0)+#define LIFTED_FUNCTOR_CLASSES 1+#else+#if MIN_VERSION_transformers_compat(0,5,0) && !MIN_VERSION_transformers(0,4,0)+#define LIFTED_FUNCTOR_CLASSES 1+#endif+#endif+#endif
kan-extensions.cabal view
@@ -1,6 +1,6 @@ name: kan-extensions category: Data Structures, Monads, Comonads, Functors-version: 5.0.2+version: 5.1 license: BSD3 cabal-version: >= 1.6 license-file: LICENSE@@ -10,9 +10,16 @@ homepage: http://github.com/ekmett/kan-extensions/ bug-reports: http://github.com/ekmett/kan-extensions/issues copyright: Copyright (C) 2008-2016 Edward A. Kmett-synopsis: Kan extensions, Kan lifts, various forms of the Yoneda lemma, and (co)density (co)monads-description: Kan extensions, Kan lifts, various forms of the Yoneda lemma, and (co)density (co)monads+synopsis: Kan extensions, Kan lifts, the Yoneda lemma, and (co)density (co)monads+description: Kan extensions, Kan lifts, various forms of the Yoneda lemma, and (co)density (co)monads. build-type: Simple+tested-with: GHC == 7.4.2+ , GHC == 7.6.3+ , GHC == 7.8.4+ , GHC == 7.10.3+ , GHC == 8.0.2+ , GHC == 8.2.2+ , GHC == 8.4.1 extra-source-files: .travis.yml@@ -21,6 +28,7 @@ .vim.custom CHANGELOG.markdown README.markdown+ include/kan-extensions-common.h source-repository head type: git@@ -28,6 +36,8 @@ library hs-source-dirs: src+ include-dirs: include+ includes: kan-extensions-common.h other-extensions: CPP@@ -48,11 +58,13 @@ contravariant >= 1 && < 2, distributive >= 0.2.2 && < 1, fail >= 4.9 && < 5,- free >= 4 && < 5,+ free >= 4 && < 6, mtl >= 2.0.1 && < 2.3,+ profunctors >= 5 && < 6, semigroupoids >= 4 && < 6, tagged >= 0.7.2 && < 1,- transformers >= 0.2 && < 0.6+ transformers >= 0.2 && < 0.6,+ transformers-compat >= 0.3 && <0.6 exposed-modules: Control.Comonad.Density@@ -70,3 +82,6 @@ ghc-options: -Wall + -- See https://ghc.haskell.org/trac/ghc/wiki/Migration/8.0#base-4.9.0.0+ if impl(ghc >= 8.0)+ ghc-options: -Wcompat -Wnoncanonical-monad-instances -Wnoncanonical-monadfail-instances
src/Control/Comonad/Density.hs view
@@ -1,5 +1,8 @@ {-# LANGUAGE CPP #-} {-# LANGUAGE GADTs #-}+#if __GLASGOW_HASKELL__ >= 706+{-# LANGUAGE PolyKinds #-}+#endif {-# LANGUAGE MultiParamTypeClasses #-} #if __GLASGOW_HASKELL__ >= 702 && __GLASGOW_HASKELL__ < 710 {-# LANGUAGE Trustworthy #-}
src/Control/Monad/Co.hs view
@@ -4,6 +4,9 @@ {-# LANGUAGE FlexibleContexts #-} {-# LANGUAGE UndecidableInstances #-} {-# LANGUAGE MultiParamTypeClasses #-}+#if __GLASGOW_HASKELL__ >= 706+{-# LANGUAGE PolyKinds #-}+#endif #if __GLASGOW_HASKELL__ >= 702 && __GLASGOW_HASKELL__ < 710 {-# LANGUAGE Trustworthy #-} #endif@@ -29,7 +32,7 @@ -- which is a 'Monad' in @Hask^op@ to a 'Monad' in 'Hask'. -- -- For any @r@, the 'Contravariant' functor / presheaf @(-> r)@ :: Hask^op -> Hask is adjoint to the \"same\"--- 'Contravariant' functor @(-> r) :: Hask -> Hask^op@. So we can sandwhich a+-- 'Contravariant' functor @(-> r) :: Hask -> Hask^op@. So we can sandwich a -- Monad in Hask^op in the middle to obtain @w (a -> r-) -> r+@, and then take a coend over -- @r@ to obtain @forall r. w (a -> r) -> r@. This gives rise to 'Co'. If we observe that -- we didn't care what the choices we made for @r@ were to finish this construction, we can
src/Control/Monad/Codensity.hs view
@@ -3,6 +3,9 @@ {-# LANGUAGE FlexibleInstances #-} {-# LANGUAGE UndecidableInstances #-} {-# LANGUAGE MultiParamTypeClasses #-}+#if __GLASGOW_HASKELL__ >= 706+{-# LANGUAGE PolyKinds #-}+#endif #if __GLASGOW_HASKELL__ >= 702 {-# LANGUAGE Trustworthy #-} #endif@@ -57,7 +60,7 @@ -- See \"Asymptotic Improvement of Computations over Free Monads\" by Janis -- Voigtländer for more information about this type. ----- <http://www.iai.uni-bonn.de/~jv/mpc08.pdf>+-- <https://www.janis-voigtlaender.eu/papers/AsymptoticImprovementOfComputationsOverFreeMonads.pdf> newtype Codensity m a = Codensity { runCodensity :: forall b. (a -> m b) -> m b }
src/Data/Functor/Coyoneda.hs view
@@ -9,6 +9,7 @@ #if defined(__GLASGOW_HASKELL__) && __GLASGOW_HASKELL__ >= 702 {-# LANGUAGE Trustworthy #-} #endif+#include "kan-extensions-common.h" ----------------------------------------------------------------------------- -- |@@ -36,9 +37,12 @@ import Control.Comonad import Control.Comonad.Trans.Class import Data.Distributive+#if !LIFTED_FUNCTOR_CLASSES import Data.Function (on)+#endif import Data.Functor.Adjunction import Data.Functor.Bind+import Data.Functor.Classes import Data.Functor.Extend import Data.Functor.Identity import Data.Functor.Kan.Lan@@ -145,13 +149,19 @@ instance Monad m => Monad (Coyoneda m) where #if __GLASGOW_HASKELL__ < 710+ -- pre-AMP return = Coyoneda id . return {-# INLINE return #-}++ Coyoneda _ m >> Coyoneda g n = Coyoneda g (m >> n)+ {-# INLINE (>>) #-}+#else+ -- post-AMP+ (>>) = (*>)+ {-# INLINE (>>) #-} #endif Coyoneda f v >>= k = lift (v >>= lowerM . k . f) {-# INLINE (>>=) #-}- Coyoneda _ m >> Coyoneda g n = Coyoneda g (m >> n)- {-# INLINE (>>) #-} instance MonadTrans Coyoneda where lift = Coyoneda id@@ -208,25 +218,74 @@ collect f = liftCoyoneda . collect (lowerCoyoneda . f) {-# INLINE collect #-} -instance (Functor f, Show (f a)) => Show (Coyoneda f a) where- showsPrec d (Coyoneda f a) = showParen (d > 10) $- showString "liftCoyoneda " . showsPrec 11 (fmap f a)+instance (Functor f, Show1 f) => Show1 (Coyoneda f) where+#if LIFTED_FUNCTOR_CLASSES+ liftShowsPrec sp sl d (Coyoneda f a) =+ showsUnaryWith (liftShowsPrec sp sl) "liftCoyoneda" d (fmap f a)+ {-# INLINE liftShowsPrec #-}+#else+ showsPrec1 d (Coyoneda f a) = showParen (d > 10) $+ showString "liftCoyoneda " . showsPrec1 11 (fmap f a)+ {-# INLINE showsPrec1 #-}+#endif++instance (Read1 f) => Read1 (Coyoneda f) where+#if LIFTED_FUNCTOR_CLASSES+ liftReadsPrec rp rl = readsData $+ readsUnaryWith (liftReadsPrec rp rl) "liftCoyoneda" liftCoyoneda+ {-# INLINE liftReadsPrec #-}+#else+ readsPrec1 d = readParen (d > 10) $ \r' ->+ [ (liftCoyoneda f, t)+ | ("liftCoyoneda", s) <- lex r'+ , (f, t) <- readsPrec1 11 s+ ]+ {-# INLINE readsPrec1 #-}+#endif++instance (Functor f, Show1 f, Show a) => Show (Coyoneda f a) where+ showsPrec = showsPrec1 {-# INLINE showsPrec #-} -#ifdef __GLASGOW_HASKELL__ instance Read (f a) => Read (Coyoneda f a) where+#ifdef __GLASGOW_HASKELL__ readPrec = parens $ prec 10 $ do Ident "liftCoyoneda" <- lexP liftCoyoneda <$> step readPrec {-# INLINE readPrec #-}+#else+ readsPrec d = readParen (d > 10) $ \r' ->+ [ (liftCoyoneda f, t)+ | ("liftCoyoneda", s) <- lex r'+ , (f, t) <- readsPrec 11 s+ ]+ {-# INLINE readsPrec #-} #endif -instance (Functor f, Eq (f a)) => Eq (Coyoneda f a) where- (==) = (==) `on` lowerCoyoneda+instance (Functor f, Eq1 f) => Eq1 (Coyoneda f) where+#if LIFTED_FUNCTOR_CLASSES+ liftEq eq = \x y -> liftEq eq (lowerCoyoneda x) (lowerCoyoneda y)+ {-# INLINE liftEq #-}+#else+ eq1 = eq1 `on` lowerCoyoneda+ {-# INLINE eq1 #-}+#endif++instance (Functor f, Ord1 f) => Ord1 (Coyoneda f) where+#if LIFTED_FUNCTOR_CLASSES+ liftCompare cmp = \x y -> liftCompare cmp (lowerCoyoneda x) (lowerCoyoneda y)+ {-# INLINE liftCompare #-}+#else+ compare1 = compare1 `on` lowerCoyoneda+ {-# INLINE compare1 #-}+#endif++instance (Functor f, Eq1 f, Eq a) => Eq (Coyoneda f a) where+ (==) = eq1 {-# INLINE (==) #-} -instance (Functor f, Ord (f a)) => Ord (Coyoneda f a) where- compare = compare `on` lowerCoyoneda+instance (Functor f, Ord1 f, Ord a) => Ord (Coyoneda f a) where+ compare = compare1 {-# INLINE compare #-} instance Adjunction f g => Adjunction (Coyoneda f) (Coyoneda g) where
src/Data/Functor/Day.hs view
@@ -35,21 +35,24 @@ , intro1, intro2 , elim1, elim2 , trans1, trans2+ , cayley, dayley ) where import Control.Applicative+import Control.Category import Control.Comonad import Control.Comonad.Trans.Class import Data.Distributive+import Data.Profunctor.Cayley (Cayley(..))+import Data.Profunctor.Composition (Procompose(..)) import Data.Functor.Identity import Data.Functor.Rep #ifdef __GLASGOW_HASKELL__ import Data.Typeable #endif+import Prelude hiding (id,(.)) -- | The Day convolution of two covariant functors.------ @Day f g a -> h a@ is isomorphic to @f a -> Rift g h a@ data Day f g a = forall b c. Day (f b) (g c) (b -> c -> a) #if defined(__GLASGOW_HASKELL__) && __GLASGOW_HASKELL__ >= 707 deriving Typeable@@ -204,3 +207,10 @@ -- @ trans2 :: (forall x. g x -> h x) -> Day f g a -> Day f h a trans2 gh (Day fb gc bca) = Day fb (gh gc) bca++cayley :: Procompose (Cayley f p) (Cayley g q) a b -> Cayley (Day f g) (Procompose p q) a b+cayley (Procompose (Cayley p) (Cayley q)) = Cayley $ Day p q Procompose++-- | Proposition 4.1 from Pastro and Street+dayley :: Category p => Procompose (Cayley f p) (Cayley g p) a b -> Cayley (Day f g) p a b+dayley (Procompose (Cayley p) (Cayley q)) = Cayley $ Day p q (.)
src/Data/Functor/Kan/Lan.hs view
@@ -1,6 +1,9 @@ {-# LANGUAGE CPP #-} {-# LANGUAGE GADTs #-} {-# LANGUAGE Rank2Types #-}+#if __GLASGOW_HASKELL__ >= 706+{-# LANGUAGE PolyKinds #-}+#endif #if __GLASGOW_HASKELL__ >= 702 && __GLASGOW_HASKELL__ < 710 {-# LANGUAGE Trustworthy #-} #endif
src/Data/Functor/Kan/Ran.hs view
@@ -1,5 +1,8 @@ {-# LANGUAGE Rank2Types, GADTs #-} {-# LANGUAGE CPP #-}+#if __GLASGOW_HASKELL__ >= 706+{-# LANGUAGE PolyKinds #-}+#endif #if defined(__GLASGOW_HASKELL__) && __GLASGOW_HASKELL__ >= 702 {-# LANGUAGE Trustworthy #-} #endif@@ -38,7 +41,7 @@ -- from the universal property. -- -- Given a 'Functor' @h : C -> D@ and a 'Functor' @g : C -> C'@, we want to extend @h@ /back/ along @g@--- to give @Ran g h : C' -> C@, such that the natural transformation @'gran' :: Ran g h (g a) -> h a@ exists.+-- to give @Ran g h : C' -> D@, such that the natural transformation @'gran' :: Ran g h (g a) -> h a@ exists. -- -- In some sense this is trying to approximate the inverse of @g@ by using one of -- its adjoints, because if the adjoint and the inverse both exist, they match!@@ -52,7 +55,7 @@ -- -- The Right Kan extension is unique (up to isomorphism) by taking this as its universal property. ----- That is to say given any @K : C' -> C@ such that we have a natural transformation from @k.g@ to @h@+-- That is to say given any @K : C' -> D@ such that we have a natural transformation from @k.g@ to @h@ -- @(forall x. k (g x) -> h x)@ there exists a canonical natural transformation from @k@ to @Ran g h@. -- @(forall x. k x -> Ran g h x)@. --
src/Data/Functor/Yoneda.hs view
@@ -8,6 +8,7 @@ #if defined(__GLASGOW_HASKELL__) && __GLASGOW_HASKELL__ >= 702 {-# LANGUAGE Trustworthy #-} #endif+#include "kan-extensions-common.h" ----------------------------------------------------------------------------- -- |@@ -44,9 +45,9 @@ import Control.Comonad.Trans.Class import Data.Distributive import Data.Foldable-import Data.Function (on) import Data.Functor.Adjunction import Data.Functor.Bind+import Data.Functor.Classes import Data.Functor.Extend import Data.Functor.Identity import Data.Functor.Kan.Ran@@ -138,24 +139,67 @@ unit = liftYoneda . fmap liftYoneda . unit counit (Yoneda m) = counit (m lowerYoneda) --- instance Show1 f => Show1 (Yoneda f) where+instance Show1 f => Show1 (Yoneda f) where+#if LIFTED_FUNCTOR_CLASSES+ liftShowsPrec sp sl d (Yoneda f) =+ showsUnaryWith (liftShowsPrec sp sl) "liftYoneda" d (f id)+#else+ showsPrec1 d (Yoneda f) = showParen (d > 10) $+ showString "liftYoneda " . showsPrec1 11 (f id)+#endif++instance (Read1 f, Functor f) => Read1 (Yoneda f) where+#if LIFTED_FUNCTOR_CLASSES+ liftReadsPrec rp rl = readsData $+ readsUnaryWith (liftReadsPrec rp rl) "liftYoneda" liftYoneda+#else+ readsPrec1 d = readParen (d > 10) $ \r' ->+ [ (liftYoneda f, t)+ | ("liftYoneda", s) <- lex r'+ , (f, t) <- readsPrec1 11 s+ ]+#endif+ instance Show (f a) => Show (Yoneda f a) where showsPrec d (Yoneda f) = showParen (d > 10) $ showString "liftYoneda " . showsPrec 11 (f id) --- instance Read1 f => Read1 (Yoneda f) where-#ifdef __GLASGOW_HASKELL__ instance (Functor f, Read (f a)) => Read (Yoneda f a) where+#ifdef __GLASGOW_HASKELL__ readPrec = parens $ prec 10 $ do Ident "liftYoneda" <- lexP liftYoneda <$> step readPrec+#else+ readsPrec d = readParen (d > 10) $ \r' ->+ [ (liftYoneda f, t)+ | ("liftYoneda", s) <- lex r'+ , (f, t) <- readsPrec 11 s+ ] #endif -instance Eq (f a) => Eq (Yoneda f a) where- (==) = (==) `on` lowerYoneda+infixl 0 `on1`+on1 :: (g a -> g b -> c) -> (forall x. f x -> g x) -> f a -> f b -> c+(.*.) `on1` f = \x y -> f x .*. f y -instance Ord (f a) => Ord (Yoneda f a) where- compare = compare `on` lowerYoneda+instance Eq1 f => Eq1 (Yoneda f) where+#if LIFTED_FUNCTOR_CLASSES+ liftEq eq = liftEq eq `on1` lowerYoneda+#else+ eq1 = eq1 `on1` lowerYoneda+#endif++instance Ord1 f => Ord1 (Yoneda f) where+#if LIFTED_FUNCTOR_CLASSES+ liftCompare cmp = liftCompare cmp `on1` lowerYoneda+#else+ compare1 = compare1 `on1` lowerYoneda+#endif++instance (Eq1 f, Eq a) => Eq (Yoneda f a) where+ (==) = eq1++instance (Ord1 f, Ord a) => Ord (Yoneda f a) where+ compare = compare1 maxF :: (Functor f, Ord (f a)) => Yoneda f a -> Yoneda f a -> Yoneda f a Yoneda f `maxF` Yoneda g = liftYoneda $ f id `max` g id