From aa9b2277ac575e4f7d1f7963ba4fb85341e92a71 Mon Sep 17 00:00:00 2001 From: Ellis Kesterton Date: Sun, 29 Sep 2024 12:16:57 +0100 Subject: [PATCH] Use existential type variable for IndentOpt --- Text/Megaparsec/Char/Lexer.hs | 13 +++++++++---- megaparsec.cabal | 4 ++++ 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/Text/Megaparsec/Char/Lexer.hs b/Text/Megaparsec/Char/Lexer.hs index 06c317cb..15bffeed 100644 --- a/Text/Megaparsec/Char/Lexer.hs +++ b/Text/Megaparsec/Char/Lexer.hs @@ -212,17 +212,22 @@ nonIndented sc p = indentGuard sc EQ pos1 *> p -- 'indentBlock', which see. -- -- @since 4.3.0 -data IndentOpt m a b +data IndentOpt m a = -- | Parse no indented tokens, just return the value IndentNone a | -- | Parse many indented tokens (possibly zero), use given indentation -- level (if 'Nothing', use level of the first indented token); the -- second argument tells how to get the final result, and the third -- argument describes how to parse an indented token - IndentMany (Maybe Pos) ([b] -> m a) (m b) + forall b. IndentMany (Maybe Pos) ([b] -> m a) (m b) | -- | Just like 'IndentMany', but requires at least one indented token to -- be present - IndentSome (Maybe Pos) ([b] -> m a) (m b) + forall b. IndentSome (Maybe Pos) ([b] -> m a) (m b) + +instance Functor m => Functor (IndentOpt m) where + fmap f (IndentNone x) = IndentNone (f x) + fmap f (IndentMany i g p) = IndentMany i (fmap (fmap f) g) p + fmap f (IndentSome i g p) = IndentSome i (fmap (fmap f) g) p -- | Parse a “reference” token and a number of other tokens that have a -- greater (but the same for all of them) level of indentation than that of @@ -238,7 +243,7 @@ indentBlock :: -- | How to consume indentation (white space) m () -> -- | How to parse “reference” token - m (IndentOpt m a b) -> + m (IndentOpt m a) -> m a indentBlock sc r = do sc diff --git a/megaparsec.cabal b/megaparsec.cabal index b4e89c17..1c1b8380 100644 --- a/megaparsec.cabal +++ b/megaparsec.cabal @@ -56,6 +56,10 @@ library Text.Megaparsec.Lexer default-language: Haskell2010 + + default-extensions: + ExistentialQuantification + build-depends: array >=0.5.3 && <0.6, base >=4.15 && <5,