git.iko.soy/typeable/attoparsec
on master help sign in
6 files changed+166−111
since splitsnapshots
unifiedsplit
.travis.yml+136−96 Data/Attoparsec/Internal/Types.hs+3−1 Data/Attoparsec/Zepto.hs+2 attoparsec.cabal+10−9 tests/QC/ByteString.hs+4−2 tests/QC/Text.hs+11−3
.travis.yml+136−96
@@ -1,121 +1,161 @@
11# This Travis job script has been generated by a script via
22#
3−# runghc make_travis_yml_2.hs 'attoparsec.cabal'
3+# haskell-ci '--tests-jobs=>=7.4' '--no-benchmarks' 'attoparsec.cabal'
44#
5−# For more information, see https://github.com/hvr/multi-ghc-travis
5+# For more information, see https://github.com/haskell-CI/haskell-ci
6+#
7+# version: 0.3.20190815
68#
79language: c
8−sudo: false
9−
10−# Bryan threatens to turn off Travis-CI if he gets any email :-)
11−notifications:
12− email: false
13−
10+dist: xenial
1411git:
15− submodules: false # whether to recursively clone submodules
16−
12+ # whether to recursively clone submodules
13+ submodules: false
1714cache:
1815 directories:
1916 - $HOME/.cabal/packages
2017 - $HOME/.cabal/store
21−
2218before_cache:
23− - rm -fv $HOME/.cabal/packages/hackage.haskell.org/build-reports.log
19+ - rm -fv $CABALHOME/packages/hackage.haskell.org/build-reports.log
2420 # remove files that are regenerated by 'cabal update'
25− - rm -fv $HOME/.cabal/packages/hackage.haskell.org/00-index.*
26− - rm -fv $HOME/.cabal/packages/hackage.haskell.org/*.json
27− - rm -fv $HOME/.cabal/packages/hackage.haskell.org/01-index.cache
28− - rm -fv $HOME/.cabal/packages/hackage.haskell.org/01-index.tar
29− - rm -fv $HOME/.cabal/packages/hackage.haskell.org/01-index.tar.idx
30−
31− - rm -rfv $HOME/.cabal/packages/head.hackage
32−
21+ - rm -fv $CABALHOME/packages/hackage.haskell.org/00-index.*
22+ - rm -fv $CABALHOME/packages/hackage.haskell.org/*.json
23+ - rm -fv $CABALHOME/packages/hackage.haskell.org/01-index.cache
24+ - rm -fv $CABALHOME/packages/hackage.haskell.org/01-index.tar
25+ - rm -fv $CABALHOME/packages/hackage.haskell.org/01-index.tar.idx
26+ - rm -rfv $CABALHOME/packages/head.hackage
3327matrix:
3428 include:
35− - compiler: "ghc-7.0.4"
36− env: TEST=--disable-tests BENCH=--disable-benchmarks
37− addons: {apt: {packages: [ghc-ppa-tools,cabal-install-head,ghc-7.0.4], sources: [hvr-ghc]}}
38− - compiler: "ghc-7.2.2"
39− env: TEST=--disable-tests BENCH=--disable-benchmarks
40− addons: {apt: {packages: [ghc-ppa-tools,cabal-install-head,ghc-7.2.2], sources: [hvr-ghc]}}
41− - compiler: "ghc-7.4.2"
42− env: TEST=--disable-tests BENCH=--disable-benchmarks
43− addons: {apt: {packages: [ghc-ppa-tools,cabal-install-head,ghc-7.4.2], sources: [hvr-ghc]}}
44− - compiler: "ghc-7.6.3"
45− env: TEST=--disable-tests BENCH=--disable-benchmarks
46− addons: {apt: {packages: [ghc-ppa-tools,cabal-install-head,ghc-7.6.3], sources: [hvr-ghc]}}
47− - compiler: "ghc-7.8.4"
48− env: BENCH=--disable-benchmarks
49− addons: {apt: {packages: [ghc-ppa-tools,cabal-install-head,ghc-7.8.4], sources: [hvr-ghc]}}
50− - compiler: "ghc-7.10.3"
51− env: BENCH=--disable-benchmarks
52− addons: {apt: {packages: [ghc-ppa-tools,cabal-install-head,ghc-7.10.3], sources: [hvr-ghc]}}
53− - compiler: "ghc-8.0.2"
54− env: BENCH=--disable-benchmarks
55− addons: {apt: {packages: [ghc-ppa-tools,cabal-install-head,ghc-8.0.2], sources: [hvr-ghc]}}
56− - compiler: "ghc-8.2.2"
57− env: BENCH=--disable-benchmarks
58− addons: {apt: {packages: [ghc-ppa-tools,cabal-install-head,ghc-8.2.2], sources: [hvr-ghc]}}
59−
29+ - compiler: ghc-8.8.1
30+ addons: {"apt":{"sources":["hvr-ghc"],"packages":["ghc-8.8.1","cabal-install-3.0"]}}
31+ - compiler: ghc-8.6.5
32+ addons: {"apt":{"sources":["hvr-ghc"],"packages":["ghc-8.6.5","cabal-install-2.4"]}}
33+ - compiler: ghc-8.4.4
34+ addons: {"apt":{"sources":["hvr-ghc"],"packages":["ghc-8.4.4","cabal-install-2.4"]}}
35+ - compiler: ghc-8.2.2
36+ addons: {"apt":{"sources":["hvr-ghc"],"packages":["ghc-8.2.2","cabal-install-2.4"]}}
37+ - compiler: ghc-8.0.2
38+ addons: {"apt":{"sources":["hvr-ghc"],"packages":["ghc-8.0.2","cabal-install-2.4"]}}
39+ - compiler: ghc-7.10.3
40+ addons: {"apt":{"sources":["hvr-ghc"],"packages":["ghc-7.10.3","cabal-install-2.4"]}}
41+ - compiler: ghc-7.8.4
42+ addons: {"apt":{"sources":["hvr-ghc"],"packages":["ghc-7.8.4","cabal-install-2.4"]}}
43+ - compiler: ghc-7.6.3
44+ addons: {"apt":{"sources":["hvr-ghc"],"packages":["ghc-7.6.3","cabal-install-2.4"]}}
45+ - compiler: ghc-7.4.2
46+ addons: {"apt":{"sources":["hvr-ghc"],"packages":["ghc-7.4.2","cabal-install-2.4"]}}
47+ - compiler: ghc-7.2.2
48+ addons: {"apt":{"sources":["hvr-ghc"],"packages":["ghc-7.2.2","cabal-install-2.4"]}}
49+ - compiler: ghc-7.0.4
50+ addons: {"apt":{"sources":["hvr-ghc"],"packages":["ghc-7.0.4","cabal-install-2.4"]}}
6051before_install:
61− - HC=${CC}
62− - HCPKG=${HC/ghc/ghc-pkg}
52+ - HC=$(echo "/opt/$CC/bin/ghc" | sed 's/-/\//')
53+ - WITHCOMPILER="-w $HC"
54+ - HCPKG="$HC-pkg"
6355 - unset CC
64− - ROOTDIR=$(pwd)
65− - mkdir -p $HOME/.local/bin
66− - "PATH=/opt/ghc/bin:/opt/ghc-ppa-tools/bin:$HOME/local/bin:$PATH"
67− - HCNUMVER=$(( $(${HC} --numeric-version|sed -E 's/([0-9]+)\.([0-9]+)\.([0-9]+).*/\1 * 10000 + \2 * 100 + \3/') ))
56+ - CABAL=/opt/ghc/bin/cabal
57+ - CABALHOME=$HOME/.cabal
58+ - export PATH="$CABALHOME/bin:$PATH"
59+ - TOP=$(pwd)
60+ - "HCNUMVER=$(${HC} --numeric-version|perl -ne '/^(\\d+)\\.(\\d+)\\.(\\d+)(\\.(\\d+))?$/; print(10000 * $1 + 100 * $2 + ($3 == 0 ? $5 != 1 : $3))')"
6861 - echo $HCNUMVER
69−
62+ - CABAL="$CABAL -vnormal+nowrap+markoutput"
63+ - set -o pipefail
64+ - |
65+ echo 'function blue(s) { printf "\033[0;34m" s "\033[0m " }' >> .colorful.awk
66+ echo 'BEGIN { state = "output"; }' >> .colorful.awk
67+ echo '/^-----BEGIN CABAL OUTPUT-----$/ { state = "cabal" }' >> .colorful.awk
68+ echo '/^-----END CABAL OUTPUT-----$/ { state = "output" }' >> .colorful.awk
69+ echo '!/^(-----BEGIN CABAL OUTPUT-----|-----END CABAL OUTPUT-----)/ {' >> .colorful.awk
70+ echo ' if (state == "cabal") {' >> .colorful.awk
71+ echo ' print blue($0)' >> .colorful.awk
72+ echo ' } else {' >> .colorful.awk
73+ echo ' print $0' >> .colorful.awk
74+ echo ' }' >> .colorful.awk
75+ echo '}' >> .colorful.awk
76+ - cat .colorful.awk
77+ - |
78+ color_cabal_output () {
79+ awk -f $TOP/.colorful.awk
80+ }
81+ - echo text | color_cabal_output
7082install:
71− - cabal --version
83+ - ${CABAL} --version
7284 - echo "$(${HC} --version) [$(${HC} --print-project-git-commit-id 2> /dev/null || echo '?')]"
73− - BENCH=${BENCH---enable-benchmarks}
74− - TEST=${TEST---enable-tests}
75− - HADDOCK=${HADDOCK-true}
76− - INSTALLED=${INSTALLED-true}
77− - GHCHEAD=${GHCHEAD-false}
78− - travis_retry cabal update -v
79− - "sed -i.bak 's/^jobs:/-- jobs:/' ${HOME}/.cabal/config"
80− - rm -fv cabal.project cabal.project.local
81− - grep -Ev -- '^\s*--' ${HOME}/.cabal/config | grep -Ev '^\s*$'
82− - "printf 'packages: \".\"\\n' > cabal.project"
83− - cat cabal.project
84− - if [ -f "./configure.ac" ]; then
85− (cd "." && autoreconf -i);
86− fi
87− - rm -f cabal.project.freeze
88− - cabal new-build -w ${HC} ${TEST} ${BENCH} --project-file="cabal.project" --dep -j2 all
89− - cabal new-build -w ${HC} --disable-tests --disable-benchmarks --project-file="cabal.project" --dep -j2 all
90− - rm -rf "."/.ghc.environment.* "."/dist
91− - DISTDIR=$(mktemp -d /tmp/dist-test.XXXX)
92−
93−# Here starts the actual work to be performed for the package under test;
94−# any command which exits with a non-zero exit code causes the build to fail.
85+ - TEST=--enable-tests
86+ - if [ $HCNUMVER -lt 70400 ] ; then TEST=--disable-tests ; fi
87+ - BENCH=--enable-benchmarks
88+ - BENCH=--disable-benchmarks
89+ - HEADHACKAGE=false
90+ - rm -f $CABALHOME/config
91+ - |
92+ echo "verbose: normal +nowrap +markoutput" >> $CABALHOME/config
93+ echo "remote-build-reporting: anonymous" >> $CABALHOME/config
94+ echo "write-ghc-environment-files: always" >> $CABALHOME/config
95+ echo "remote-repo-cache: $CABALHOME/packages" >> $CABALHOME/config
96+ echo "logs-dir: $CABALHOME/logs" >> $CABALHOME/config
97+ echo "world-file: $CABALHOME/world" >> $CABALHOME/config
98+ echo "extra-prog-path: $CABALHOME/bin" >> $CABALHOME/config
99+ echo "symlink-bindir: $CABALHOME/bin" >> $CABALHOME/config
100+ echo "installdir: $CABALHOME/bin" >> $CABALHOME/config
101+ echo "build-summary: $CABALHOME/logs/build.log" >> $CABALHOME/config
102+ echo "store-dir: $CABALHOME/store" >> $CABALHOME/config
103+ echo "install-dirs user" >> $CABALHOME/config
104+ echo " prefix: $CABALHOME" >> $CABALHOME/config
105+ echo "repository hackage.haskell.org" >> $CABALHOME/config
106+ echo " url: http://hackage.haskell.org/" >> $CABALHOME/config
107+ - cat $CABALHOME/config
108+ - rm -fv cabal.project cabal.project.local cabal.project.freeze
109+ - travis_retry ${CABAL} v2-update -v
110+ # Generate cabal.project
111+ - rm -rf cabal.project cabal.project.local cabal.project.freeze
112+ - touch cabal.project
113+ - |
114+ echo "packages: ." >> cabal.project
115+ - |
116+ - "for pkg in $($HCPKG list --simple-output); do echo $pkg | sed 's/-[^-]*$//' | (grep -vE -- '^(attoparsec)$' || true) | sed 's/^/constraints: /' | sed 's/$/ installed/' >> cabal.project.local; done"
117+ - cat cabal.project || true
118+ - cat cabal.project.local || true
119+ - if [ -f "./configure.ac" ]; then (cd "." && autoreconf -i); fi
120+ - ${CABAL} v2-freeze $WITHCOMPILER ${TEST} ${BENCH} | color_cabal_output
121+ - "cat cabal.project.freeze | sed -E 's/^(constraints: *| *)//' | sed 's/any.//'"
122+ - rm cabal.project.freeze
123+ - ${CABAL} v2-build $WITHCOMPILER ${TEST} ${BENCH} --dep -j2 all | color_cabal_output
124+ - ${CABAL} v2-build $WITHCOMPILER --disable-tests --disable-benchmarks --dep -j2 all | color_cabal_output
95125script:
96− # test that source-distributions can be generated
97− - (cd "." && cabal sdist)
98− - mv "."/dist/attoparsec-*.tar.gz ${DISTDIR}/
126+ - DISTDIR=$(mktemp -d /tmp/dist-test.XXXX)
127+ # Packaging...
128+ - ${CABAL} v2-sdist all | color_cabal_output
129+ # Unpacking...
130+ - mv dist-newstyle/sdist/*.tar.gz ${DISTDIR}/
99131 - cd ${DISTDIR} || false
100− - find . -maxdepth 1 -name '*.tar.gz' -exec tar -xvf '{}' \;
101− - "printf 'packages: attoparsec-*/*.cabal\\n' > cabal.project"
102− - cat cabal.project
132+ - find . -maxdepth 1 -type f -name '*.tar.gz' -exec tar -xvf '{}' \;
133+ - find . -maxdepth 1 -type f -name '*.tar.gz' -exec rm '{}' \;
134+ - PKGDIR_attoparsec="$(find . -maxdepth 1 -type d -regex '.*/attoparsec-[0-9.]*')"
135+ # Generate cabal.project
136+ - rm -rf cabal.project cabal.project.local cabal.project.freeze
137+ - touch cabal.project
138+ - |
139+ echo "packages: ${PKGDIR_attoparsec}" >> cabal.project
140+ - |
141+ - "for pkg in $($HCPKG list --simple-output); do echo $pkg | sed 's/-[^-]*$//' | (grep -vE -- '^(attoparsec)$' || true) | sed 's/^/constraints: /' | sed 's/$/ installed/' >> cabal.project.local; done"
142+ - cat cabal.project || true
143+ - cat cabal.project.local || true
144+ # Building...
103145 # this builds all libraries and executables (without tests/benchmarks)
104− - cabal new-build -w ${HC} --disable-tests --disable-benchmarks all
105−
106− # Build with installed constraints for packages in global-db
107− - if $INSTALLED; then echo cabal new-build -w ${HC} --disable-tests --disable-benchmarks $(${HCPKG} list --global --simple-output --names-only | sed 's/\([a-zA-Z0-9-]\{1,\}\) */--constraint="\1 installed" /g') all | sh; else echo "Not building with installed constraints"; fi
108−
146+ - ${CABAL} v2-build $WITHCOMPILER --disable-tests --disable-benchmarks all | color_cabal_output
147+ # Building with tests and benchmarks...
109148 # build & run tests, build benchmarks
110− - cabal new-build -w ${HC} ${TEST} ${BENCH} all
111− - if [ "x$TEST" = "x--enable-tests" ]; then cabal new-test -w ${HC} ${TEST} ${BENCH} all; fi
112−
113− # cabal check
114− - (cd attoparsec-* && cabal check)
115−
116− # haddock
117− - rm -rf ./dist-newstyle
118− - if $HADDOCK; then cabal new-haddock -w ${HC} ${TEST} ${BENCH} all; else echo "Skipping haddock generation";fi
149+ - ${CABAL} v2-build $WITHCOMPILER ${TEST} ${BENCH} all | color_cabal_output
150+ # Testing...
151+ - if [ $HCNUMVER -ge 70400 ] ; then ${CABAL} v2-test $WITHCOMPILER ${TEST} ${BENCH} all | color_cabal_output ; fi
152+ # cabal check...
153+ - (cd ${PKGDIR_attoparsec} && ${CABAL} -vnormal check)
154+ # haddock...
155+ - ${CABAL} v2-haddock $WITHCOMPILER ${TEST} ${BENCH} all | color_cabal_output
156+ # Building without installed constraints for packages in global-db...
157+ - rm -f cabal.project.local
158+ - ${CABAL} v2-build $WITHCOMPILER --disable-tests --disable-benchmarks all | color_cabal_output
119159
120−# REGENDATA ["attoparsec.cabal"]
160+# REGENDATA ["--tests-jobs=>=7.4","--no-benchmarks","attoparsec.cabal"]
121161# EOF
Data/Attoparsec/Internal/Types.hs+3−1
@@ -1,4 +1,4 @@
1−{-# LANGUAGE BangPatterns, GeneralizedNewtypeDeriving, OverloadedStrings,
1+{-# LANGUAGE CPP, BangPatterns, GeneralizedNewtypeDeriving, OverloadedStrings,
22 Rank2Types, RecordWildCards, TypeFamilies #-}
33-- |
44-- Module : Data.Attoparsec.Internal.Types
@@ -136,8 +136,10 @@ instance Mon.Monoid More where
136136 mempty = Incomplete
137137
138138instance Monad (Parser i) where
139+#if !(MIN_VERSION_base(4,13,0))
139140 fail = Fail.fail
140141 {-# INLINE fail #-}
142+#endif
141143
142144 return = App.pure
143145 {-# INLINE return #-}
Data/Attoparsec/Zepto.hs+2
@@ -92,8 +92,10 @@ instance Monad m => Monad (ZeptoT m) where
9292 Fail err -> return (Fail err)
9393 {-# INLINE (>>=) #-}
9494
95+#if !(MIN_VERSION_base(4,13,0))
9596 fail = Fail.fail
9697 {-# INLINE fail #-}
98+#endif
9799
98100instance Monad m => Fail.MonadFail (ZeptoT m) where
99101 fail msg = Parser $ \_ -> return (Fail msg)
attoparsec.cabal+10−9
@@ -1,12 +1,13 @@
11name: attoparsec
22version: 0.13.2.2
3+x-revision: 3
34license: BSD3
45license-file: LICENSE
56category: Text, Parsing
67author: Bryan O'Sullivan <bos@serpentine.com>
78maintainer: Bryan O'Sullivan <bos@serpentine.com>, Ben Gamari <ben@smart-cactus.org>
89stability: experimental
9−tested-with: GHC == 7.0.4, GHC == 7.2.2, GHC == 7.4.2, GHC ==7.6.3, GHC ==7.8.4, GHC ==7.10.3, GHC ==8.0.2, GHC ==8.2.2
10+tested-with: GHC == 7.0.4, GHC == 7.2.2, 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.4, GHC==8.6.5, GHC==8.8.1
1011synopsis: Fast combinator parsing for bytestrings and text
1112cabal-version: >= 1.8
1213homepage: https://github.com/bos/attoparsec
@@ -39,12 +40,12 @@ Flag developer
3940
4041library
4142 build-depends: array,
42− base >= 4.2 && < 5,
43+ base >= 4.3 && < 5,
4344 bytestring,
4445 containers,
4546 deepseq,
4647 scientific >= 0.3.1 && < 0.4,
47− transformers,
48+ transformers >= 0.2 && (< 0.4 || >= 0.4.1.0) && < 0.6,
4849 text >= 1.1.1.3
4950 if impl(ghc < 7.4)
5051 build-depends:
@@ -53,7 +54,7 @@ library
5354 if !impl(ghc >= 8.0)
5455 -- Data.Semigroup && Control.Monad.Fail are available in base-4.9+
5556 build-depends: fail == 4.9.*,
56− semigroups >=0.16.1 && <0.19
57+ semigroups >=0.16.1 && <0.20
5758
5859 exposed-modules: Data.Attoparsec
5960 Data.Attoparsec.ByteString
@@ -124,22 +125,22 @@ test-suite tests
124125
125126 build-depends:
126127 array,
127− base >= 4 && < 5,
128+ base,
128129 bytestring,
129130 deepseq >= 1.1,
130− QuickCheck >= 2.7 && < 2.10,
131+ QuickCheck >= 2.13.2 && < 2.14,
131132 quickcheck-unicode,
132133 scientific,
133134 tasty >= 0.11,
134135 tasty-quickcheck >= 0.8,
135136 text,
136− transformers,
137+ transformers >= 0.2 && (< 0.4 || >= 0.4.1.0) && < 0.6,
137138 vector
138139
139140 if !impl(ghc >= 8.0)
140141 -- Data.Semigroup && Control.Monad.Fail are available in base-4.9+
141142 build-depends: fail == 4.9.*,
142− semigroups >=0.16.1 && <0.19
143+ semigroups >=0.16.1 && <0.20
143144
144145benchmark benchmarks
145146 type: exitcode-stdio-1.0
@@ -178,7 +179,7 @@ benchmark benchmarks
178179 parsec >= 3.1.2,
179180 scientific,
180181 text >= 1.1.1.0,
181− transformers,
182+ transformers >= 0.2 && (< 0.4 || >= 0.4.1.0) && < 0.6,
182183 unordered-containers,
183184 vector
184185
tests/QC/ByteString.hs+4−2
@@ -26,9 +26,11 @@ import qualified Data.ByteString.Lazy.Char8 as L8
2626satisfy :: Word8 -> L.ByteString -> Property
2727satisfy w s = parseBS (P.satisfy (<=w)) (L.cons w s) === Just w
2828
29−satisfyWith :: Char -> L.ByteString -> Property
30−satisfyWith c s = parseBS (P.satisfyWith (chr . fromIntegral) (<=c))
29+satisfyWith :: Word8 -> L.ByteString -> Property
30+satisfyWith w s = parseBS (P.satisfyWith (chr . fromIntegral) (<=c))
3131 (L.cons (fromIntegral (ord c)) s) === Just c
32+ where
33+ c = chr (fromIntegral w)
3234
3335word8 :: Word8 -> L.ByteString -> Property
3436word8 w s = parseBS (P.word8 w) (L.cons w s) === Just w
tests/QC/Text.hs+11−3
@@ -6,6 +6,7 @@ module QC.Text (tests) where
66import Control.Applicative ((<*>), (<$>))
77#endif
88import Data.Int (Int64)
9+import Data.Word (Word8)
910import Prelude hiding (take, takeWhile)
1011import QC.Common (liftOp, parseT)
1112import qualified QC.Text.FastSet as FastSet
@@ -16,8 +17,10 @@ import Test.QuickCheck
1617import qualified Data.Attoparsec.Text as P
1718import qualified Data.Attoparsec.Text.Lazy as PL
1819import qualified Data.Attoparsec.Text.FastSet as S
20+import qualified Data.ByteString as BS
1921import qualified Data.Char as Char
2022import qualified Data.Text as T
23+import qualified Data.Text.Encoding as TE
2124import qualified Data.Text.Lazy as L
2225
2326-- Basic byte-level combinators.
@@ -70,9 +73,12 @@ strings s t u =
7073 === Just t'
7174 where t' = toStrict t
7275
73−stringCI :: T.Text -> Property
74−stringCI s = P.parseOnly (P.stringCI fs) s === Right s
76+-- | Note: "simple, and efficient" works for well formed input...
77+-- i.e. e.g. Latin1 texts
78+stringCI :: [Word8] -> Property
79+stringCI ws = P.parseOnly (P.stringCI fs) s === Right s
7580 where fs = T.toCaseFold s
81+ s = TE.decodeLatin1 (BS.pack ws)
7682
7783asciiCI :: T.Text -> Gen Bool
7884asciiCI x =
@@ -150,7 +156,9 @@ endOfLine s =
150156 (c, fst <$> L.uncons s') === ('\r', Just '\n')
151157
152158scan :: L.Text -> Positive Int64 -> Property
153−scan s (Positive k) = parseT p s === Just (toStrict $ L.take k s)
159+-- for some reason, if counterexample is removed, this test fails?
160+scan s (Positive k) = counterexample (show s)
161+ $ parseT p s === Just (toStrict $ L.take k s)
154162 where p = P.scan k $ \ n _ ->
155163 if n > 0 then let !n' = n - 1 in Just n' else Nothing
156164