free-functors 1.1.2 → 1.2
raw patch · 9 files changed
+41/−34 lines, 9 filesdep ~basedep ~derive-lifted-instancesdep ~template-haskell
Dependency ranges changed: base, derive-lifted-instances, template-haskell
Files
- CHANGELOG +4/−0
- examples/Sem.hs +2/−2
- free-functors.cabal +5/−4
- src/Data/Functor/Cofree/Internal.hs +5/−5
- src/Data/Functor/Free/Internal.hs +5/−5
- src/Data/Functor/HCofree.hs +8/−8
- src/Data/Functor/HFree.hs +7/−5
- src/Data/Functor/HHCofree.hs +2/−2
- src/Data/Functor/HHFree.hs +3/−3
CHANGELOG view
@@ -1,5 +1,9 @@ CHANGELOG +1.1.2 -> 1.2+ - Add support for GHC 9.0, drop GHC 8.8+ - Update to derive-lifted-instances v0.2.2+ 1.1.1 -> 1.1.2 - Update to derive-lifted-instances v0.2 - Add deriving instances for `Cofree`, `HCofree` and `HHCofree`
examples/Sem.hs view
@@ -1,6 +1,6 @@-{-# LANGUAGE TemplateHaskell, UndecidableInstances, QuantifiedConstraints, FlexibleInstances #-}+{-# LANGUAGE TemplateHaskell, UndecidableInstances, QuantifiedConstraints, ConstraintKinds, FlexibleInstances #-} module Sem where- + import Data.Functor.Free class BaseSem a where
free-functors.cabal view
@@ -1,5 +1,5 @@ name: free-functors-version: 1.1.2+version: 1.2 synopsis: Free functors, adjoint to functors that forget class constraints. description: A free functor is a left adjoint to a forgetful functor. It used to be the case that the only category that was easy to work with in Haskell was Hask itself, so@@ -22,6 +22,7 @@ build-type: Simple cabal-version: >= 1.10+tested-with: GHC==9.0.0.20200925, GHC==8.10.2 extra-source-files: examples/*.hs@@ -45,11 +46,11 @@ Haskell2010 build-depends:- base >= 4.13 && < 4.15,- template-haskell >= 2.15 && < 2.17,+ base >= 4.14 && < 4.16,+ template-haskell >= 2.16 && < 2.18, transformers == 0.5.*, comonad == 5.*,- derive-lifted-instances >= 0.2 && < 0.3,+ derive-lifted-instances >= 0.2.2 && < 0.3, contravariant == 1.5.*, bifunctors == 5.*, profunctors == 5.*
src/Data/Functor/Cofree/Internal.hs view
@@ -15,6 +15,7 @@ , QuantifiedConstraints , MultiParamTypeClasses , UndecidableSuperClasses+ , StandaloneKindSignatures #-} module Data.Functor.Cofree.Internal where @@ -22,6 +23,7 @@ import Language.Haskell.TH.Syntax import Data.DeriveLiftedInstances+import Data.Kind (Constraint) kExp :: Q Exp@@ -41,9 +43,7 @@ deriveCofreeInstance' :: Name -> Name -> Name -> Q [Dec] deriveCofreeInstance' (pure . ConT -> cofree) ccofree (pure . ConT -> clss) = deriveInstance (cofreeDeriv ccofree)- [t| forall a c. (c ~=> $clss) => $clss ($cofree c a) |]--class (a => b) => a :=> b-instance (a => b) => a :=> b+ [t| forall a c. (c ~=> $clss, c ($cofree c a)) => $clss ($cofree c a) |] -type a ~=> b = forall x. a x :=> b x+type (~=>) :: (k -> Constraint) -> (k -> Constraint) -> Constraint+type a ~=> b = forall x. a x => b x
src/Data/Functor/Free/Internal.hs view
@@ -15,6 +15,7 @@ , QuantifiedConstraints , MultiParamTypeClasses , UndecidableSuperClasses+ , StandaloneKindSignatures #-} module Data.Functor.Free.Internal where @@ -22,6 +23,7 @@ import Language.Haskell.TH.Syntax import Data.DeriveLiftedInstances+import Data.Kind (Constraint) kExp :: Q Exp@@ -40,7 +42,7 @@ deriveFreeInstance' (pure . ConT -> free) cfree runFree (pure . ConT -> clss) = deriveInstance (freeDeriv cfree runFree)- [t| forall a c. (c ~=> $clss) => $clss ($free c a) |]+ [t| forall a c. (c ~=> $clss, c ($free c a)) => $clss ($free c a) |] deriveInstances' :: Name -> Name -> Name -> Name -> Q [Dec] deriveInstances' tfree cfree runFree nm@(pure . ConT -> clss) =@@ -50,7 +52,5 @@ , deriveInstance (apDeriv idDeriv) [t| forall f a c. (Applicative f, $clss a) => $clss (Ap f a) |] ] -class (a => b) => a :=> b-instance (a => b) => a :=> b--type a ~=> b = forall x. a x :=> b x+type (~=>) :: (k -> Constraint) -> (k -> Constraint) -> Constraint+type a ~=> b = forall x. a x => b x
src/Data/Functor/HCofree.hs view
@@ -40,7 +40,13 @@ data HCofree c g a where HCofree :: c f => (f :~> g) -> f a -> HCofree c g a +-- | The cofree comonad of a functor.+instance (c ~=> Comonad, c (HCofree c g)) => Comonad (HCofree c g) where+ extract (HCofree _ a) = extract a+ extend f (HCofree k a) = HCofree k $ extend (f . HCofree k) a+ duplicate (HCofree k a) = HCofree k $ extend (HCofree k) a + -- | Derive the instance of @`HCofree` c a@ for the class @c@. -- -- For example:@@ -54,7 +60,7 @@ counit (HCofree k fa) = k fa leftAdjunct :: c f => (f :~> g) -> f :~> HCofree c g-leftAdjunct = HCofree+leftAdjunct f = HCofree f -- | @unit = leftAdjunct id@ unit :: c g => g :~> HCofree c g@@ -68,7 +74,7 @@ transform t (HCofree k a) = HCofree (t k) a hfmap :: (f :~> g) -> HCofree c f :~> HCofree c g-hfmap f = transform (f .)+hfmap f = transform (\g -> f . g) hextend :: (HCofree c f :~> g) -> HCofree c f :~> HCofree c g hextend f = transform (\k -> f . leftAdjunct k)@@ -91,9 +97,3 @@ deriveCofreeInstance' ''HCofree 'HCofree ''Functor deriveCofreeInstance' ''HCofree 'HCofree ''Foldable deriveCofreeInstance' ''HCofree 'HCofree ''Traversable---- | The cofree comonad of a functor.-instance (c ~=> Comonad) => Comonad (HCofree c g) where- extract (HCofree _ a) = extract a- extend f (HCofree k a) = HCofree k $ extend (f . HCofree k) a- duplicate (HCofree k a) = HCofree k $ extend (HCofree k) a
src/Data/Functor/HFree.hs view
@@ -41,7 +41,13 @@ -- | The higher order free functor for constraint @c@. newtype HFree c f a = HFree { runHFree :: forall g. c g => (f :~> g) -> g a } +-- | The free monad of a functor.+instance (c ~=> Monad, c (HFree c f)) => Monad (HFree c f) where+ return = pure+ HFree f >>= g = HFree $ \k -> f k >>= rightAdjunct k . g+ HFree f >> HFree g = HFree $ \k -> f k >> g k + -- | Derive the instance of @`HFree` c f a@ for the class @c@,. -- -- For example:@@ -50,7 +56,6 @@ deriveHFreeInstance :: Name -> Q [Dec] deriveHFreeInstance = deriveFreeInstance' ''HFree 'HFree 'runHFree - unit :: f :~> HFree c f unit fa = HFree $ \k -> k fa @@ -70,7 +75,7 @@ -- transform t = HFree . (. t) . runHFree hfmap :: (f :~> g) -> HFree c f :~> HFree c g-hfmap f = transform (. f)+hfmap f = transform (\g -> g . f) bind :: (f :~> HFree c g) -> HFree c f :~> HFree c g bind f = transform (\k -> rightAdjunct k . f)@@ -94,9 +99,6 @@ deriveFreeInstance' ''HFree 'HFree 'runHFree ''Functor deriveFreeInstance' ''HFree 'HFree 'runHFree ''Applicative deriveFreeInstance' ''HFree 'HFree 'runHFree ''Alternative---- | The free monad of a functor.-deriveFreeInstance' ''HFree 'HFree 'runHFree ''Monad -- HFree Monad is only a monad transformer if rightAdjunct is called with monad morphisms. -- F.e. lift . return == return fails if the results are inspected with rightAdjunct (const Nothing).
src/Data/Functor/HHCofree.hs view
@@ -60,7 +60,7 @@ counit (HHCofree k fa) = k fa leftAdjunct :: c f => (f :~~> g) -> f :~~> HHCofree c g-leftAdjunct = HHCofree+leftAdjunct f = HHCofree f -- | @unit = leftAdjunct id@ unit :: c g => g :~~> HHCofree c g@@ -74,7 +74,7 @@ transform t (HHCofree k a) = HHCofree (t k) a hfmap :: (f :~~> g) -> HHCofree c f :~~> HHCofree c g-hfmap f = transform (f .)+hfmap f = transform (\g -> f . g) hextend :: (HHCofree c f :~~> g) -> HHCofree c f :~~> HHCofree c g hextend f = transform (\k -> f . leftAdjunct k)
src/Data/Functor/HHFree.hs view
@@ -72,7 +72,7 @@ -- transform t = HHFree . (. t) . runHHFree hfmap :: (f :~~> g) -> HHFree c f :~~> HHFree c g-hfmap f = transform (. f)+hfmap f = transform (\g -> g . f) bind :: (f :~~> HHFree c g) -> HHFree c f :~~> HHFree c g bind f = transform (\k -> rightAdjunct k . f)@@ -99,8 +99,8 @@ deriveFreeInstance' ''HHFree 'HHFree 'runHHFree ''ArrowChoice deriveFreeInstance' ''HHFree 'HHFree 'runHHFree ''ArrowLoop -instance (forall x. c x => ArrowApply x) => ArrowApply (HHFree c f) where- app = HHFree $ \k -> app . arr (first (rightAdjunct k))+instance (c ~=> ArrowApply, c (HHFree c f)) => ArrowApply (HHFree c f) where+ app = HHFree $ \k -> app . arr (\(a, b) -> (rightAdjunct k a, b)) deriveFreeInstance' ''HHFree 'HHFree 'runHHFree ''Bifunctor deriveFreeInstance' ''HHFree 'HHFree 'runHHFree ''Biapplicative