vec 0.1.1.1 → 0.2
raw patch · 9 files changed
+164/−81 lines, 9 filesdep ~base-compatdep ~inspection-testingPVP ok
version bump matches the API change (PVP)
Dependency ranges changed: base-compat, inspection-testing
API changes (from Hackage documentation)
- Data.Vec.DataFamily.SpineStrict: instance Control.Lens.At.Ixed (Data.Vec.DataFamily.SpineStrict.Vec n a)
+ Data.Vec.DataFamily.SpineStrict: instance Data.Type.Nat.InlineInduction n => Control.Lens.At.Ixed (Data.Vec.DataFamily.SpineStrict.Vec n a)
+ Data.Vec.DataFamily.SpineStrict.Pigeonhole: gix :: (Generic i, GFrom i, Generic1 t, GTo t, GFrom t, GEnumSize i ~ GPigeonholeSize t, InlineInduction (GPigeonholeSize t), Functor f) => i -> (a -> f a) -> t a -> f (t a)
- Data.Vec.DataFamily.SpineStrict: ix :: Fin n -> Lens' (Vec n a) a
+ Data.Vec.DataFamily.SpineStrict: ix :: forall n a. InlineInduction n => Fin n -> Lens' (Vec n a) a
Files
- ChangeLog.md +5/−0
- src/Data/Functor/Confusing.hs +44/−17
- src/Data/Vec/DataFamily/SpineStrict.hs +33/−25
- src/Data/Vec/DataFamily/SpineStrict/Pigeonhole.hs +31/−12
- src/Data/Vec/Lazy.hs +3/−4
- src/Data/Vec/Lazy/Inline.hs +8/−10
- src/Data/Vec/Pull.hs +2/−2
- test/Inspection/DataFamily/SpineStrict/Pigeonhole.hs +23/−1
- vec.cabal +15/−10
ChangeLog.md view
@@ -1,5 +1,10 @@ # Revision history for vec +## 0.1.2++- Add `Data.Vec.DataFamily.SpineStrict.gix`+- Add `Data.Vec.DataFamily.SpineStrict.ix` requires `InlineInduction`+ ## 0.1.1.1 - Use `fin-0.1`
src/Data/Functor/Confusing.hs view
@@ -1,4 +1,5 @@ {-# LANGUAGE RankNTypes #-}+{-# LANGUAGE Safe #-} -- | -- Csongor Kiss, Matthew Pickering, and Nicolas Wu. 2018. Generic deriving of generic traversals. -- Proc. ACM Program. Lang. 2, ICFP, Article 85 (July 2018), 30 pages. DOI: https://doi.org/10.1145/3236780@@ -8,24 +9,24 @@ -- This is modified version of part of @generic-lens@ library -- -- Copyright (c) 2018, Csongor Kiss--- +-- -- All rights reserved.--- +-- -- Redistribution and use in source and binary forms, with or without -- modification, are permitted provided that the following conditions are met:--- +-- -- * Redistributions of source code must retain the above copyright -- notice, this list of conditions and the following disclaimer.--- +-- -- * Redistributions in binary form must reproduce the above -- copyright notice, this list of conditions and the following -- disclaimer in the documentation and/or other materials provided -- with the distribution.--- +-- -- * Neither the name of Csongor Kiss nor the names of other -- contributors may be used to endorse or promote products derived -- from this software without specific prior written permission.--- +-- -- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -- "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -- LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR@@ -37,11 +38,17 @@ -- THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -- (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -- OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.--- -module Data.Functor.Confusing where+--+module Data.Functor.Confusing (+ fusing, confusing, LensLike,+ ifusing, iconfusing, IxLensLike,+ ffusing, fconfusing, FLensLike,+ liftCurriedYoneda, yap,+ Curried (..), liftCurried, lowerCurried,+ Yoneda (..), liftYoneda, lowerYoneda,+ ) where -import Prelude ()-import Prelude.Compat+import Control.Applicative ------------------------------------------------------------------------------- -- Confusing@@ -49,15 +56,15 @@ type LensLike f s t a b = (a -> f b) -> s -> f t -confusing :: Applicative f => LensLike (Curried (Yoneda f)) s t a b -> (a -> f b) -> s -> f t-confusing t = \f -> lowerYoneda . lowerCurried . t (liftCurriedYoneda . f)-{-# INLINE confusing #-}+-- note: qualified name to justify import even with newer GHCs -type IxLensLike f i s t a b = (i -> a -> f b) -> s -> f t+fusing :: Functor f => LensLike (Yoneda f) s t a b -> LensLike f s t a b+fusing t = \f -> lowerYoneda . t (liftYoneda . f)+{-# INLINE fusing #-} -iconfusing :: Applicative f => IxLensLike (Curried (Yoneda f)) i s t a b -> (i -> a -> f b) -> s -> f t-iconfusing t = \f -> lowerYoneda . lowerCurried . t (\i a -> liftCurriedYoneda (f i a))-{-# INLINE iconfusing #-}+confusing :: Control.Applicative.Applicative f => LensLike (Curried (Yoneda f)) s t a b -> LensLike f s t a b+confusing t = \f -> lowerYoneda . lowerCurried . t (liftCurriedYoneda . f)+{-# INLINE confusing #-} liftCurriedYoneda :: Applicative f => f a -> Curried (Yoneda f) a liftCurriedYoneda fa = Curried (`yap` fa)@@ -66,6 +73,26 @@ yap :: Applicative f => Yoneda f (a -> b) -> f a -> Yoneda f b yap (Yoneda k) fa = Yoneda (\ab_r -> k (ab_r .) <*> fa) {-# INLINE yap #-}++type IxLensLike f i s t a b = (i -> a -> f b) -> s -> f t++ifusing :: Functor f => IxLensLike (Yoneda f) i s t a b -> IxLensLike f i s t a b+ifusing t = \f -> lowerYoneda . t (\i a -> liftYoneda (f i a))+{-# INLINE ifusing #-}++iconfusing :: Applicative f => IxLensLike (Curried (Yoneda f)) i s t a b -> IxLensLike f i s t a b+iconfusing t = \f -> lowerYoneda . lowerCurried . t (\i a -> liftCurriedYoneda (f i a))+{-# INLINE iconfusing #-}++type FLensLike f s t a b = (forall x. a x -> f (b x)) -> s -> f t++ffusing :: Functor f => FLensLike (Yoneda f) s t a b -> FLensLike f s t a b+ffusing t = \f -> lowerYoneda . t (liftYoneda . f)+{-# INLINE ffusing #-}++fconfusing :: Applicative f => FLensLike (Curried (Yoneda f)) s t a b -> FLensLike f s t a b+fconfusing t = \f -> lowerYoneda . lowerCurried . t (liftCurriedYoneda . f)+{-# INLINE fconfusing #-} ------------------------------------------------------------------------------- -- Curried
src/Data/Vec/DataFamily/SpineStrict.hs view
@@ -1,57 +1,57 @@-{-# LANGUAGE CPP #-}-{-# LANGUAGE DataKinds #-}-{-# LANGUAGE FlexibleInstances #-}-{-# LANGUAGE MultiParamTypeClasses #-}-{-# LANGUAGE RankNTypes #-}-{-# LANGUAGE ScopedTypeVariables #-}-{-# LANGUAGE TypeFamilies #-}-{-# LANGUAGE UndecidableInstances #-}+{-# LANGUAGE CPP #-}+{-# LANGUAGE DataKinds #-}+{-# LANGUAGE FlexibleInstances #-}+{-# LANGUAGE MultiParamTypeClasses #-}+{-# LANGUAGE RankNTypes #-}+{-# LANGUAGE ScopedTypeVariables #-}+{-# LANGUAGE TypeFamilies #-}+{-# LANGUAGE UndecidableInstances #-} -- | Spine-strict length-indexed list defined as data-family: 'Vec'. -- -- Data family variant allows lazy pattern matching. -- On the other hand, the 'Vec' value doesn't "know" its length (i.e. there isn't 'Data.Vec.Lazy.withDict'). ----- == Agda +-- == Agda -- -- If you happen to familiar with Agda, then the difference -- between GADT and data-family version is maybe clearer: -- -- @ -- module Vec where--- +-- -- open import Data.Nat -- open import Relation.Binary.PropositionalEquality using (_≡_; refl)--- +-- -- -- \"GADT" -- data Vec (A : Set) : ℕ → Set where -- [] : Vec A 0 -- _∷_ : ∀ {n} → A → Vec A n → Vec A (suc n)--- +-- -- infixr 50 _∷_--- +-- -- exVec : Vec ℕ 2 -- exVec = 13 ∷ 37 ∷ []--- +-- -- -- "data family" -- data Unit : Set where -- [] : Unit--- +-- -- data _×_ (A B : Set) : Set where -- _∷_ : A → B → A × B--- +-- -- infixr 50 _×_--- +-- -- VecF : Set → ℕ → Set -- VecF A zero = Unit -- VecF A (suc n) = A × VecF A n--- +-- -- exVecF : VecF ℕ 2 -- exVecF = 13 ∷ 37 ∷ []--- +-- -- reduction : VecF ℕ 2 ≡ ℕ × ℕ × Unit -- reduction = refl -- @--- +-- module Data.Vec.DataFamily.SpineStrict ( Vec (..), -- * Construction@@ -290,7 +290,7 @@ -- | 'Vec' doesn't have 'I.At' instance, as we __cannot__ remove value from 'Vec'. -- See 'ix' in "Data.Vec.DataFamily.SpineStrict" module for an 'I.Lens' (not 'I.Traversal').-instance I.Ixed (Vec n a) where+instance N.InlineInduction n => I.Ixed (Vec n a) where ix = ix instance I.Field1 (Vec ('S n) a) (Vec ('S n) a) a a where@@ -484,10 +484,18 @@ -- >>> ('a' ::: 'b' ::: 'c' ::: VNil) & ix (FS FZ) .~ 'x' -- 'a' ::: 'x' ::: 'c' ::: VNil ---ix :: Fin n -> I.Lens' (Vec n a) a-ix FZ f (x ::: xs) = (::: xs) <$> f x-ix (FS n) f (x ::: xs) = (x :::) <$> ix n f xs+ix :: forall n a. N.InlineInduction n => Fin n -> I.Lens' (Vec n a) a+ix = getIxLens $ N.inlineInduction1 start step where+ start :: IxLens 'Z a+ start = IxLens F.absurd + step :: IxLens m a -> IxLens ('S m) a+ step (IxLens l) = IxLens $ \i -> case i of+ FZ -> _head+ FS j -> _tail . l j++newtype IxLens n a = IxLens { getIxLens :: Fin n -> I.Lens' (Vec n a) a }+ -- | Match on non-empty 'Vec'. -- -- /Note:/ @lens@ 'I._Cons' is a 'I.Prism'.@@ -872,7 +880,7 @@ ensureSpine = getEnsureSpine (N.inlineInduction1 first step) where first :: EnsureSpine 'Z a first = EnsureSpine $ \_ -> VNil- + step :: EnsureSpine m a -> EnsureSpine ('S m) a step (EnsureSpine go) = EnsureSpine $ \ ~(x ::: xs) -> x ::: go xs
src/Data/Vec/DataFamily/SpineStrict/Pigeonhole.hs view
@@ -1,19 +1,20 @@-{-# LANGUAGE ConstraintKinds #-}-{-# LANGUAGE DataKinds #-}-{-# LANGUAGE DefaultSignatures #-}-{-# LANGUAGE FlexibleContexts #-}-{-# LANGUAGE FlexibleInstances #-}-{-# LANGUAGE FunctionalDependencies #-}-{-# LANGUAGE PolyKinds #-}-{-# LANGUAGE ScopedTypeVariables #-}-{-# LANGUAGE TypeFamilies #-}-{-# LANGUAGE TypeOperators #-}-{-# LANGUAGE UndecidableInstances #-}+{-# LANGUAGE ConstraintKinds #-}+{-# LANGUAGE DataKinds #-}+{-# LANGUAGE DefaultSignatures #-}+{-# LANGUAGE FlexibleContexts #-}+{-# LANGUAGE FlexibleInstances #-}+{-# LANGUAGE MultiParamTypeClasses #-}+{-# LANGUAGE PolyKinds #-}+{-# LANGUAGE ScopedTypeVariables #-}+{-# LANGUAGE TypeFamilies #-}+{-# LANGUAGE TypeOperators #-}+{-# LANGUAGE UndecidableInstances #-} module Data.Vec.DataFamily.SpineStrict.Pigeonhole ( Pigeonhole (..), -- * Representable gindex, gtabulate,+ gix, -- ** Traversable with index gtraverse, gitraverse,@@ -27,7 +28,7 @@ import Prelude.Compat import Control.Arrow (first)-import Data.Functor.Confusing (confusing, iconfusing)+import Data.Functor.Confusing (confusing, fusing, iconfusing) import Data.Functor.Identity (Identity (..)) import Data.Functor.Product (Product (..)) import Data.Functor.Rep (tabulate)@@ -44,6 +45,8 @@ -- $setup -- >>> :set -XDeriveGeneric -- >>> import Control.Applicative (Const (..))+-- >>> import Control.Lens (view, over)+-- >>> import Data.Char (toUpper) -- >>> import Data.Void (absurd) -- >>> import GHC.Generics (Generic, Generic1) @@ -130,6 +133,22 @@ ) => (i -> a) -> f a gtabulate idx = gto $ tabulate (idx . F.gto)++-- | A lens. @i -> Lens' (t a) a@+--+-- >>> view (gix ()) (Identity 'x')+-- 'x'+--+-- >>> over (gix ()) toUpper (Identity 'x')+-- Identity 'X'+--+gix :: ( G.Generic i, F.GFrom i, G.Generic1 t, GTo t, GFrom t+ , F.GEnumSize i ~ GPigeonholeSize t, N.InlineInduction (GPigeonholeSize t)+ , Functor f+ )+ => i -> (a -> f a) -> t a -> f (t a)+gix i = fusing $ \ab ta -> gto <$> V.ix (F.gfrom i) ab (gfrom ta)+ ------------------------------------------------------------------------------- -- Generic traversable with index
src/Data/Vec/Lazy.hs view
@@ -6,7 +6,6 @@ {-# LANGUAGE FlexibleInstances #-} {-# LANGUAGE FunctionalDependencies #-} {-# LANGUAGE GADTs #-}-{-# LANGUAGE KindSignatures #-} {-# LANGUAGE RankNTypes #-} {-# LANGUAGE ScopedTypeVariables #-} {-# LANGUAGE StandaloneDeriving #-}@@ -77,9 +76,9 @@ import Prelude () import Prelude.Compat- (Bool (..), Eq (..), Functor (..), Int, Maybe (..),- Monad (..), Monoid (..), Num (..), Ord (..), Show (..), id, seq,- showParen, showString, ($), (.), (<$>))+ (Bool (..), Eq (..), Functor (..), Int, Maybe (..), Monad (..),+ Monoid (..), Num (..), Ord (..), Show (..), id, seq, showParen,+ showString, ($), (.), (<$>)) import Control.Applicative (Applicative (..)) import Control.DeepSeq (NFData (..))
src/Data/Vec/Lazy/Inline.hs view
@@ -1,13 +1,11 @@-{-# LANGUAGE DataKinds #-}-{-# LANGUAGE EmptyCase #-}-{-# LANGUAGE FlexibleInstances #-}-{-# LANGUAGE FunctionalDependencies #-}-{-# LANGUAGE GADTs #-}-{-# LANGUAGE KindSignatures #-}-{-# LANGUAGE RankNTypes #-}-{-# LANGUAGE ScopedTypeVariables #-}-{-# LANGUAGE TypeFamilies #-}-{-# LANGUAGE UndecidableInstances #-}+{-# LANGUAGE DataKinds #-}+{-# LANGUAGE FlexibleInstances #-}+{-# LANGUAGE GADTs #-}+{-# LANGUAGE MultiParamTypeClasses #-}+{-# LANGUAGE RankNTypes #-}+{-# LANGUAGE ScopedTypeVariables #-}+{-# LANGUAGE TypeFamilies #-}+{-# LANGUAGE UndecidableInstances #-} -- | A variant of "Data.Vec.Lazy" with functions written using 'N.InlineInduction'. -- The hypothesis is that these (goursive) functions could be fully unrolled, -- if the 'Vec' size @n@ is known at compile time.
src/Data/Vec/Pull.hs view
@@ -58,8 +58,8 @@ import Prelude () import Prelude.Compat- (Bool (..), Eq (..), Functor (..), Int, Maybe (..),- Monad (..), Monoid (..), Num (..), all, const, id, ($), (.), (<$>))+ (Bool (..), Eq (..), Functor (..), Int, Maybe (..), Monad (..),+ Monoid (..), Num (..), all, const, id, ($), (.), (<$>)) import Control.Applicative (Applicative (..)) import Control.Lens ((<&>))
test/Inspection/DataFamily/SpineStrict/Pigeonhole.hs view
@@ -8,10 +8,13 @@ {-# OPTIONS_GHC -dsuppress-module-prefixes #-} {-# OPTIONS_GHC -dsuppress-type-signatures #-} -- {-# OPTIONS_GHC -dsuppress-uniques #-}+-- This makes gix tests pass, default is 60+{-# OPTIONS_GHC -funfolding-use-threshold=200 #-} module Inspection.DataFamily.SpineStrict.Pigeonhole where +import Data.Functor.Compat ((<&>)) import Data.Vec.DataFamily.SpineStrict.Pigeonhole- (gindex, gitraverse, gtabulate, gtraverse)+ (gindex, gitraverse, gix, gtabulate, gtraverse) import GHC.Generics (Generic, Generic1) import Test.Inspection @@ -63,6 +66,25 @@ inspect $ hasNoGenerics 'lhsTabulate inspect $ 'lhsTabulate === 'rhsTabulate++-------------------------------------------------------------------------------+-- Ix+-------------------------------------------------------------------------------++type LensLike' f s a = (a -> f a) -> s -> f s++lhsIx :: Functor f => Key -> LensLike' f (Values a) a+lhsIx = gix++rhsIx :: Functor f => Key -> LensLike' f (Values a) a+rhsIx Key1 f (Values x1 x2 x3 x4 x5) = f x1 <&> \x1' -> Values x1' x2 x3 x4 x5+rhsIx Key2 f (Values x1 x2 x3 x4 x5) = f x2 <&> \x2' -> Values x1 x2' x3 x4 x5+rhsIx Key3 f (Values x1 x2 x3 x4 x5) = f x3 <&> \x3' -> Values x1 x2 x3' x4 x5+rhsIx Key4 f (Values x1 x2 x3 x4 x5) = f x4 <&> \x4' -> Values x1 x2 x3 x4' x5+rhsIx Key5 f (Values x1 x2 x3 x4 x5) = f x5 <&> \x5' -> Values x1 x2 x3 x4 x5'++inspect $ hasNoGenerics 'lhsIx+inspect $ 'lhsIx === 'rhsIx ------------------------------------------------------------------------------- -- Indexed traverse
vec.cabal view
@@ -1,6 +1,6 @@ cabal-version: >=1.10 name: vec-version: 0.1.1.1+version: 0.2 synopsis: Vec: length-indexed (sized) list category: Data, Dependent Types description:@@ -68,7 +68,13 @@ build-type: Simple extra-source-files: ChangeLog.md tested-with:- GHC ==8.8.1 || ==8.6.5 || ==8.4.4 || ==8.2.2 || ==8.0.2 || ==7.10.3 || ==7.8.4+ GHC ==7.8.4+ || ==7.10.3+ || ==8.0.2+ || ==8.2.2+ || ==8.4.4+ || ==8.6.5+ || ==8.8.1 source-repository head type: git@@ -82,18 +88,16 @@ Data.Vec.Lazy.Inline Data.Vec.Pull - other-modules:- Data.Functor.Confusing-+ other-modules: Data.Functor.Confusing build-depends: adjunctions >=4.4 && <4.5- , base >=4.7 && <4.13- , base-compat >=0.9.3 && <0.11- , deepseq >=1.3.0.2 && <1.5+ , base >=4.6 && <4.14+ , base-compat >=0.9.3 && <0.12+ , deepseq >=1.3.0.1 && <1.5 , distributive >=0.5.3 && <0.7 , fin >=0.1 && <0.2 , hashable >=1.2.7.0 && <1.4- , lens >=4.16 && <4.18+ , lens >=4.16 && <4.19 , semigroupoids >=5.2.2 && <5.4 , transformers >=0.3.0.0 && <0.6 @@ -123,8 +127,9 @@ default-language: Haskell2010 build-depends: base+ , base-compat , fin- , inspection-testing >=0.2.0.1 && <0.5+ , inspection-testing >=0.4.2.2 && <0.5 , tagged , vec