data-has 0.3.0.0 → 0.4.0.0
raw patch · 3 files changed
+36/−21 lines, 3 filesdep −base-compatdep ~basePVP ok
version bump matches the API change (PVP)
Dependencies removed: base-compat
Dependency ranges changed: base
API changes (from Hackage documentation)
- Data.Has: instance Data.Has.Has b (a, b)
+ Data.Has: infixr 1 :*:
+ Data.Has: instance Data.Has.Has b bs => Data.Has.Has b (a, bs)
+ Data.Has: pattern (:*:) :: a -> b -> (a, b)
+ Data.Has: type Lens t a = forall f. Functor f => (a -> f a) -> t -> f t
+ Data.Has: type a :*: b = (a, b)
- Data.Has: class Has a t where getter = getConst . hasLens Const modifier f t = runIdentity (hasLens (Identity . f) t) hasLens afa t = (\ a -> modifier (const a) t) <$> afa (getter t)
+ Data.Has: class Has a t
Files
- CHANGELOG +5/−1
- Data/Has.hs +29/−14
- data-has.cabal +2/−6
CHANGELOG view
@@ -1,3 +1,8 @@+# v0.4.0.0++* Add `:*:` type operator and pattern synonym for tuple.+* Drop GHC < 7.10 support.+ # v0.3.0.0 * Add `hasLens`, thanks @pavelkogan!@@ -9,5 +14,4 @@ # v0.2.0.0 * Change `get/modify` to `getter/modifier` to reduce naming collision, namely `get/modify` would collide with `MonadState`.- * Add tuple instances up to 12 elements.
Data/Has.hs view
@@ -1,7 +1,8 @@ {-# LANGUAGE MultiParamTypeClasses #-} {-# LANGUAGE FlexibleInstances #-} {-# LANGUAGE RankNTypes #-}-{-# LANGUAGE CPP #-}+{-# LANGUAGE PatternSynonyms #-}+{-# LANGUAGE TypeOperators #-} {-| Module : Data.Has@@ -64,21 +65,34 @@ @ ... (3 :: Int, "hello" :: String, ...) @ --}+This module also provide infix type operator and pattern synonym of tuple, i.e. inductive procducts,+which is more convenient to write. An overlapping instance prefer first(left) one is provided: -module Data.Has (Has(..)) where+@+> getter (True :*: "hello" :*: 1) :: Integer+> 1+> getter (1 :*: 2 :*: 3) :: Integer+> 1+@ -import Data.Functor-import Data.Functor.Identity+-} -#if MIN_VERSION_base(4,9,0)-import Data.Functor.Const-#else-import Data.Functor.Const.Compat-#endif+module Data.Has where +import Data.Functor.Identity ( Identity(Identity, runIdentity) )+import Control.Applicative ( Const(Const, getConst) )+ type Lens t a = forall f. Functor f => (a -> f a) -> t -> f t +-- | Infix version of tuple(right associative).+type a :*: b = (a, b)++-- | Infix pattern alias for tuple(right associative).+pattern (:*:) :: a -> b -> (a, b)+pattern a :*: b = (a, b)++infixr 1 :*:+ -- | A type class for extensible product. -- -- We provide instances for tuples up to 12 elements by default.@@ -101,15 +115,16 @@ modifier = id {-# INLINABLE modifier #-} -instance Has a (a, b) where+instance {-# OVERLAPPING #-} Has a (a, b) where getter (a, _) = a {-# INLINABLE getter #-} modifier f (a, b) = (f a, b) {-# INLINABLE modifier #-}-instance Has b (a, b) where- getter (_, b) = b++instance {-# OVERLAPPABLE #-} Has b bs => Has b (a, bs) where+ getter (_, bs) = getter bs {-# INLINABLE getter #-}- modifier f (a, b) = (a, f b)+ modifier f (a, b) = (a, modifier f b) {-# INLINABLE modifier #-} --------------------------------------------------------------------------------
data-has.cabal view
@@ -1,5 +1,5 @@ name: data-has-version: 0.3.0.0+version: 0.4.0.0 synopsis: Simple extensible product description: Simple extensible product license: BSD3@@ -21,11 +21,7 @@ exposed-modules: Data.Has -- other-modules: -- other-extensions: - build-depends: base < 5- if impl(ghc < 8)- build-depends: base-compat >= 0.9- if impl(ghc < 7.10)- build-depends: transformers+ build-depends: base >= 4.8 && < 5 -- hs-source-dirs: default-language: Haskell2010