From d928083f2307e7916602900ffcd78d8d4a921e63 Mon Sep 17 00:00:00 2001 From: Asad Saeeduddin Date: Thu, 22 Apr 2021 21:54:00 -0400 Subject: [PATCH 1/3] Add `hoistDeclare` --- src/Data/OpenApi/Declare.hs | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/Data/OpenApi/Declare.hs b/src/Data/OpenApi/Declare.hs index 559009a2..e52ab3fd 100644 --- a/src/Data/OpenApi/Declare.hs +++ b/src/Data/OpenApi/Declare.hs @@ -29,6 +29,8 @@ import Control.Monad.Trans.RWS.Strict as Strict import Control.Monad.Trans.Writer.Lazy as Lazy import Control.Monad.Trans.Writer.Strict as Strict import Data.Functor.Identity +import Data.Functor.Compose +import Data.Tuple (swap) -- | A declare monad transformer parametrized by: -- @@ -115,6 +117,14 @@ execDeclareT (DeclareT f) d = fst <$> f d undeclareT :: (Monad m, Monoid d) => DeclareT d m a -> m a undeclareT = flip evalDeclareT mempty +-- | Lift a declaration-producing computation for a subpart into a +-- declaration-producing computation for the whole. +hoistDeclareT :: Functor m => Lens' d d' -> DeclareT d' m a -> DeclareT d m a +hoistDeclareT l = DeclareT . unconvert . l . convert . runDeclareT + where + convert f = Compose . fmap swap . f + unconvert f = fmap swap . getCompose . f + -- | A declare monad parametrized by @d@ — the output to accumulate (declarations). -- -- This monad is similar to both state and writer monads. From 48063d69117cec810372c9099839bfbd7078605c Mon Sep 17 00:00:00 2001 From: Asad Saeeduddin Date: Thu, 22 Apr 2021 23:48:14 -0400 Subject: [PATCH 2/3] Add missing import --- src/Data/OpenApi/Declare.hs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Data/OpenApi/Declare.hs b/src/Data/OpenApi/Declare.hs index e52ab3fd..e3c46ad6 100644 --- a/src/Data/OpenApi/Declare.hs +++ b/src/Data/OpenApi/Declare.hs @@ -28,6 +28,7 @@ import Control.Monad.Trans.RWS.Lazy as Lazy import Control.Monad.Trans.RWS.Strict as Strict import Control.Monad.Trans.Writer.Lazy as Lazy import Control.Monad.Trans.Writer.Strict as Strict +import Control.Lens.Lens (Lens') import Data.Functor.Identity import Data.Functor.Compose import Data.Tuple (swap) From 832b02999c48219952bf3bb8caecf5628dcb6809 Mon Sep 17 00:00:00 2001 From: Asad Saeeduddin Date: Fri, 23 Apr 2021 00:36:41 -0400 Subject: [PATCH 3/3] Add missing extension --- src/Data/OpenApi/Declare.hs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Data/OpenApi/Declare.hs b/src/Data/OpenApi/Declare.hs index e3c46ad6..9c03de2d 100644 --- a/src/Data/OpenApi/Declare.hs +++ b/src/Data/OpenApi/Declare.hs @@ -3,6 +3,7 @@ {-# LANGUAGE FunctionalDependencies #-} {-# LANGUAGE MultiParamTypeClasses #-} {-# LANGUAGE UndecidableInstances #-} +{-# LANGUAGE RankNTypes #-} -- | -- Module: Data.OpenApi.Declare -- Maintainer: Nickolay Kudasov