packages feed

vinyl 0.2.1 → 0.3

raw patch · 9 files changed

+109/−56 lines, 9 filesdep −transformersdep ~basedep ~vinyl

Dependencies removed: transformers

Dependency ranges changed: base, vinyl

Files

Data/Vinyl/Classes.hs view
@@ -5,8 +5,8 @@  module Data.Vinyl.Classes where -import           Control.Applicative-import           Data.Functor.Identity+import Control.Applicative+import Data.Vinyl.Idiom.Identity  -- | This class is a generalized, but non-pointed version of 'Applicative'. This -- is useful for types which range over functors rather than sets.
+ Data/Vinyl/Idiom/Identity.hs view
@@ -0,0 +1,25 @@+{-# LANGUAGE DeriveFunctor #-}+{-# LANGUAGE DeriveFoldable #-}+{-# LANGUAGE DeriveTraversable #-}++module Data.Vinyl.Idiom.Identity where++import Control.Applicative+import Data.Foldable+import Data.Traversable++newtype Identity a+  = Identity+  { runIdentity :: a+  } deriving (Functor, Foldable, Traversable)++instance Applicative Identity where+  pure = Identity+  (Identity f) <*> (Identity x) = Identity (f x)++instance Monad Identity where+  return = Identity+  (Identity x) >>= f = f x++instance Show a => Show (Identity a) where+  show (Identity x) = show x
+ Data/Vinyl/Idiom/LazyIdentity.hs view
@@ -0,0 +1,25 @@+{-# LANGUAGE DeriveFunctor #-}+{-# LANGUAGE DeriveFoldable #-}+{-# LANGUAGE DeriveTraversable #-}++module Data.Vinyl.Idiom.LazyIdentity where++import Control.Applicative+import Data.Foldable+import Data.Traversable++data LazyIdentity a+  = LazyIdentity+  { runLazyIdentity :: a+  } deriving (Functor, Foldable, Traversable)++instance Applicative LazyIdentity where+  pure = LazyIdentity+  (LazyIdentity f) <*> (LazyIdentity x) = LazyIdentity (f x)++instance Monad LazyIdentity where+  return = LazyIdentity+  (LazyIdentity x) >>= f = f x++instance Show a => Show (LazyIdentity a) where+  show (LazyIdentity x) = show x
+ Data/Vinyl/Idiom/Validation.hs view
@@ -0,0 +1,31 @@+{-# LANGUAGE TypeOperators #-}++module Data.Vinyl.Idiom.Validation where++import Control.Applicative+import Data.Monoid+import Data.Vinyl.Classes+import Data.Vinyl.Idiom.Identity++-- | A type which is similar to 'Either', except that it has a+-- slightly different Applicative instance.+data Result e a+  = Failure e+  | Success a+  deriving (Show, Eq)++-- | Validators transform identities into results.+type Validator e = Identity ~> Result e++instance Functor (Result e) where+  fmap f (Success x) = Success $ f x+  fmap f (Failure e) = Failure e++-- | The 'Applicative' instance to 'Result' relies on its error type+-- being a 'Monoid'. That way, it can accumulate errors.+instance Monoid e => Applicative (Result e) where+  pure = Success+  (Success f) <*> (Success x)  = Success $ f x+  (Failure e) <*> (Success x)  = Failure e+  (Success f) <*> (Failure e)  = Failure e+  (Failure e) <*> (Failure e') = Failure $ e <> e'
Data/Vinyl/Lens.hs view
@@ -7,7 +7,7 @@ -- compatible with the @lens@ package. module Data.Vinyl.Lens where import Control.Applicative-import Data.Functor.Identity+import Data.Vinyl.Idiom.Identity import Data.Vinyl.Field import Data.Vinyl.Rec import Data.Vinyl.Witnesses@@ -71,7 +71,7 @@ -- | A lens into a 'PlainRec' that smoothly interoperates with lenses -- from the @lens@ package. Note that polymorphic update is not -- supported. In the parlance of the @lens@ package,--- +-- -- > rLens :: IElem (sy:::t) rs => (sy:::t) -> Lens' (PlainRec rs) t rLens :: forall r rs sy t g. (r ~ (sy:::t), IElem r rs, Functor g)       => r -> (t -> g t) -> PlainRec rs -> g (PlainRec rs)
Data/Vinyl/Rec.hs view
@@ -18,6 +18,7 @@ module Data.Vinyl.Rec   ( Rec(..)   , PlainRec+  , LazyPlainRec   , (=:)   , (<+>)   , (<-:)@@ -25,28 +26,33 @@   , fixRecord   ) where -import           Data.Vinyl.Classes-import           Control.Applicative-import           Data.Functor.Identity-import           Data.Vinyl.Field-import           Foreign.Ptr (castPtr, plusPtr)-import           Foreign.Storable (Storable(..))-import           GHC.TypeLits-import           Data.Monoid+import Data.Vinyl.Classes+import Control.Applicative+import Data.Vinyl.Idiom.Identity+import Data.Vinyl.Idiom.LazyIdentity+import Data.Vinyl.Field+import Foreign.Ptr (castPtr, plusPtr)+import Foreign.Storable (Storable(..))+import GHC.TypeLits+import Data.Monoid  -- | A record is parameterized by a list of fields and a functor -- to be applied to each of those fields. data Rec :: [*] -> (* -> *) -> * where   RNil :: Rec '[] f-  (:&) :: f t -> Rec rs f -> Rec ((sy ::: t) ': rs) f+  (:&) :: !(f t) -> !(Rec rs f) -> Rec ((sy ::: t) ': rs) f infixr :&  -- | Fixes a polymorphic record into the 'Identity' functor. fixRecord :: (forall f. Applicative f => Rec rs f) -> PlainRec rs fixRecord xs = xs +fixRecordLazy :: (forall f. Applicative f => Rec rs f) -> LazyPlainRec rs+fixRecordLazy xs = xs+ -- | Fields of plain records are in the 'Identity' functor. type PlainRec rs = Rec rs Identity+type LazyPlainRec rs = Rec rs LazyIdentity  -- | Append for records. (<+>) :: Rec as f -> Rec bs f -> Rec (as ++ bs) f@@ -119,10 +125,6 @@ -- | Accumulates a homogenous record into a list recToList :: FoldRec (Rec fs g) (g t) => Rec fs g -> [g t] recToList = foldRec (\e a -> [e] ++ a) []---- | We provide a 'Show' instance for 'Identity'.-instance Show a => Show (Identity a) where-  show (Identity x) = show x  instance Storable (PlainRec '[]) where   sizeOf _    = 0
− Data/Vinyl/Validation.hs
@@ -1,31 +0,0 @@-{-# LANGUAGE TypeOperators #-}--module Data.Vinyl.Validation where--import           Control.Applicative-import           Data.Functor.Identity-import           Data.Monoid-import           Data.Vinyl.Classes---- | A type which is similar to 'Either', except that it has a--- slightly different Applicative instance.-data Result e a-  = Failure e-  | Success a-  deriving (Show, Eq)---- | Validators transform identities into results.-type Validator e = Identity ~> Result e--instance Functor (Result e) where-  fmap f (Success x) = Success $ f x-  fmap f (Failure e) = Failure e---- | The 'Applicative' instance to 'Result' relies on its error type--- being a 'Monoid'. That way, it can accumulate errors.-instance Monoid e => Applicative (Result e) where-  pure = Success-  (Success f) <*> (Success x)  = Success $ f x-  (Failure e) <*> (Success x)  = Failure e-  (Success f) <*> (Failure e)  = Failure e-  (Failure e) <*> (Failure e') = Failure $ e <> e'
tests/Intro.lhs view
@@ -22,10 +22,10 @@ > {-# LANGUAGE GADTs #-} > import Data.Vinyl > import Data.Vinyl.Unicode-> import Data.Vinyl.Validation+> import Data.Vinyl.Idiom.Identity+> import Data.Vinyl.Idiom.Validation > import Control.Applicative-> import Control.Lens-> import Data.Functor.Identity+> import Control.Lens hiding (Identity) > import Data.Char > import Test.DocTest 
vinyl.cabal view
@@ -1,5 +1,5 @@ name:                vinyl-version:             0.2.1+version:             0.3 synopsis:            Extensible Records -- description: license:             MIT@@ -22,15 +22,16 @@   exposed-modules:     Data.Vinyl, Data.Vinyl.Field, Data.Vinyl.Lens,                        Data.Vinyl.Witnesses, Data.Vinyl.Rec,                        Data.Vinyl.Relation, Data.Vinyl.Unicode,-                       Data.Vinyl.Classes, Data.Vinyl.Validation-  build-depends:       base >=4.6 && <= 5, ghc-prim, transformers+                       Data.Vinyl.Classes, Data.Vinyl.Idiom.Validation,+                       Data.Vinyl.Idiom.Identity, Data.Vinyl.Idiom.LazyIdentity+  build-depends:       base >=4.6 && <= 5, ghc-prim   default-language:    Haskell2010  benchmark bench-builder-all   type:             exitcode-stdio-1.0   hs-source-dirs:   benchmarks   main-is:          StorableBench.hs-  build-depends:    base >= 4.6 && <= 5, vector, criterion, vinyl, mwc-random, lens, linear+  build-depends:    base >= 4.6 && <= 5, vector, criterion, vinyl == 0.3, mwc-random, lens, linear   ghc-options:      -O2 -fllvm   default-language: Haskell2010 @@ -38,5 +39,5 @@   type:             exitcode-stdio-1.0   hs-source-dirs:   tests   main-is:          Intro.lhs-  build-depends:    base >= 4.6 && <= 5, lens, transformers, vinyl, doctest >= 0.8+  build-depends:    base >= 4.6 && <= 5, lens, vinyl == 0.3, doctest >= 0.8   default-language: Haskell2010