From 2e0ba8479fb0554596954e2089a39a1219dbe77d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Baldur=20Bl=C3=B6ndal?= Date: Wed, 21 Feb 2024 14:25:10 +0000 Subject: [PATCH] Applicative, Alternative instances for Cayley. --- CHANGELOG.markdown | 1 + src/Data/Profunctor/Cayley.hs | 17 ++++++++++++++--- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.markdown b/CHANGELOG.markdown index b26950a3..e4e4f6f6 100644 --- a/CHANGELOG.markdown +++ b/CHANGELOG.markdown @@ -1,5 +1,6 @@ 6 [unreleased] -------------- +* `Applicative`, `Alternative` instances for `Cayley` * Removed support for GHC < 8.6 * Inverted dependency between `distributive` v1 and `profunctors` v6 * `Data.Profunctor.Mapping`, `Data.Profunctor.Closed`, `Data.Profunctor.Rep` diff --git a/src/Data/Profunctor/Cayley.hs b/src/Data/Profunctor/Cayley.hs index 6b37d62f..c3603930 100644 --- a/src/Data/Profunctor/Cayley.hs +++ b/src/Data/Profunctor/Cayley.hs @@ -1,7 +1,12 @@ -{-# LANGUAGE DeriveTraversable #-} -{-# LANGUAGE DeriveGeneric #-} +{-# LANGUAGE CPP #-} +Hello: __GLASGOW_HASKELL__ {-# LANGUAGE DeriveDataTypeable #-} +{-# LANGUAGE DeriveGeneric #-} +{-# LANGUAGE DeriveTraversable #-} +#if __GLASGOW_HASKELL__ < 811 {-# LANGUAGE DerivingStrategies #-} +#endif +{-# LANGUAGE DerivingVia #-} {-# LANGUAGE PolyKinds #-} {-# LANGUAGE RankNTypes #-} {-# LANGUAGE StandaloneDeriving #-} @@ -21,11 +26,13 @@ import Control.Arrow as A import Control.Category import Control.Comonad import Data.Biapplicative +import Data.Bifoldable import Data.Bifunctor as B import Data.Bifunctor.Functor -import Data.Bifoldable import Data.Bitraversable import Data.Data +import Data.Functor.Compose +import Data.Kind import Data.Profunctor import Data.Profunctor.Functor import Data.Profunctor.Monad @@ -45,6 +52,10 @@ newtype Cayley f p a b = Cayley { runCayley :: f (p a b) } deriving stock instance (Functor f, Functor (p a)) => Functor (Cayley f p a) deriving stock instance (Foldable f, Foldable (p a)) => Foldable (Cayley f p a) deriving stock instance (Traversable f, Traversable (p a)) => Traversable (Cayley f p a) +deriving via Compose f (p a :: Type -> Type) + instance (Applicative f, Applicative (p a)) => Applicative (Cayley f p a) +deriving via Compose f (p a :: Type -> Type) + instance (Alternative f, Applicative (p a)) => Alternative (Cayley f p a) instance Functor f => ProfunctorFunctor (Cayley f) where promap = \f -> Cayley #. fmap f .# runCayley