Skip to content

Commit

Permalink
Merge branch 'master' into koz/indexed-traversable
Browse files Browse the repository at this point in the history
  • Loading branch information
kozross committed Jan 22, 2022
2 parents 044f8be + 7c29f2c commit ed2ebdc
Show file tree
Hide file tree
Showing 18 changed files with 127 additions and 171 deletions.
3 changes: 1 addition & 2 deletions .github/pull_request_template.md
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
Please don't forget to add to the "WIP" section of the changelog and run
`hpack` if appropriate!
Please don't forget to add to the "WIP" section of the changelog!
126 changes: 50 additions & 76 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,93 +4,67 @@ on: [pull_request]

jobs:
cabal:

name: "Cabal: ${{ matrix.ghc }} on ${{ matrix.os }}"
runs-on: ${{ matrix.os }}
strategy:
matrix:
ghc: ['8.10.1', '8.8.3', '8.6.5', '8.4.4', '8.2.2', '8.0.2']
cabal: ['3.0']
os: [ubuntu-latest]

runs-on: ${{ matrix.os }}


ghc: ['8.10', '9.0', '9.2']
os: [ubuntu-latest, windows-latest, macos-latest]
steps:
- uses: actions/checkout@v2
- uses: actions/setup-haskell@v1
- name: Checkout base repo
uses: actions/[email protected]
- name: Set up Haskell
id: setup-haskell
uses: haskell/actions/setup@v1
with:
ghc-version: ${{ matrix.ghc }}
cabal-version: ${{ matrix.cabal }}

- uses: actions/cache@v1
name: Cache ~/.cabal/packages
with:
path: ~/.cabal/packages
key: ${{ runner.os }}-${{ matrix.ghc }}-cabal-packages
- uses: actions/cache@v1
name: Cache ~/.cabal/store
cabal-version: 'latest'
- name: Configure
run: cabal new-configure
- name: Freeze
run: cabal freeze
- name: Cache
uses: actions/[email protected]
with:
path: ~/.cabal/store
key: ${{ runner.os }}-${{ matrix.ghc }}-cabal-store
- uses: actions/cache@v1
name: Cache dist-newstyle
with:
path: dist-newstyle
key: ${{ runner.os }}-${{ matrix.ghc }}-dist-newstyle

- name: Install dependencies
run: |
cabal update
cabal build --only-dependencies --enable-tests --enable-benchmarks
path: ${{ steps.setup-haskell.outputs.cabal-store }}
key: ${{ runner.os }}-${{ matrix.ghc }}-${{ hashFiles('cabal.project.freeze') }}
restore-keys: ${{ runner.os }}-${{ matrix.ghc }}-
- name: Build
run: cabal build --enable-tests --enable-benchmarks all

run: cabal build
stack:

name: "Stack: ${{ matrix.resolver }} on ${{ matrix.os }}"
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-latest]
stack-args: ['']

runs-on: ${{ matrix.os }}

os: [ubuntu-latest, windows-latest, macos-latest]
resolver: ['lts-18.22', 'nightly-2022-01-20']
steps:
- uses: actions/checkout@v2
- uses: actions/setup-haskell@v1
with:
stack-version: 'latest'

- name: Cache stack global package db
id: stack-global
uses: actions/cache@v1
with:
path: ~/.stack
key: ${{ runner.os }}-stack-global-${{ matrix.stack-args }}-${{ hashFiles('**.yaml') }}
restore-keys: |
${{ runner.os }}-stack-global-${{ matrix.stack-args }}
${{ runner.os }}-stack-global
- name: Cache .stack-work
id: stack-work
uses: actions/cache@v1
with:
path: .stack-work
key: ${{ runner.os }}-stack-work-${{ matrix.stack-args }}-${{ hashFiles('**.yaml') }}
restore-keys: |
${{ runner.os }}-stack-work-${{ matrix.stack-args }}
${{ runner.os }}-stack-work
- name: Install dependencies
run: |
stack build --test --bench --only-dependencies $ARGS
env:
ARGS: ${{ matrix.args }}

- name: Build
run: |
stack build $ARGS
env:
ARGS: ${{ matrix.args }}

- name: Checkout base repo
uses: actions/[email protected]
- name: Set up Haskell
id: setup-haskell
uses: haskell/actions/setup@v1
with:
stack-version: 'latest'
- name: Cache Stack global package DB
uses: actions/[email protected]
with:
path: ~/.stack
key: ${{ runner.os }}-stack-global-${{ matrix.resolver }}-${{ hashFiles('**.yaml') }}
restore-keys: ${{ runner.os }}-stack-global-${{ matrix.resolver }}
- name: Cache .stack-work
uses: actions/[email protected]
with:
path: .stack-work
key: ${{ runner.os }}-stack-work-${{ matrix.resolver}}-${{ hashFiles('**.yaml') }}
restore-keys: ${{ runner.os }}-stack-work-${{ matrix.resolver }}
# https://github.com/commercialhaskell/stack/issues/5405
- name: Clear setup-exe-cache directory
if: runner.os == 'macOS'
continue-on-error: true
run: rm -r ~/.stack/setup-exe-cache
- name: Build
run: stack build --resolver=${{ matrix.resolver }}
nix:
runs-on: ubuntu-latest
steps:
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/tag-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,5 @@ jobs:
fetch-depth: 0 # Fetch everything
ssh-key: ${{ secrets.DEPLOY_KEY }}
- uses: expipiplus1/tag-latest-release/tag-latest-release@HEAD
with:
tagsAndFiles: v vector-sized.cabal
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
.ghc.environment.*
cabal.project.local
cabal.project.local*
dist
dist-*
cabal-dev
Expand All @@ -19,3 +19,4 @@ cabal.sandbox.config
.stack-work/
.nvimrc
.vimrc

5 changes: 5 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@

- Add instances of `FunctorWithIndex`, `FoldableWithIndex` and
`TraversableWithIndex` for `Vector n a`.
- Drop support for GHC older than 8.10
- Safe construction of vectors from linked lists
- https://github.com/expipiplus1/vector-sized/pull/88

Thanks to @sheaf and @kozross

## [1.5.0] - 2021-08-25

Expand Down
32 changes: 0 additions & 32 deletions package.yaml

This file was deleted.

5 changes: 0 additions & 5 deletions src/Data/Vector/Generic/Mutable/Sized.hs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
{-# LANGUAGE CPP #-}
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE FlexibleInstances #-}
Expand Down Expand Up @@ -68,10 +67,8 @@ module Data.Vector.Generic.Mutable.Sized
, unsafeModify
, unsafeSwap
, unsafeExchange
#if MIN_VERSION_vector(0,12,0)
-- * Modifying vectors
, nextPermutation
#endif
-- ** Filling and copying
, set
, copy
Expand Down Expand Up @@ -386,7 +383,6 @@ unsafeExchange :: forall v n m a. (PrimMonad m, VGM.MVector v a)
unsafeExchange (MVector v) = VGM.unsafeExchange v
{-# inline unsafeExchange #-}

#if MIN_VERSION_vector(0,12,0)
-- * Modifying vectors

-- | Compute the next permutation (in lexicographic order) of a given vector
Expand All @@ -395,7 +391,6 @@ nextPermutation :: forall v n e m. (Ord e, PrimMonad m, VGM.MVector v e)
=> MVector v n (PrimState m) e -> m Bool
nextPermutation (MVector v) = VGM.nextPermutation v
{-# inline nextPermutation #-}
#endif

-- ** Filling and copying

Expand Down
36 changes: 26 additions & 10 deletions src/Data/Vector/Generic/Sized.hs
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,12 @@
{-# LANGUAGE TypeApplications #-}
{-# LANGUAGE PatternSynonyms #-}
{-# LANGUAGE ViewPatterns #-}
{-# LANGUAGE CPP #-}
{-# LANGUAGE StandaloneDeriving #-}
{-# LANGUAGE GADTs #-}
{-# LANGUAGE UndecidableInstances #-}
{-# LANGUAGE AllowAmbiguousTypes #-}
{-# LANGUAGE MultiParamTypeClasses #-}

#if MIN_VERSION_base(4,12,0)
{-# LANGUAGE NoStarIsType #-}
#endif

{-# OPTIONS_GHC -Wno-orphans #-}
{-|
Expand Down Expand Up @@ -67,6 +65,8 @@ module Data.Vector.Generic.Sized
, empty
, singleton
, fromTuple
, BuildVector(..)
, pattern Build
, replicate
, replicate'
, generate
Expand Down Expand Up @@ -326,9 +326,13 @@ instance KnownNat n => Applicative (Vector Boxed.Vector n) where
-- @'join' :: Vector n (Vector n a) -> Vector n a@ gets the /diagonal/ from
-- a square "matrix".
instance KnownNat n => Monad (Vector Boxed.Vector n) where
<<<<<<< HEAD
return = pure
xs >>= f = imap (\i x -> f x `index` i) xs
(>>) = (*>)
=======
xs >>= f = imap (\i x -> f x `index` i) xs
>>>>>>> master

-- | Non-empty sized vectors are lawful comonads.
--
Expand Down Expand Up @@ -371,11 +375,6 @@ instance (Semigroup g, VG.Vector v g) => Semigroup (Vector v n g) where
-- 'Monoid' will dodge the 'KnownNat' constraint.
instance (Monoid m, VG.Vector v m, KnownNat n) => Monoid (Vector v n m) where
mempty = replicate mempty
#if MIN_VERSION_base(4,11,0)
-- begone, non-canonical mappend!
#else
mappend = zipWith mappend
#endif
mconcat vs = generate $ mconcat . flip fmap vs . flip index

instance KnownNat n => Distributive (Vector Boxed.Vector n) where
Expand Down Expand Up @@ -655,7 +654,7 @@ singleton :: forall v a. (VG.Vector v a)
singleton a = Vector (VG.singleton a)
{-# inline singleton #-}

-- | /O(n)/ Construct a vector in a type-safe manner.
-- | /O(n)/ Construct a vector in a type-safe manner using a tuple.
-- @
-- fromTuple (1,2) :: Vector v 2 Int
-- fromTuple ("hey", "what's", "going", "on") :: Vector v 4 String
Expand All @@ -665,6 +664,23 @@ fromTuple :: forall v a input length.
=> input -> Vector v length a
fromTuple = Vector . VG.fromListN (fromIntegral $ natVal $ Proxy @length) . ILL.toList

infixr 5 :<
data BuildVector (n :: Nat) a where
Nil :: BuildVector 0 a
(:<) :: a -> BuildVector n a -> BuildVector (1 + n) a
deriving instance Show a => Show (BuildVector n a)

-- | /O(n)/ Construct a vector in a type-safe manner using a sized linked list.
-- @
-- Build (1 :< 2 :< 3 :< Nil) :: Vector v 3 Int
-- Build ("not" :< "much" :< Nil) :: Vector v 2 String
-- @
-- Can also be used as a pattern.
pattern Build :: VG.Vector v a => BuildVector n a -> Vector v n a
pattern Build build <- ( ( \ ( Vector v ) -> unsafeCoerce $ VG.toList v ) -> build )
where
Build vec = Vector . VG.fromList . unsafeCoerce $ vec

-- | /O(n)/ Construct a vector with the same element in each position where the
-- length is inferred from the type.
replicate :: forall v n a. (KnownNat n, VG.Vector v a)
Expand Down
5 changes: 0 additions & 5 deletions src/Data/Vector/Mutable/Sized.hs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
{-# LANGUAGE CPP #-}
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE RankNTypes #-}
Expand Down Expand Up @@ -64,10 +63,8 @@ module Data.Vector.Mutable.Sized
, unsafeModify
, unsafeSwap
, unsafeExchange
#if MIN_VERSION_vector(0,12,0)
-- * Modifying vectors
, nextPermutation
#endif
-- ** Filling and copying
, set
, copy
Expand Down Expand Up @@ -378,7 +375,6 @@ unsafeExchange :: forall n m a. PrimMonad m
unsafeExchange = VGM.unsafeExchange
{-# inline unsafeExchange #-}

#if MIN_VERSION_vector(0,12,0)
-- * Modifying vectors

-- | Compute the next permutation (lexicographically) of a given vector
Expand All @@ -387,7 +383,6 @@ nextPermutation :: forall n e m. (Ord e, PrimMonad m)
=> MVector n (PrimState m) e -> m Bool
nextPermutation = VGM.nextPermutation
{-# inline nextPermutation #-}
#endif

-- ** Filling and copying

Expand Down
5 changes: 0 additions & 5 deletions src/Data/Vector/Primitive/Mutable/Sized.hs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
{-# LANGUAGE CPP #-}
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE RankNTypes #-}
Expand Down Expand Up @@ -64,10 +63,8 @@ module Data.Vector.Primitive.Mutable.Sized
, unsafeModify
, unsafeSwap
, unsafeExchange
#if MIN_VERSION_vector(0,12,0)
-- * Modifying vectors
, nextPermutation
#endif
-- ** Filling and copying
, set
, copy
Expand Down Expand Up @@ -379,7 +376,6 @@ unsafeExchange :: forall n m a. (PrimMonad m, Prim a)
unsafeExchange = VGM.unsafeExchange
{-# inline unsafeExchange #-}

#if MIN_VERSION_vector(0,12,0)
-- * Modifying vectors

-- | Compute the next permutation (lexicographically) of a given vector
Expand All @@ -388,7 +384,6 @@ nextPermutation :: forall n e m. (Ord e, PrimMonad m, Prim e)
=> MVector n (PrimState m) e -> m Bool
nextPermutation = VGM.nextPermutation
{-# inline nextPermutation #-}
#endif

-- ** Filling and copying

Expand Down
Loading

0 comments on commit ed2ebdc

Please sign in to comment.