{-# LANGUAGE BlockArguments #-} module WithLower where -- base import Data.Void -- transformers import Control.Monad.Trans.Reader -- text import Data.Text (Text) -- megaparsec import Text.Megaparsec type Parser = Parsec Void Text withLower :: ((forall a. ReaderT r f a -> f a) -> f b) -> ReaderT r f b withLower k = ReaderT \r -> k (`runReaderT` r) myParser :: ReaderT r Parser a myParser = withLower \lower -> choice [try (lower parserA) <|> try parserB <|> parserC] parserA :: ReaderT r Parser a parserA = undefined parserB, parserC :: Parser a parserB = undefined parserC = undefined