From 3f998fbec7d7dba77f6f9f7f33d7b0deba59c649 Mon Sep 17 00:00:00 2001 From: Mirek Kratochvil Date: Fri, 28 Mar 2025 20:28:54 +0100 Subject: [PATCH 1/4] do not drop extra elements in Data.List.Linear drop and take Fixes #484 . --- src/Data/List/Linear.hs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Data/List/Linear.hs b/src/Data/List/Linear.hs index 5a054a69..e67f9993 100644 --- a/src/Data/List/Linear.hs +++ b/src/Data/List/Linear.hs @@ -191,13 +191,13 @@ dropWhile p (x : xs) = take :: (Consumable a) => Int -> [a] %1 -> [a] take _ [] = [] take i (x : xs) - | i Prelude.< 0 = (x, xs) `lseq` [] + | i Prelude.<= 0 = (x, xs) `lseq` [] | otherwise = x : take (i - 1) xs drop :: (Consumable a) => Int -> [a] %1 -> [a] drop _ [] = [] drop i (x : xs) - | i Prelude.< 0 = x : xs + | i Prelude.<= 0 = x : xs | otherwise = x `lseq` drop (i - 1) xs -- | The intersperse function takes an element and a list and From abdfcf8c6a9baa13a12238c4d6c5f34618d0e862 Mon Sep 17 00:00:00 2001 From: Mirek Kratochvil Date: Mon, 31 Mar 2025 14:43:04 +0200 Subject: [PATCH 2/4] update checkout action in ci.yaml --- .github/workflows/ci.yaml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 8ebb8c9f..b60b56ee 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -13,7 +13,7 @@ jobs: ghc-version: [96, 98, 910] runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v4 - uses: cachix/install-nix-action@v15 with: nix_path: "${{ env.nixpkgs-url }}" @@ -56,7 +56,7 @@ jobs: name: check formatting with ormolu runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v4 - uses: cachix/install-nix-action@v15 with: nix_path: "${{ env.nixpkgs-url }}" @@ -75,7 +75,7 @@ jobs: name: stack build runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v4 - uses: cachix/install-nix-action@v15 with: nix_path: "${{ env.nixpkgs-url }}" From 8b2815b566af4d16ab0029b7efbeab6c77314bb2 Mon Sep 17 00:00:00 2001 From: Arnaud Spiwack Date: Tue, 1 Apr 2025 22:06:13 +0900 Subject: [PATCH 3/4] Add tests for take/drop --- linear-base.cabal | 7 ++++--- test/Main.hs | 2 ++ test/Test/Data/List.hs | 43 ++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 49 insertions(+), 3 deletions(-) create mode 100644 test/Test/Data/List.hs diff --git a/linear-base.cabal b/linear-base.cabal index 35d60254..db30d1b9 100644 --- a/linear-base.cabal +++ b/linear-base.cabal @@ -170,14 +170,15 @@ test-suite test hs-source-dirs: test other-modules: Test.Data.Destination + Test.Data.Functor.Linear + Test.Data.List Test.Data.Mutable.Array - Test.Data.Mutable.Vector Test.Data.Mutable.HashMap Test.Data.Mutable.Set + Test.Data.Mutable.Vector Test.Data.Polarized - Test.Data.Functor.Linear - Test.Data.V Test.Data.Replicator + Test.Data.V default-language: Haskell2010 build-depends: inspection-testing, diff --git a/test/Main.hs b/test/Main.hs index 8741474b..eee20a1c 100644 --- a/test/Main.hs +++ b/test/Main.hs @@ -5,6 +5,7 @@ module Main where import Test.Data.Destination (destArrayTests) import Test.Data.Functor.Linear (genericTests) +import Test.Data.List (listTests) import Test.Data.Mutable.Array (mutArrTests) import Test.Data.Mutable.HashMap (mutHMTests) import Test.Data.Mutable.Set (mutSetTests) @@ -29,6 +30,7 @@ allTests = mutSetTests, destArrayTests, polarizedArrayTests, + listTests, genericTests ], testGroup diff --git a/test/Test/Data/List.hs b/test/Test/Data/List.hs new file mode 100644 index 00000000..7d1b679c --- /dev/null +++ b/test/Test/Data/List.hs @@ -0,0 +1,43 @@ +{-# LANGUAGE OverloadedStrings #-} +{-# LANGUAGE NoImplicitPrelude #-} + +module Test.Data.List (listTests) where + +import qualified Data.List.Linear as List +import Hedgehog +import qualified Hedgehog.Gen as Gen +import qualified Hedgehog.Range as Range +import Prelude.Linear +import Test.Tasty +import Test.Tasty.Hedgehog (testPropertyNamed) +import qualified Prelude + +listTests :: TestTree +listTests = + testGroup + "List tests" + [ testPropertyNamed "take n ++ drop n = id" "take_drop" take_drop, + testPropertyNamed "length . take n = const n" "take_length" take_length + ] + +take_drop :: Property +take_drop = property $ do + n <- forAll $ Gen.int (Range.linear 0 50) + classify "0" $ n == 0 + xs <- forAll $ Gen.list (Range.linear 0 1000) (Gen.int (Range.linear 0 40)) + classify "length > n" $ Prelude.length xs > n + List.take n xs ++ List.drop n xs === xs + +take_length :: Property +take_length = property $ do + n <- forAll $ Gen.int (Range.linear 0 50) + classify "0" $ n == 0 + xs <- forAll $ Gen.list (Range.linear 0 1000) (Gen.int (Range.linear 0 40)) + classify "length > n" $ Prelude.length xs > n + case Prelude.length xs > n of + True -> do + annotate "Prelude.length xs > n" + Prelude.length (List.take n xs) === n + False -> do + annotate "Prelude.length xs < n" + Prelude.length (List.take n xs) === Prelude.length xs From 4ab7dc7727bb89902bdeb85e4a62a2eb1189c0d3 Mon Sep 17 00:00:00 2001 From: Arnaud Spiwack Date: Tue, 1 Apr 2025 23:24:10 +0900 Subject: [PATCH 4/4] Bump actions/cache and actions/upload-artifact to v4 in CI --- .github/workflows/ci.yaml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index b60b56ee..3d17e464 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -18,7 +18,7 @@ jobs: with: nix_path: "${{ env.nixpkgs-url }}" - name: Cache Cabal dependencies - uses: actions/cache@v2 + uses: actions/cache@v4 with: path: | ~/.cabal/packages @@ -45,7 +45,7 @@ jobs: - name: Run benchmarks run: nix-shell --arg ghcVersion '"${{ matrix.ghc-version }}"' --arg installHls 'false' --pure --run "cabal bench 2>&1 | tee benchmark_ghc${{ matrix.ghc-version }}.txt" - name: Upload benchmark results - uses: actions/upload-artifact@v3 + uses: actions/upload-artifact@v4 with: name: linear-base_benchmarks_ghc${{ matrix.ghc-version }} path: | @@ -61,7 +61,7 @@ jobs: with: nix_path: "${{ env.nixpkgs-url }}" - name: Cache Stack dependencies - uses: actions/cache@v2 + uses: actions/cache@v4 with: path: ~/.stack key: stack-deps-ormolu-${{ runner.os }}-${{ hashFiles('nix/sources.json') }}-v${{ env.cache-invalidation-key }}-${{ hashFiles('stack.yaml.lock') }}-${{ github.sha }} @@ -80,7 +80,7 @@ jobs: with: nix_path: "${{ env.nixpkgs-url }}" - name: Cache Stack dependencies - uses: actions/cache@v2 + uses: actions/cache@v4 with: path: ~/.stack key: stack-deps-${{ runner.os }}-${{ hashFiles('nix/sources.json') }}-v${{ env.cache-invalidation-key }}-${{ hashFiles('stack.yaml.lock', 'linear-base.cabal') }}-${{ github.sha }}