packages feed

constraints-extras 0.3 → 0.3.0.1

raw patch · 4 files changed

+130/−123 lines, 4 filesPVP ok

version bump matches the API change (PVP)

API changes (from Hackage documentation)

Files

ChangeLog.md view
@@ -1,5 +1,9 @@ # Revision history for constraints-extras +## 0.3.0.1 - 2019-05-17++* Drop markdown-unlit in favor of using regular "Bird"-style LHS to avoid some cross-compilation problems+ ## 0.3 - 2019-05-16  * Added a parameter for the type class, to allow for custom not-fully-polymorphic instances of ArgDict in cases where e.g. your key type contains dictionaries for specific classes. You will now need FlexibleInstances, MultiParamTypeClasses for the instances created by deriveArgDict.
README.lhs view
@@ -1,64 +1,67 @@-# constraints-extras--## Example usage:+constraints-extras+================== -NB: This example can be built with `-pgmL markdown-unlit`.+Example usage:+--------------  ```haskell-{-# LANGUAGE GADTs #-}-{-# LANGUAGE KindSignatures #-}-{-# LANGUAGE PolyKinds #-}-{-# LANGUAGE ScopedTypeVariables #-}-{-# LANGUAGE TemplateHaskell #-}-{-# LANGUAGE TypeApplications  #-}-{-# LANGUAGE TypeFamilies #-}-{-# LANGUAGE FlexibleInstances #-}-{-# LANGUAGE MultiParamTypeClasses #-}-{-# LANGUAGE UndecidableInstances #-}-{-# LANGUAGE ExistentialQuantification #-} -import Data.Aeson-import Data.Constraint.Forall-import Data.Constraint.Extras-import Data.Constraint.Extras.TH--data A :: * -> * where-  A_a :: A Int-  A_b :: Int -> A ()--data B :: * -> * where-  B_a :: A a -> A a -> B a-  B_x :: Int -> B Int--data V :: (* -> *) -> * where-  V_a :: A Int -> V A--deriveArgDict ''A-deriveArgDict ''B-deriveArgDict ''V--data DSum k f = forall a. DSum (k a) (f a)---- Derive a ToJSON instance for our 'DSum'-instance forall k f.-  ( Has' ToJSON k f -- Given a value of type (k a), we can obtain an instance (ToJSON (f a))-  , ForallF ToJSON k -- For any (a), we have an instance (ToJSON (k a))-  ) => ToJSON (DSum k f) where-  toJSON (DSum (k :: k a) f) = toJSON-    ( whichever @ToJSON @k @a $ toJSON k -- Use the (ForallF ToJSON k) constraint to obtain the (ToJSON (k a)) instance-    , has' @ToJSON @f k $ toJSON f -- Use the (Has' ToJSON k f) constraint to obtain the (ToJSON (f a)) instance-    )--data Some k = forall a. Some (k a)---- Derive a FromJSON instance for our 'DSum'-instance (FromJSON (Some f), Has' FromJSON f g) => FromJSON (DSum f g) where-  parseJSON x = do-    (jf, jg) <- parseJSON x-    Some (f :: f a) <- parseJSON jf-    g <- has' @FromJSON @g f (parseJSON jg)-    return $ DSum f g--main :: IO ()-main = return ()+> {-# LANGUAGE GADTs #-}+> {-# LANGUAGE KindSignatures #-}+> {-# LANGUAGE PolyKinds #-}+> {-# LANGUAGE ScopedTypeVariables #-}+> {-# LANGUAGE TemplateHaskell #-}+> {-# LANGUAGE TypeApplications  #-}+> {-# LANGUAGE TypeFamilies #-}+> {-# LANGUAGE FlexibleInstances #-}+> {-# LANGUAGE MultiParamTypeClasses #-}+> {-# LANGUAGE UndecidableInstances #-}+> {-# LANGUAGE ExistentialQuantification #-}+>+> import Data.Aeson+> import Data.Constraint.Forall+> import Data.Constraint.Extras+> import Data.Constraint.Extras.TH+>+> data A :: * -> * where+>   A_a :: A Int+>   A_b :: Int -> A ()+>+> deriveArgDict ''A+>+> data B :: * -> * where+>   B_a :: A a -> A a -> B a+>   B_x :: Int -> B Int+>+> deriveArgDict ''B+>+> data V :: (* -> *) -> * where+>   V_a :: A Int -> V A+>+> deriveArgDict ''V+>+> data DSum k f = forall a. DSum (k a) (f a)+>+> -- Derive a ToJSON instance for our 'DSum'+> instance forall k f.+>   ( Has' ToJSON k f -- Given a value of type (k a), we can obtain an instance (ToJSON (f a))+>   , ForallF ToJSON k -- For any (a), we have an instance (ToJSON (k a))+>   ) => ToJSON (DSum k f) where+>   toJSON (DSum (k :: k a) f) = toJSON+>     ( whichever @ToJSON @k @a $ toJSON k -- Use the (ForallF ToJSON k) constraint to obtain the (ToJSON (k a)) instance+>     , has' @ToJSON @f k $ toJSON f -- Use the (Has' ToJSON k f) constraint to obtain the (ToJSON (f a)) instance+>     )+>+> data Some k = forall a. Some (k a)+>+> -- Derive a FromJSON instance for our 'DSum'+> instance (FromJSON (Some f), Has' FromJSON f g) => FromJSON (DSum f g) where+>   parseJSON x = do+>     (jf, jg) <- parseJSON x+>     Some (f :: f a) <- parseJSON jf+>     g <- has' @FromJSON @g f (parseJSON jg)+>     return $ DSum f g+>+> main :: IO ()+> main = return () ```
README.md view
@@ -1,64 +1,67 @@-# constraints-extras--## Example usage:+constraints-extras+================== -NB: This example can be built with `-pgmL markdown-unlit`.+Example usage:+--------------  ```haskell-{-# LANGUAGE GADTs #-}-{-# LANGUAGE KindSignatures #-}-{-# LANGUAGE PolyKinds #-}-{-# LANGUAGE ScopedTypeVariables #-}-{-# LANGUAGE TemplateHaskell #-}-{-# LANGUAGE TypeApplications  #-}-{-# LANGUAGE TypeFamilies #-}-{-# LANGUAGE FlexibleInstances #-}-{-# LANGUAGE MultiParamTypeClasses #-}-{-# LANGUAGE UndecidableInstances #-}-{-# LANGUAGE ExistentialQuantification #-} -import Data.Aeson-import Data.Constraint.Forall-import Data.Constraint.Extras-import Data.Constraint.Extras.TH--data A :: * -> * where-  A_a :: A Int-  A_b :: Int -> A ()--data B :: * -> * where-  B_a :: A a -> A a -> B a-  B_x :: Int -> B Int--data V :: (* -> *) -> * where-  V_a :: A Int -> V A--deriveArgDict ''A-deriveArgDict ''B-deriveArgDict ''V--data DSum k f = forall a. DSum (k a) (f a)---- Derive a ToJSON instance for our 'DSum'-instance forall k f.-  ( Has' ToJSON k f -- Given a value of type (k a), we can obtain an instance (ToJSON (f a))-  , ForallF ToJSON k -- For any (a), we have an instance (ToJSON (k a))-  ) => ToJSON (DSum k f) where-  toJSON (DSum (k :: k a) f) = toJSON-    ( whichever @ToJSON @k @a $ toJSON k -- Use the (ForallF ToJSON k) constraint to obtain the (ToJSON (k a)) instance-    , has' @ToJSON @f k $ toJSON f -- Use the (Has' ToJSON k f) constraint to obtain the (ToJSON (f a)) instance-    )--data Some k = forall a. Some (k a)---- Derive a FromJSON instance for our 'DSum'-instance (FromJSON (Some f), Has' FromJSON f g) => FromJSON (DSum f g) where-  parseJSON x = do-    (jf, jg) <- parseJSON x-    Some (f :: f a) <- parseJSON jf-    g <- has' @FromJSON @g f (parseJSON jg)-    return $ DSum f g--main :: IO ()-main = return ()+> {-# LANGUAGE GADTs #-}+> {-# LANGUAGE KindSignatures #-}+> {-# LANGUAGE PolyKinds #-}+> {-# LANGUAGE ScopedTypeVariables #-}+> {-# LANGUAGE TemplateHaskell #-}+> {-# LANGUAGE TypeApplications  #-}+> {-# LANGUAGE TypeFamilies #-}+> {-# LANGUAGE FlexibleInstances #-}+> {-# LANGUAGE MultiParamTypeClasses #-}+> {-# LANGUAGE UndecidableInstances #-}+> {-# LANGUAGE ExistentialQuantification #-}+>+> import Data.Aeson+> import Data.Constraint.Forall+> import Data.Constraint.Extras+> import Data.Constraint.Extras.TH+>+> data A :: * -> * where+>   A_a :: A Int+>   A_b :: Int -> A ()+>+> deriveArgDict ''A+>+> data B :: * -> * where+>   B_a :: A a -> A a -> B a+>   B_x :: Int -> B Int+>+> deriveArgDict ''B+>+> data V :: (* -> *) -> * where+>   V_a :: A Int -> V A+>+> deriveArgDict ''V+>+> data DSum k f = forall a. DSum (k a) (f a)+>+> -- Derive a ToJSON instance for our 'DSum'+> instance forall k f.+>   ( Has' ToJSON k f -- Given a value of type (k a), we can obtain an instance (ToJSON (f a))+>   , ForallF ToJSON k -- For any (a), we have an instance (ToJSON (k a))+>   ) => ToJSON (DSum k f) where+>   toJSON (DSum (k :: k a) f) = toJSON+>     ( whichever @ToJSON @k @a $ toJSON k -- Use the (ForallF ToJSON k) constraint to obtain the (ToJSON (k a)) instance+>     , has' @ToJSON @f k $ toJSON f -- Use the (Has' ToJSON k f) constraint to obtain the (ToJSON (f a)) instance+>     )+>+> data Some k = forall a. Some (k a)+>+> -- Derive a FromJSON instance for our 'DSum'+> instance (FromJSON (Some f), Has' FromJSON f g) => FromJSON (DSum f g) where+>   parseJSON x = do+>     (jf, jg) <- parseJSON x+>     Some (f :: f a) <- parseJSON jf+>     g <- has' @FromJSON @g f (parseJSON jg)+>     return $ DSum f g+>+> main :: IO ()+> main = return () ```
constraints-extras.cabal view
@@ -1,5 +1,5 @@ name: constraints-extras-version: 0.3+version: 0.3.0.1 synopsis: Utility package for constraints description: Convenience functions and TH for working with constraints. See <https://github.com/obsidiansystems/constraints-extras/blob/develop/README.md README.md> for example usage. category: Constraints@@ -32,16 +32,13 @@   default-language: Haskell2010  executable readme-  if impl(ghcjs)-    buildable: False   build-depends: base >=4.9 && <4.13                , aeson                , constraints >= 0.9 && < 0.11                , constraints-extras   main-is: README.lhs-  ghc-options: -pgmL markdown-unlit -Wall+  ghc-options: -Wall -optL -q   default-language: Haskell2010-  build-tool-depends: markdown-unlit:markdown-unlit  source-repository head   type:     git