packages feed

vinyl 0.10.0.1 → 0.11.0

raw patch · 5 files changed

+41/−12 lines, 5 filesdep ~basedep ~hspec

Dependency ranges changed: base, hspec

Files

CHANGELOG.md view
@@ -1,3 +1,9 @@+# 0.11.0++- Changed the `Show` instance of `CoRec`+- Added the `corec` helper that specifically helps type inference when+  constructing `CoRec ElField` values.+ # 0.10.0  - Changed the types of `Data.Vinyl.CoRec.onCoRec` and `Data.Vinyl.CoRec.onField`. This was pushing through the changes to drop the use of `Proxy` arguments, relying instead on `TypeApplications`. Also added `onCoRec1` and `onField` to work with functions relying on a single type class.
Data/Vinyl/CoRec.hs view
@@ -17,12 +17,27 @@ import Data.Vinyl.Lens (RElem, rget, rput, type (∈)) import Data.Vinyl.Functor (Compose(..), (:.), Identity(..), Const(..)) import Data.Vinyl.TypeLevel+import Data.Vinyl.Derived (FieldType, (:::))+import GHC.TypeLits (Symbol, KnownSymbol)+import GHC.Types (type Type)+ import Unsafe.Coerce (unsafeCoerce)  -- | Generalize algebraic sum types. data CoRec :: (k -> *) -> [k] -> * where   CoRec :: RElem a ts (RIndex a ts) => !(f a) -> CoRec f ts +-- | A 'CoRec' constructor with better inference. If you have a label+-- that should pick out a type from the list of types that index a+-- 'CoRec', this function will help you more so than the raw 'CoRec'+-- data constructor.+corec :: forall (l :: Symbol)+                (ts :: [(Symbol,Type)])+                (f :: (Symbol,Type) -> Type).+         (KnownSymbol l, (l ::: FieldType l ts) ∈ ts)+      => f (l ::: FieldType l ts) -> CoRec f ts+corec x = CoRec x+ -- | Apply a function to a 'CoRec' value. The function must accept -- /any/ variant. foldCoRec :: (forall a. RElem a ts (RIndex a ts) => f a -> b) -> CoRec f ts -> b@@ -35,9 +50,17 @@ -- reverse order. newtype Op b a = Op { runOp :: a -> b } -instance forall ts. (RPureConstrained Show ts, RecApplicative ts)-  => Show (CoRec Identity ts) where-  show x = "(Col " ++ onField @Show show x++")"+-- | Helper for writing a 'Show' instance for 'CoRec'. This lets us+-- ask for a 'Show' constraint on the type formed by applying a type+-- constructor to a type index.+class ShowF f a where+  showf :: f a -> String++instance Show (f a) => ShowF f a where+  showf = show++instance forall f ts. RPureConstrained (ShowF f) ts => Show (CoRec f ts) where+  show x = "{|" ++ onCoRec @(ShowF f) showf x ++ "|}"  instance forall ts. (RecApplicative ts, RecordToList ts,                      RApply ts, ReifyConstraint Eq Maybe ts, RMap ts)
Data/Vinyl/Core.hs view
@@ -285,6 +285,10 @@   rpureConstrained _ = RNil   {-# INLINE rpureConstrained #-} +instance (c x, RPureConstrained c xs) => RPureConstrained c (x ': xs) where+  rpureConstrained f = f :& rpureConstrained @c @xs f+  {-# INLINE rpureConstrained #-}+ -- | Capture a type class instance dictionary. See -- 'Data.Vinyl.Lens.getDict' for a way to obtain a 'DictOnly' value -- from an 'RPureConstrained' constraint.@@ -296,10 +300,6 @@ -- @MyClass@. This helper can then be used to eliminate the original. withPairedDict :: (c a => f a -> r) -> Product (DictOnly c) f a -> r withPairedDict f (Pair DictOnly x) = f x--instance (c x, RPureConstrained c xs) => RPureConstrained c (x ': xs) where-  rpureConstrained f = f :& rpureConstrained @c @xs f-  {-# INLINE rpureConstrained #-}  -- | Build a record whose elements are derived solely from a -- list of constraint constructors satisfied by each.
tests/CoRecSpec.hs view
@@ -1,5 +1,5 @@-{-# LANGUAGE CPP, DataKinds, FlexibleContexts,-             ScopedTypeVariables, TypeApplications, TypeOperators #-}+{-# LANGUAGE CPP, DataKinds, FlexibleContexts, ScopedTypeVariables,+             TypeApplications, TypeOperators #-} {-# OPTIONS_GHC -fdefer-type-errors #-} module CoRecSpec (spec) where import Control.Monad ((>=>))@@ -27,7 +27,7 @@ fun3 x = if x == 7 then Right () else Left (CoRec (pure Not7))  spec :: SpecWith ()-spec = do+spec =   describe "CoRecs" $ do     let x = CoRec (pure True) :: Field '[Int,Bool,()]     it "Can be cast successfully" $
vinyl.cabal view
@@ -1,5 +1,5 @@ name:                vinyl-version:             0.10.0.1+version:             0.11.0 synopsis:            Extensible Records -- description: license:             MIT@@ -12,7 +12,7 @@ build-type:          Simple cabal-version:       >=1.10 extra-source-files:  CHANGELOG.md-tested-with:         GHC == 8.0.2, GHC == 8.2.2, GHC == 8.4.3+tested-with:         GHC == 8.0.2, GHC == 8.2.2, GHC == 8.4.4, GHC == 8.6.2  description: Extensible records for Haskell with lenses.