packages feed

derive-lifted-instances 0.1 → 0.1.1

raw patch · 5 files changed

+38/−15 lines, 5 filesdep +reflectionPVP ok

version bump matches the API change (PVP)

Dependencies added: reflection

API changes (from Hackage documentation)

+ Data.DeriveLiftedInstances: monoidDerivBy :: Q Exp -> Q Exp -> Derivator

Files

CHANGELOG.md view
@@ -1,11 +1,15 @@ Changelog ========= -v0.1 2020-06-22-----------------  - Generalize `tupleDeriv` to `biapDeriv`+v0.1.1 2020-06-24+-----------------+  - Add `monoidDerivBy`++v0.1   2020-06-22+-----------------+  - Generalize `tupleDeriv` to `biapDeriv` and `recordDeriv`   - Generalize `unitDeriv` to `monoidDeriv` -v0 2020-06-20--------------+v0     2020-06-20+-----------------   - First release
Data/DeriveLiftedInstances.hs view
@@ -1,3 +1,4 @@+{-# LANGUAGE CPP #-} {-# LANGUAGE ViewPatterns #-} {-# LANGUAGE TemplateHaskell #-} {-# OPTIONS_GHC -fno-warn-orphans #-}@@ -17,7 +18,7 @@   idDeriv, newtypeDeriv, isoDeriv,   -- * Derivators for algebraic classes   -- $algebraic-classes-  recordDeriv, apDeriv, biapDeriv, monoidDeriv,+  recordDeriv, apDeriv, biapDeriv, monoidDeriv, monoidDerivBy,   showDeriv, ShowsPrec(..),   -- * Creating derivators   Derivator(..)@@ -28,6 +29,7 @@ import Control.Applicative (liftA2) import Control.Monad (zipWithM) import Data.Biapplicative+import Data.Reflection  -- $algebraic-classes -- Algebraic classes are type classes where all the methods return a value of the same type, which is also the class parameter.@@ -75,11 +77,14 @@ -- | Create a `Derivator` for any `Monoid` @m@. This is a degenerate instance that only collects -- all values of type @m@, and ignores the rest. monoidDeriv :: Derivator-monoidDeriv = idDeriv {-  op  = \_ _ -> [| mempty |],-  arg = \_ _ -> [| mempty |],-  var = \fold v -> [| ($(fold [| foldMap |] [| id |]) $v) |],-  ap  = \f a -> [| $f <> $a |]+monoidDeriv = monoidDerivBy [| (<>) |] [| mempty |]++monoidDerivBy :: Q Exp -> Q Exp -> Derivator+monoidDerivBy append empty = idDeriv {+  op  = \_ _ -> empty,+  arg = \_ _ -> empty,+  var = \fold v -> [| ($(fold [| foldMapBy $append $empty |] [| id |]) $v) |],+  ap  = \f a -> [| $append $f $a |] }  -- | Given how to derive an instance for @a@, and the names of a newtype wrapper around @a@,@@ -124,7 +129,7 @@ --     [ ([| getUnit |], apDeriv monoidDeriv) --     , ([| getInt  |], apDeriv idDeriv) --     ])---   [t| forall f. Applicative f => Test (Rec f) |]+--   [t| forall f. Applicative f => Num (Rec f) |] -- @ -- -- @@@ -147,7 +152,11 @@ }   where     tup :: Q [Exp] -> Q Exp+#if __GLASGOW_HASKELL__ >= 810     tup = fmap (TupE . fmap Just)+#else+    tup = fmap TupE+#endif     pat :: [Name] -> Q Pat     pat = pure . TupP . fmap VarP     ex :: Name -> Q Exp
README.md view
@@ -1,1 +1,5 @@-# derive-lifted-instances+derive-lifted-instances+=======================++[![Hackage](https://img.shields.io/hackage/v/derive-lifted-instances.svg)](https://hackage.haskell.org/package/derive-lifted-instances)+[![Build Status](https://travis-ci.org/sjoerdvisscher/derive-lifted-instances.svg?branch=master)](https://travis-ci.org/github/sjoerdvisscher/derive-lifted-instances)
derive-lifted-instances.cabal view
@@ -1,5 +1,5 @@ name:                derive-lifted-instances-version:             0.1+version:             0.1.1 synopsis:            Derive class instances though various kinds of lifting description:         Helper functions to use Template Haskell for generating class instances. homepage:            https://github.com/sjoerdvisscher/derive-lifted-instances@@ -11,6 +11,7 @@ category:            Data, Generics, Development build-type:          Simple cabal-version:       2.0+tested-with:         GHC==8.10.1, GHC==8.8.3  extra-source-files:   examples/*.hs@@ -26,6 +27,7 @@       base >= 4.13 && < 4.15     , template-haskell >= 2.15 && < 2.17     , bifunctors >= 5.5.7 && < 6+    , reflection >= 2.1 && < 3    default-language:     Haskell2010
examples/Test.hs view
@@ -1,3 +1,5 @@+{-# LANGUAGE UndecidableInstances #-}+{-# LANGUAGE StandaloneDeriving #-} {-# LANGUAGE ConstraintKinds #-} {-# LANGUAGE GADTs #-} {-# LANGUAGE FlexibleInstances #-}@@ -19,6 +21,7 @@   op2 = sum . fmap sum  data Rec f = Rec { getUnit :: f (), getInt :: f Int }+deriving instance (Show (f ()), Show (f Int)) => Show (Rec f) deriveInstance (recordDeriv [| Rec |]     [ ([| getUnit |], apDeriv monoidDeriv)     , ([| getInt |], apDeriv idDeriv)@@ -35,7 +38,7 @@ deriveInstance showDeriv [t| Test ShowsPrec |] deriveInstance monoidDeriv [t| Test () |] deriveInstance (apDeriv idDeriv) [t| forall a. Test a => Test [a] |]-deriveInstance (biapDeriv idDeriv idDeriv) [t| forall a b. (Test a, Test b) => Test (a, b) |]+-- deriveInstance (biapDeriv idDeriv idDeriv) [t| forall a b. (Test a, Test b) => Test (a, b) |] -- deriveInstance (newtypeDeriv 'Identity 'runIdentity idDeriv) [t| forall a. Test a => Test (Identity a) |]  deriveInstance (apDeriv monoidDeriv) [t| forall a. Monoid a => Test (IO a) |]@@ -49,6 +52,7 @@ deriveInstance (apDeriv (apDeriv (newtypeDeriv 'Id 'runId idDeriv))) [t| forall a. Test a => Test (() -> Identity (Id a)) |] deriveInstance (apDeriv (biapDeriv idDeriv idDeriv)) [t| forall a b. (Test a, Test b) => Test (() -> (a, b)) |] deriveInstance (biapDeriv (apDeriv idDeriv) (newtypeDeriv 'Id 'runId idDeriv)) [t| forall a b. (Test a, Test b) => Test (() -> a, Id b) |]+deriveInstance (biapDeriv (monoidDerivBy [| (+) |] [| 0 |]) (monoidDerivBy [| (*) |] [| 1 |])) [t| Test (Int, Int) |]  class Test1 f where   hop0 :: f a