distributors-grammar
Copyright(C) 2026 - Eitan Chatav
LicenseBSD-style (see the file LICENSE)
MaintainerEitan Chatav <eitan.chatav@gmail.com>
Stabilityprovisional
Portabilitynon-portable
Safe HaskellNone
LanguageHaskell2010

Control.Lens.Grammar

Description

Synopsis

Regular grammar

A regular grammar may be constructed using terminal symbols, Tokenized combinators, tokenClasses and Alternator combinators. Let's see an example using semantic versioning syntax.

>>> import Numeric.Natural (Natural)
>>> :{
data SemVer = SemVer          -- e.g., 2.1.5-rc.1+build.123
  { major         :: Natural  -- e.g., 1
  , minor         :: Natural  -- e.g., 2
  , patch         :: Natural  -- e.g., 3
  , preRelease    :: [String] -- e.g., "alpha.1", "rc.2"
  , buildMetadata :: [String] -- e.g., "build.123", "20130313144700"
  }
  deriving (Eq, Ord, Show, Read)
:}

We'd like to define an optic _SemVer, corresponding to the constructor pattern SemVer. You could generate it with the TemplateHaskell combinator, makeNestedPrisms.

makeNestedPrisms ''SemVer

Unfortunately, we can't use TemplateHaskell to generate it in GHCi, which is used to test this documentation. Here is equivalent Haskell code instead. Since SemVer has only one constructor, _SemVer can be an Iso.

>>> :set -XRecordWildCards
>>> import Control.Lens (Iso', iso)
>>> :{
_SemVer :: Iso' SemVer (Natural, (Natural, (Natural, ([String], [String]))))
_SemVer = iso
  (\SemVer {..} -> (major, (minor, (patch, (preRelease, buildMetadata)))))
  (\(major, (minor, (patch, (preRelease, buildMetadata)))) -> SemVer {..})
:}

Now we can build a RegGrammar for SemVer using the "idiom" style of Applicative parsing with a couple modifications.

>>> :{
semverGrammar :: RegGrammatical Char p => p SemVer SemVer
semverGrammar = _SemVer
  >?  numberG
  >*< terminal "." >* numberG
  >*< terminal "." >* numberG
  >*< optionP _Empty (terminal "-" >* identifiersG)
  >*< optionP _Empty (terminal "+" >* identifiersG)
  where
    numberG = numeral 10
    identifiersG = sepWith "." (atLeast 1) (someP charG)
    charG = asIn LowercaseLetter
      >|< asIn UppercaseLetter
      >|< asIn DecimalNumber
      >|< token '-'
instance CtxGrammar Char SemVer
instance Grammar Char SemVer
instance RegGrammar Char SemVer where regGrammar = semverGrammar
:}

A type's RegGrammar instance, here semverGrammar, & its Grammar & CtxGrammar instances, by default, let generators run it by its type, a required type argument, (type SemVer) where a constructor shares its name, & parsers & printers by inference.

Instead of using the constructor SemVer with the Functor applicator <$>, we use the optic _SemVer we defined and the Choice applicator >?; although, we could have used the Profunctor applicator >~ instead, because _SemVer is an Iso.

FunctorialProfunctorial
SemVer_SemVer
<$>>?
purepureP
*>>*
<**<
<*>>*<
emptyfalseP
<|>>|<
choiceorP
manymanyP
somesomeP
optionaloptionalP

You can generate a regular expression string, a RegEx, from a RegGrammar with regexG.

>>> putStringLn (regexG (type SemVer))
[0-9]+.[0-9]+.[0-9]+(-(\p{Ll}|\p{Lu}|\p{Nd}|-)+(.(\p{Ll}|\p{Lu}|\p{Nd}|-)+)*)?(\+(\p{Ll}|\p{Lu}|\p{Nd}|-)+(.(\p{Ll}|\p{Lu}|\p{Nd}|-)+)*)?

You can also generate parsers and printers.

>>> [parsed | (parsed, "") <- parseG @SemVer "2.1.5-rc.1+build.123"]
[SemVer {major = 2, minor = 1, patch = 5, preRelease = ["rc","1"], buildMetadata = ["build","123"]}]

Parsing unconses tokens left-to-right, from the beginning of a string. Unparsing, on the other hand, snocs tokens left-to-right, to the end of a string.

>>> unparseG (SemVer 1 0 0 ["alpha"] []) "SemVer: " :: Maybe String
Just "SemVer: 1.0.0-alpha"

Printing, on the gripping hand, conses tokens right-to-left, to the beginning of a string.

>>> ($ " is the SemVer.") <$> printG (SemVer 1 2 3 [] []) :: Maybe String
Just "1.2.3 is the SemVer."

Profunctorial combinators give us correct-by-construction invertible parsers. New RegGrammar generators can be defined with new RegGrammatical instances.

class Grammar token a => RegGrammar token a where Source #

A type's regular grammar, over its tokens, which is also its context-free & context-sensitive grammar.

Methods

regGrammar :: RegGrammatical token p => p a a Source #

type RegGrammatical token (p :: Type -> Type -> Type) = (forall x y. (x ~ (), y ~ ()) => TerminalSymbol token (p x y), forall x y. (x ~ token, y ~ token) => TokenAlgebra token (p x y), Alternator p, forall x y. Tried (p x y)) Source #

The Alternators of terminal symbols, Tokenized combinators & tokenClasses, which are Tried, & run Control.Lens.Grammar.RegGrammars.

regexG :: forall a -> (Categorized token, RegGrammar token a) => RegEx token Source #

regexG generates a RegExpression from a regular grammar, over any token, a regular expression string over characters. Since context-free Grammars and CtxGrammars aren't necessarily regular, the type system will prevent regexG from being applied to them.

Context-free grammar

Context-free Grammars add two capabilities to RegGrammars, coming from the BackusNaurForm interface

  • rule abstraction,
  • and general recursion.

The Grammars of RegExpressions & of their Bnfs, in Control.Lens.Grammar.RegEx, are examples of context-free Grammars. Regular expressions are a form of expression algebra. Let's see a similar but simpler example, the algebra of arithmetic expressions of natural numbers.

>>> import Numeric.Natural (Natural)
>>> :{
data Arith
  = Num Natural
  | Add Arith Arith
  | Mul Arith Arith
  deriving stock (Eq, Ord, Show, Read)
:}

Here are Prisms for the constructor patterns.

>>> import Control.Lens (Prism', prism')
>>> :{
_Num :: Prism' Arith Natural
_Num = prism' Num (\case Num n -> Just n; _ -> Nothing)
_Add, _Mul :: Prism' Arith (Arith, Arith)
_Add = prism' (uncurry Add) (\case Add x y -> Just (x,y); _ -> Nothing)
_Mul = prism' (uncurry Mul) (\case Mul x y -> Just (x,y); _ -> Nothing)
:}

Now we can build a Grammar for Arith by combining "idiom" style with named rules, and tying the recursive loop (caused by parenthesization) with ruleRec.

>>> :{
arithGrammar :: Grammatical Char p => p Arith Arith
arithGrammar = ruleRec "arith" sumG
  where
    sumG arith = rule "sum" $
      sepWith "+" (chain1 Left _Add) (prodG arith)
    prodG arith = rule "product" $
      sepWith "*" (chain1 Left _Mul) (factorG arith)
    factorG arith = rule "factor" $
      numberG >|< terminal "(" >* arith *< terminal ")"
    numberG = rule "number" $
      _Num >? numeral 10
instance CtxGrammar Char Arith
instance Grammar Char Arith where grammar = arithGrammar
:}

We can generate grammar strings, printers and parsers from arithGrammar.

>>> putStringLn (regbnfG Arith)
{start} = \q{arith}
{arith} = \q{sum}
{factor} = \q{number}|\(\q{arith}\)
{number} = [0-9]+
{product} = \q{factor}(\*\q{factor})*
{sum} = \q{product}(\+\q{product})*
>>> [x | (x,"") <- parseG @Arith "1+2*3+4"]
[Add (Add (Num 1) (Mul (Num 2) (Num 3))) (Num 4)]
>>> unparseG (Add (Num 1) (Mul (Num 2) (Num 3))) "" :: Maybe String
Just "1+2*3"
>>> do pr <- printG (Num 69); pure (pr "") :: Maybe String
Just "69"

Operator tables with precedence, like buildExpressionParser's, are built by withOperators. For example, an expression grammar over natural numbers with a postfix factorial ! (binding tightest, and not required to actually compute a factorial), a right-associative exponent ^, a left-associative *, and left-associative + & - binding loosest:

>>> :{
data Expr
  = Nat Natural
  | Fac Expr
  | Exp Expr Expr
  | Mul Expr Expr
  | Add Expr Expr
  | Sub Expr Expr
  deriving stock (Eq, Ord, Show, Read)
_Nat :: Prism' Expr Natural
_Nat = prism' Nat (\case Nat n -> Just n; _ -> Nothing)
_Fac :: Prism' Expr Expr
_Fac = prism' Fac (\case Fac x -> Just x; _ -> Nothing)
_Exp, _Mul, _Add, _Sub :: Prism' Expr (Expr, Expr)
_Exp = prism' (uncurry Exp) (\case Exp x y -> Just (x,y); _ -> Nothing)
_Mul = prism' (uncurry Mul) (\case Mul x y -> Just (x,y); _ -> Nothing)
_Add = prism' (uncurry Add) (\case Add x y -> Just (x,y); _ -> Nothing)
_Sub = prism' (uncurry Sub) (\case Sub x y -> Just (x,y); _ -> Nothing)
exprGrammar :: Grammatical Char p => p Expr Expr
exprGrammar = ruleRec "expr" $ \expr ->
  let atom = rule "atom" $ nat >|< terminal "(" >* expr *< terminal ")"
      nat  = rule "nat"  $ _Nat >? numeral 10
  in withOperators
    [ [ Postfix _Fac (terminal "!") ]
    , [ Infix RightAssoc _Exp (terminal "^") ]
    , [ Infix LeftAssoc _Mul (terminal "*") ]
    , [ Infix LeftAssoc _Add (terminal "+"), Infix LeftAssoc _Sub (terminal "-") ]
    ] atom
instance CtxGrammar Char Expr
instance Grammar Char Expr where grammar = exprGrammar
:}

The right-associative ^ groups to the right, - to the left, * binds tighter than +, and postfix ! binds tighter than ^:

>>> [e | (e,"") <- parseG @Expr "2^3^2"]
[Exp (Nat 2) (Exp (Nat 3) (Nat 2))]
>>> [e | (e,"") <- parseG @Expr "3-2-1"]
[Sub (Sub (Nat 3) (Nat 2)) (Nat 1)]
>>> [e | (e,"") <- parseG @Expr "2*3+4"]
[Add (Mul (Nat 2) (Nat 3)) (Nat 4)]
>>> [e | (e,"") <- parseG @Expr "2*(3+4)"]
[Mul (Nat 2) (Add (Nat 3) (Nat 4))]
>>> [e | (e,"") <- parseG @Expr "3!"]
[Fac (Nat 3)]
>>> [e | (e,"") <- parseG @Expr "2^3!"]
[Exp (Nat 2) (Fac (Nat 3))]

Being bidirectional, the same grammar prints:

>>> unparseG (Exp (Nat 2) (Exp (Nat 3) (Nat 2))) "" :: Maybe String
Just "2^3^2"
>>> unparseG (Exp (Nat 2) (Fac (Nat 3))) "" :: Maybe String
Just "2^3!"

If all rules are non-recursive, then a Grammar can be rewritten as a RegGrammar. Since Haskell permits general recursion, and RegGrammars are embedded in Haskell, you can define context-free grammars with them. But it's recommended to use Grammars for rule abstraction and generator support for ruleRec.

class CtxGrammar token a => Grammar token a where Source #

A type's context-free grammar, over its tokens, which is also its context-sensitive grammar; its regular grammar, by default.

Minimal complete definition

Nothing

Methods

grammar :: Grammatical token p => p a a Source #

default grammar :: (RegGrammar token a, Grammatical token p) => p a a Source #

Instances

Instances details
Grammar Char (Bnf (RegEx Char)) Source #

The context-free Grammar of Bnfs of RegExpressions of characters, by which they're IsString & IsList. That means that it can generate a self-hosted definition.

Bnfs of RegExpressions of characters are an embedded domain specific language of Backus-Naur forms extended by regular expression strings.

Such a Bnf consists of a distinguished "start" RegEx, and a set of named RegEx rules.

>>> putStringLn (rule "baz" (terminal "foo" >|< terminal "bar") :: Bnf (RegEx Char))
{start} = \q{baz}
{baz} = foo|bar

Like RegExpressions, they have a string-like interface.

>>> let bnf = fromString "{start} = foo|bar" :: Bnf (RegEx Char)
>>> putStringLn bnf
{start} = foo|bar
>>> toList bnf
"{start} = foo|bar"
>>> :type toList bnf
toList bnf :: [Char]

They can be generated from context-free Control.Lens.Grammar.Grammars with Control.Lens.Grammar.regbnfG.

Like RegExpressions, they can be constructed using terminal, Tokenized, Monoid and KleeneStarAlgebra combinators. But they also support BackusNaurForm rules and ruleRecs.

>>> putStringLn (rule "baz" (bnf >|< terminal "baz"))
{start} = \q{baz}
{baz} = foo|bar|baz
>>> putStringLn (ruleRec "∞-loop" (\x -> x) :: Bnf (RegEx Char))
{start} = \q{∞-loop}
{∞-loop} = \q{∞-loop}
>>> putStringLn (regbnfG (type (Bnf (RegEx Char))))
{start} = \q{regbnf}
{alternate} = \q{sequence}(\|\q{sequence})*
{atom} = \\q\q{nonterminal}|\\t\{\q{regex}\}|\q{class}|\(\q{regex}\)
{bounds} = \q{count}(,\q{count}?)?
{category} = Ll|Lu|Lt|Lm|Lo|Mn|Mc|Me|Nd|Nl|No|Pc|Pd|Ps|Pe|Pi|Pf|Po|Sm|Sc|Sk|So|Zs|Zl|Zp|Cc|Cf|Cs|Co|Cn
{char} = [^\(\)\*\+\?\[\\\]\^\{\|\}\P{Cc}]|\\\q{char-escaped}
{char-control} = x\{[0-9A-Fa-f]+\}
{char-escaped} = [\(\)\*\+\?\[\\\]\^\{\|\}]|\q{char-control}
{class} = \q{class-one-of}|\q{class-not-one-of}
{class-category} = \\p\{\q{category}\}|\\P\{\q{category}(\|\q{category})*\}
{class-char} = [^\(\)\*\+\-\?\[\\\]\^\{\|\}\P{Cc}]|\\\q{class-char-escaped}
{class-char-escaped} = [\(\)\*\+\-\?\[\\\]\^\{\|\}]|\q{char-control}
{class-not-one-of} = \q{class-category}|\[\^\q{class-range}*\q{class-category}?\]
{class-one-of} = \q{char}|\[\q{class-range}*\]
{class-range} = \q{class-char}(-\q{class-char})?
{count} = [0-9]+
{expression} = \q{atom}\?|\q{atom}\*|\q{atom}\+|\q{atom}\{\q{bounds}\}|\q{atom}
{nonterminal} = \{\q{char}*\}
{regbnf} = \{start\} = \q{regex}(\x{a}\q{nonterminal} = \q{regex})*
{regex} = \q{alternate}
{sequence} = \q{expression}*
Instance details

Defined in Control.Lens.Grammar.RegEx

Grammar Char (RegEx Char) Source #

The context-free Grammar of RegExpressions of characters, in the syntax of regular expression strings, by which they're IsString & IsList. It can't be a Control.Lens.Grammar.RegGrammar, since regular expression strings include parenthesization. But balanceBy parentheses are a context-free language.

RegExpressions of characters are an embedded domain specific language of regular expression strings.

Since they are strings, they have a string-like interface.

>>> let rex = fromString "ab|c" :: RegEx Char
>>> putStringLn rex
ab|c
>>> toList rex
"ab|c"

They can be generated from Control.Lens.Grammar.RegGrammars with Control.Lens.Grammar.regexG.

>>> toList (runGrammor (terminal "a" >* terminal "b" >|< terminal "c") :: RegEx Char)
"ab|c"

A regular expression string is stored as an algebraic datatype, a RegEx.

>>> rex
RegExam (Alternate (Sequence (RegExam (OneOf (fromList "a"))) (RegExam (OneOf (fromList "b"))) []) (RegExam (OneOf (fromList "c"))) [])

They're similar to regular expression strings in many other programming languages. We can use them to see if a word and pattern are Matching.

>>> "ab" =~ rex
True
>>> "c" =~ rex
True
>>> "xyz" =~ rex
False

Like Control.Lens.Grammar.RegGrammars, they can use all the terminal & Tokenized combinators. Unlike Control.Lens.Grammar.RegGrammars, instead of using Monoidal and Alternator combinators, they use Monoid and KleeneStarAlgebra combinators.

>>> toList (terminal "a" <> terminal "b" >|< terminal "c" :: RegEx Char)
"ab|c"
>>> toList (mempty :: RegEx Char)
""

Since they're a KleeneStarAlgebra, they support Kleene quantifiers.

>>> toList (starK rex)
"(ab|c)*"
>>> toList (plusK rex)
"(ab|c)+"
>>> toList (optK rex)
"(ab|c)?"

Like other regular expression languages, they support character classes.

>>> toList (oneOf "abc" :: RegEx Char)
"[a-c]"
>>> toList (notOneOf "abc" :: RegEx Char)
"[^a-c]"

The character classes are used for failure, matching no character or string, as well as the wildcard, matching any single character.

>>> toList (falseP :: RegEx Char)
"[]"
>>> toList (anyToken :: RegEx Char)
"[^]"

Additional forms of character classes test for a character's GeneralCategory.

>>> toList (asIn LowercaseLetter :: RegEx Char)
"\\p{Ll}"
>>> toList (notAsIn Control :: RegEx Char)
"\\P{Cc}"

KleeneStarAlgebras support alternation >|<, and the Tokenized combinators are all negatable. However, we'd like to be able to take the intersection of character classes as well. they can combine characters' tokenClasses using BooleanAlgebra combinators.

>>> toList (tokenClass (notOneOf "abc" >&< notOneOf "xyz") :: RegEx Char)
"[^a-cx-z]"
>>> toList (tokenClass (oneOf "abcxyz" >&< notOneOf "xyz") :: RegEx Char)
"[a-c]"
>>> toList (tokenClass (notOneOf "#$%" >&< notAsIn Control) :: RegEx Char)
"[^#-%\\P{Cc}]"
>>> toList (tokenClass (allP notAsIn [MathSymbol, Control]) :: RegEx Char)
"\\P{Sm|Cc}"
>>> toList (tokenClass (notP (oneOf "xyz")) :: RegEx Char)
"[^x-z]"

Ill-formed regular expression strings normalize to failure.

>>> toList (fromString ")(" :: RegEx Char)
"[]"
>>> putStringLn (regbnfG (RegEx Char))
{start} = \q{regex}
{alternate} = \q{sequence}(\|\q{sequence})*
{atom} = \\q\q{nonterminal}|\\t\{\q{regex}\}|\q{class}|\(\q{regex}\)
{bounds} = \q{count}(,\q{count}?)?
{category} = Ll|Lu|Lt|Lm|Lo|Mn|Mc|Me|Nd|Nl|No|Pc|Pd|Ps|Pe|Pi|Pf|Po|Sm|Sc|Sk|So|Zs|Zl|Zp|Cc|Cf|Cs|Co|Cn
{char} = [^\(\)\*\+\?\[\\\]\^\{\|\}\P{Cc}]|\\\q{char-escaped}
{char-control} = x\{[0-9A-Fa-f]+\}
{char-escaped} = [\(\)\*\+\?\[\\\]\^\{\|\}]|\q{char-control}
{class} = \q{class-one-of}|\q{class-not-one-of}
{class-category} = \\p\{\q{category}\}|\\P\{\q{category}(\|\q{category})*\}
{class-char} = [^\(\)\*\+\-\?\[\\\]\^\{\|\}\P{Cc}]|\\\q{class-char-escaped}
{class-char-escaped} = [\(\)\*\+\-\?\[\\\]\^\{\|\}]|\q{char-control}
{class-not-one-of} = \q{class-category}|\[\^\q{class-range}*\q{class-category}?\]
{class-one-of} = \q{char}|\[\q{class-range}*\]
{class-range} = \q{class-char}(-\q{class-char})?
{count} = [0-9]+
{expression} = \q{atom}\?|\q{atom}\*|\q{atom}\+|\q{atom}\{\q{bounds}\}|\q{atom}
{nonterminal} = \{\q{char}*\}
{regex} = \q{alternate}
{sequence} = \q{expression}*
Instance details

Defined in Control.Lens.Grammar.RegEx

type Grammatical token (p :: Type -> Type -> Type) = (RegGrammatical token p, forall x y. BackusNaurForm (p x y)) Source #

The RegGrammatical BackusNaurForms, which run Grammars.

regbnfG :: forall a -> (Categorized token, Grammar token a) => Bnf (RegEx token) Source #

regbnfG generates a Bnf of RegExpressions from a context-free Grammar, over any token, of regular expression strings over characters. Since CtxGrammars aren't context-free, the type system will prevent regbnfG from being applied to a CtxGrammar. It can apply to a RegGrammar.

applicativeG :: (Grammar token a, Alternative f, TokenAlgebra token (f token), TerminalSymbol token (f ()), forall x. BackusNaurForm (f x), forall x. Tried (f x)) => f a Source #

Generate any Applicative parser backend from a Grammar with applicativeG. It works the same way as monadG, for parsers without Monad instances. That permits backends to use algorithms that can only parse context-free Grammars.

transducerG :: forall a -> (Categorized token, Grammar token a) => Transducer token Source #

Compile a Grammar into a Transducer.

>>> let regexMachine = transducerG @Char (RegEx Char)

A transducer is a form of finite state machine, usable as an intermediary for further generators like =~, expectNext, languageSample, parseForest & unreachableRules.

>>> import Test.QuickCheck
>>> let regexLang = languageSample @Char regexMachine
>>> words100 <- generate (take 100 <$> regexLang)
>>> quickCheck (property (all (=~ regexMachine) words100))
+++ OK, passed 100 tests.
>>> import Control.Monad.State
>>> import System.Random
>>> let gen = mkStdGen 69
>>> evalState (take 15 <$> regexLang) gen
["","|","\776269","()","[]","\\[","||","|\249908","\770923*","\1008821+","\318904?","\845807|","\477898\1026934","()*","()+"]
>>> import Data.Tree (drawForest)
>>> let (forest, _) = parseForest regexMachine "xy|z" in putStr (drawForest (map (fmap show) forest))
("regex",0,4,"xy|z")
|
`- ("alternate",0,4,"xy|z")
   |
   +- ("sequence",0,2,"xy")
   |  |
   |  +- ("expression",0,1,"x")
   |  |  |
   |  |  `- ("atom",0,1,"x")
   |  |     |
   |  |     `- ("class",0,1,"x")
   |  |        |
   |  |        `- ("class-one-of",0,1,"x")
   |  |           |
   |  |           `- ("char",0,1,"x")
   |  |
   |  `- ("expression",1,2,"y")
   |     |
   |     `- ("atom",1,2,"y")
   |        |
   |        `- ("class",1,2,"y")
   |           |
   |           `- ("class-one-of",1,2,"y")
   |              |
   |              `- ("char",1,2,"y")
   |
   `- ("sequence",3,4,"z")
      |
      `- ("expression",3,4,"z")
         |
         `- ("atom",3,4,"z")
            |
            `- ("class",3,4,"z")
               |
               `- ("class-one-of",3,4,"z")
                  |
                  `- ("char",3,4,"z")

Context-sensitive grammar

For context-sensitivity, the Monadic interface is used by importing Data.Profunctor.Monadic.Do qualified and using a "bonding" notation which mixes "idiom" style with qualified do-notation. Let's use length-encoded vectors of numbers as an example.

>>> import Numeric.Natural (Natural)
>>> import Control.Lens.Iso (Iso', iso)
>>> :set -XRecordWildCards
>>> :{
data LenVec = LenVec {length :: Natural, vector :: [Natural]}
  deriving (Eq, Ord, Show, Read)
_LenVec :: Iso' LenVec (Natural, [Natural])
_LenVec = iso (\LenVec {..} -> (length, vector)) (\(length, vector) -> LenVec {..})
:}
>>> :set -XQualifiedDo
>>> import qualified Data.Profunctor.Monadic.Do as P
>>> :{
lenvecGrammar :: CtxGrammatical Char p => p LenVec LenVec
lenvecGrammar = _LenVec >? P.do
  let
    numberG = numeral 10
    vectorG n = sepWith "," (exactly n) numberG
  len <- numberG             -- bonds to _LenVec
  terminal ";"               -- doesn't bond
  vectorG (fromIntegral len) -- bonds to _LenVec
instance CtxGrammar Char LenVec where ctxGrammar = lenvecGrammar
:}

The qualified do-notation changes the signature of P.>>=, so that we must apply the constructor pattern _LenVec to the do-block with the >? applicator. Any scoped bound action, var <- action, gets "bonded" to the constructor pattern. Unbound actions, except for the last action in the do-block, don't get bonded to the pattern. The last action does get bonded to the pattern. Any unscoped bound action, _ <- action, also gets bonded to the pattern, but being unscoped means it isn't added to the context. If all bound actions are unscoped, and filtration & failure handling aren't used, then a CtxGrammar can be rewritten as a Grammar since it is context-free. We can't generate a Bnf from a CtxGrammar since the rules aren't static, but dynamic and contextual. We can generate parsers and printers as expected.

>>> [vec | (vec, "") <- parseG "3;1,2,3"] :: [LenVec]
[LenVec {length = 3, vector = [1,2,3]}]
>>> [vec | (vec, "") <- parseG "0;1,2,3"] :: [LenVec]
[]
>>> [pr "" | pr <- printG (LenVec 2 [6,7])] :: [String]
["2;6,7"]
>>> [pr "" | pr <- printG (LenVec 200 [100])] :: [String]
[]

In addition to context-sensitivity via Monadic combinators, CtxGrammars add unrestricted filtration to Grammars. The satisfy combinator is an unrestricted token filter. And the satisfied pattern is used together with the Choice & Cochoice applicator >?< for unrestricted filtration.

>>> :{
palindromeG :: CtxGrammatical Char p => p String String
palindromeG = rule "palindrome" $
  satisfied (\wrd -> reverse wrd == wrd) >?< manyP (anyToken @Char)
:}
>>> [pal | word <- ["racecar", "word"], (pal, "") <- parseP (palindromeG :: Parsor String [] String String) word]
["racecar"]

Since CtxGrammars are embedded in Haskell, permitting computable predicates, and Filtrator has a default definition for Monadic Alternators, the context-sensitivity of CtxGrammar implies unrestricted filtration of grammars by computable predicates, which can recognize the larger class of recursively enumerable languages.

Context-sensitivity can also be optical. A Varifocal is an optic whose shape depends on the foci it builds, as no Bifocal can, applied in a CtxGrammar by contextually, or on a MonadicTrans profunctor, by contextuallyT. A heredoc's lines are its foci, its tag, its body, & its tag again, delimitBy by the first line equal to the opening tag, a language which isn't context-free.

>>> :{
data Heredoc = Heredoc String [String] deriving (Eq, Show)
heredocG :: CtxGrammatical Char p => p Heredoc Heredoc
heredocG = lined >~ terminal "<<" >* contextually (delimitBy (==)) lineG
  where
    lineG = manyP (notOneOf "\n") *< terminal "\n"
    lined = iso
      (\(Heredoc tag body) -> tag : body ++ [tag])
      (\case
        tag : rest -> Heredoc tag (if null rest then [] else init rest)
        [] -> Heredoc "" [])
instance CtxGrammar Char Heredoc where ctxGrammar = heredocG
:}
>>> [pr "" | pr <- printG (Heredoc "EOF" ["hi"])] :: [String]
["<<EOF\nhi\nEOF\n"]
>>> [h | (h, "") <- parseG @Heredoc "<<EOF\nhi\nEOF\n"]
[Heredoc "EOF" ["hi"]]
>>> parsecResult (parsecG @Heredoc "<<EOF\nhi\nEOF\n")
Just (Heredoc "EOF" ["hi"])
>>> [pr "" | pr <- printG (Heredoc "EOF" ["EOF"])] :: [String]
[]

Finally, CtxGrammars support failure reporting and backtracking. This has no effect on printG, parseG or unparseG; but it affects parsecG and unparsecG. For context, an LL grammar can be (un)parsed by an LL parser. An LL parser (un)parses from left to right, and constructs leftmost derivations. An LL(k) parser can look k tokens ahead. tParsor is an LL(∞) parser. tParsector is an LL(1) parser. The backtracking try combinator restores full lookahead to Parsector. Since both Parsor & Parsector are LL parsers they diverge if the CtxGrammar they're run on is left-recursive.

>>> parsecP (rule "foo" (fail "bar") >|< fail "baz") "abc"
ParsecState {parsecLooked = False, parsecOffset = 0, parsecStream = "abc", parsecFailure = ParsecFailure {parsecExpect = TokenClass (OneOf (fromList "")), parsecLabels = [Node {rootLabel = "foo", subForest = [Node {rootLabel = "bar", subForest = []}]},Node {rootLabel = "baz", subForest = []}]}, parsecResult = Nothing}
>>> parsecP (manyP (token 'a') >*< asIn @Char DecimalNumber :: Parsector String (String, Char) (String, Char)) "aaab"
ParsecState {parsecLooked = True, parsecOffset = 3, parsecStream = "b", parsecFailure = ParsecFailure {parsecExpect = TokenClass (Alternate (TokenClass (OneOf (fromList "a"))) (TokenClass (NotOneOf (fromList "") (AndAsIn DecimalNumber))) []), parsecLabels = []}, parsecResult = Nothing}
>>> unparsecP (tokens "abc") "abx" ""
ParsecState {parsecLooked = True, parsecOffset = 2, parsecStream = "ab", parsecFailure = ParsecFailure {parsecExpect = TokenClass (OneOf (fromList "c")), parsecLabels = []}, parsecResult = Nothing}

class CtxGrammar token a where Source #

A type's context-sensitive grammar, over its tokens; its context-free grammar, by default.

Minimal complete definition

Nothing

Methods

ctxGrammar :: CtxGrammatical token p => p a a Source #

default ctxGrammar :: (Grammar token a, CtxGrammatical token p) => p a a Source #

Instances

Instances details
CtxGrammar Char (Bnf (RegEx Char)) Source # 
Instance details

Defined in Control.Lens.Grammar.RegEx

CtxGrammar Char (RegEx Char) Source # 
Instance details

Defined in Control.Lens.Grammar.RegEx

type CtxGrammatical token (p :: Type -> Type -> Type) = (Grammatical token p, Filtrator p, forall x. MonadPlus (p x), forall x. MonadFail (p x)) Source #

The Grammatical Filtrators, MonadPluses & MonadFails, which run CtxGrammars.

printG Source #

Arguments

:: forall a string token m. (CtxGrammar token a, Cons string string token token, IsList string, Item string ~ token, Categorized token, Alternative m, Monad m, Filterable m) 
=> a

syntax

-> m (string -> string) 

printG generates a printer from a CtxGrammar. Since both RegGrammars and context-free Grammars are CtxGrammars, the type system will allow printG to be applied to them. Running the printer on a syntax value returns a function that conses tokens at the beginning of an input string, from right to left.

parseG Source #

Arguments

:: forall a string token m. (CtxGrammar token a, Cons string string token token, Snoc string string token token, IsList string, Item string ~ token, Categorized token, Alternative m, Monad m, Filterable m) 
=> string

input

-> m (a, string) 

parseG generates a parser from a LL(∞) CtxGrammar. Since both RegGrammars and context-free Grammars are CtxGrammars, the type system will allow parseG to be applied to them. Running the parser on an input string value unconses tokens from the beginning of an input string from left to right, returning a syntax value and the remaining output string.

unparseG Source #

Arguments

:: forall a string token m. (CtxGrammar token a, Cons string string token token, Snoc string string token token, IsList string, Item string ~ token, Categorized token, Alternative m, Monad m, Filterable m) 
=> a

syntax

-> string

input

-> m string 

unparseG generates a printer from a LL(∞) CtxGrammar. Since both RegGrammars and context-free Grammars are CtxGrammars, the type system will allow unparseG to be applied to them. Running the printer on a syntax value and an input string snocs tokens at the end of the string, from left to right, returning the output string. Print to a string with a constant time snoc, like a Data.Sequence.Seq, since a list's snoc is linear, making printing to a String quadratic.

parsecG Source #

Arguments

:: forall a string token. (CtxGrammar token a, Cons string string token token, Snoc string string token token, Item string ~ token, Categorized token) 
=> string

input

-> ParsecState string a 

parsecG generates a parser from a LL(1) CtxGrammar, with try for restoring full LL(∞) lookahead. Since both RegGrammars and context-free Grammars are CtxGrammars, the type system will allow parsecG to be applied to them. Running the parser on an input string value unconses tokens from the beginning of an input string from left to right, returning parsecResult as Nothing on failure or Just an output syntax value, with parse failure stored in parsecFailure, and a remaining output parsecStream.

unparsecG Source #

Arguments

:: forall a string token. (CtxGrammar token a, Cons string string token token, Snoc string string token token, Item string ~ token, Categorized token) 
=> a

syntax

-> string

input

-> ParsecState string a 

unparsecG generates a printer from a LL(1) CtxGrammar, with try for restoring full LL(∞) lookahead. Since both RegGrammars and context-free Grammars are CtxGrammars, the type system will allow unparsecG to be applied to them. Running the printer on a syntax value and an input string snocs tokens at the end of the string, from left to right, returning parsecResult as Nothing on failure or Just the input syntax value, with print success stored in parsecStream. Print to a string with a constant time snoc, like a Data.Sequence.Seq, since a list's snoc is linear, making printing to a String quadratic.

readG :: CtxGrammar Char a => ReadP a Source #

Generate a ReadP backend from a CtxGrammar Char.

monadG :: (CtxGrammar token a, MonadPlus m, MonadFail m, Filterable m, forall x. BackusNaurForm (m x), forall x. Tried (m x), TokenAlgebra token (m token), TerminalSymbol token (m ())) => m a Source #

Generate any parser Monad backend from a CtxGrammar with monadG. Let's see how to do this without orphan instances, using the Megaparsec library.

import qualified Text.Megaparsec as M
import qualified Text.Megaparsec.Char as M
import Control.Lens.Grammar

newtype WrapMega a = WrapMega {unwrapMega :: M.Parsec String String a}
  deriving newtype
    ( Functor, Applicative, Alternative
    , Monad, MonadPlus, MonadFail
    )
instance TerminalSymbol Char (WrapMega ()) where
  terminal str = WrapMega (M.chunk str *> pure ())
instance TokenAlgebra Char (WrapMega Char) where
  tokenClass exam = WrapMega $ M.label (show exam) (M.satisfy (tokenClass exam))
instance Tokenized Char (WrapMega Char) where
  anyToken = WrapMega M.anySingle
  token = WrapMega . M.single
  oneOf = WrapMega . M.oneOf
  notOneOf = WrapMega . M.noneOf
  asIn cat = WrapMega $ M.label ("in category " ++ show cat) (M.satisfy (asIn cat))
  notAsIn cat = WrapMega $ M.label ("not in category " ++ show cat) (M.satisfy (notAsIn cat))
instance Ruled (WrapMega a) where
  rule lbl (WrapMega p) = WrapMega (M.label lbl p)
instance BackusNaurForm (WrapMega a)
instance Tried (WrapMega a) where
  try (WrapMega p) = WrapMega (M.try p)
instance Filterable WrapMega where
  catMaybes m = m >>= maybe (fail "unrestricted filtration") pure

megaparsecG :: CtxGrammar Char a => M.Parsec String String a
megaparsecG = unwrapMega (monadG @Char)

Numerals

digit :: (Integral n, Choice p, Tokenized Char (p Char Char)) => n -> p n n Source #

A digit in a base, from 2 to 36, by its value: 0-9, then letters, printing in lowercase, & parsing either case.

>>> [d | (d, "") <- parseP (digit (16 :: Int) :: Parsor String [] Int Int) "F"]
[15]

numeral :: (Integral n, Alternator p, Tokenized Char (p Char Char)) => n -> p n n Source #

A natural number in a base, from 2 to 36, by its digits, most significant first, printing without leading zeros, & parsing them too, an improper iso.

>>> ($ "") <$> printP (numeral (16 :: Integer) :: Printor String Maybe Integer Integer) 255
Just "ff"

Utility

putStringLn :: (IsList string, Item string ~ Char) => string -> IO () Source #

putStringLn is a utility that generalizes putStrLn to string-like interfaces such as RegEx and Bnf of Chars.

Re-exports

failP :: (Ruled p, DisjunctiveMonoid p) => String -> p Source #

A nonterminal symbol to indicate a failure.

ruleTyped :: (Typeable a, Ruled (p a a)) => p a a -> p a a Source #

A rule for a Haskell type, like a type definition, named by its Typeable type, so that each type's rule is its own.

Rule names follow a convention: a module-qualified word, like M.N.x, names a definition by its qualified name, & may be displayed unqualified, as x, whenever that's unambiguous. So a type's rule is named by its fully qualified type, such as Data.Map.Internal.Map Data.Text.Internal.Text GHC.Types.Int, displayed as Map Text Int.

class Ruled bnf => BackusNaurForm bnf where Source #

BackusNaurForm grammar combinators formalize traced rule abstraction and general recursion with ruleRec, related by this invariant.

prop> rule label bnf = ruleRec label (\_ -> bnf)

The BackusNaurForm interface is reminiscent of two distinct notions of "trace". First as a traced Cartesian monoidal category which models general recursion abstractly, and second as a trace-like label for rule abstraction. The category (->) already has a traced (,)-monoidal structure in the form of unfirst = loop or equivalently the fixpoint function fix, determining the default method for a BackusNaurForm, by which the invariant holds for any Ruled rule.

prop> ruleRec label = rule label . fix

The BackusNaurForm interface permits overloading these methods, and tracing them with a label.

Both context-free Grammars & CtxGrammars support the BackusNaurForm interface. See Breitner, Showcasing Applicative, for the original interface.

Minimal complete definition

Nothing

Methods

ruleRec :: String -> (bnf -> bnf) -> bnf Source #

General recursion.

Instances

Instances details
(Ord rule, NonTerminalSymbol rule) => BackusNaurForm (Bnf rule) Source # 
Instance details

Defined in Control.Lens.Grammar.RegEx

Methods

ruleRec :: String -> (Bnf rule -> Bnf rule) -> Bnf rule Source #

BackusNaurForm (ReadP a) Source # 
Instance details

Defined in Control.Lens.Grammar.BackusNaur

Methods

ruleRec :: String -> (ReadP a -> ReadP a) -> ReadP a Source #

BackusNaurForm (ReadPrec a) Source # 
Instance details

Defined in Control.Lens.Grammar.BackusNaur

Methods

ruleRec :: String -> (ReadPrec a -> ReadPrec a) -> ReadPrec a Source #

BackusNaurForm (p a b) => BackusNaurForm (Precedence p a b) Source # 
Instance details

Defined in Control.Lens.Grammar.Prec

Methods

ruleRec :: String -> (Precedence p a b -> Precedence p a b) -> Precedence p a b Source #

BackusNaurForm k => BackusNaurForm (Grammor k a b) Source # 
Instance details

Defined in Data.Profunctor.Grammar

Methods

ruleRec :: String -> (Grammor k a b -> Grammor k a b) -> Grammor k a b Source #

BackusNaurForm (Parsector s a b) Source # 
Instance details

Defined in Data.Profunctor.Grammar.Parsector

Methods

ruleRec :: String -> (Parsector s a b -> Parsector s a b) -> Parsector s a b Source #

BackusNaurForm (Prettor w f a b) Source # 
Instance details

Defined in Control.Lens.Grammar.Pretty

Methods

ruleRec :: String -> (Prettor w f a b -> Prettor w f a b) -> Prettor w f a b Source #

BackusNaurForm (Parsor s m a b) Source # 
Instance details

Defined in Data.Profunctor.Grammar

Methods

ruleRec :: String -> (Parsor s m a b -> Parsor s m a b) -> Parsor s m a b Source #

BackusNaurForm (Printor s m a b) Source # 
Instance details

Defined in Data.Profunctor.Grammar.Printor

Methods

ruleRec :: String -> (Printor s m a b -> Printor s m a b) -> Printor s m a b Source #

(forall x. BackusNaurForm (f x)) => BackusNaurForm (Joker f a b) Source # 
Instance details

Defined in Control.Lens.Grammar.BackusNaur

Methods

ruleRec :: String -> (Joker f a b -> Joker f a b) -> Joker f a b Source #

class Ruled p where Source #

Ruled grammar combinators formalize rule abstraction, labeling a subgrammar, which a BackusNaurForm names as a nonterminal, & a parser may report on failure.

prop> rule _ = id

Minimal complete definition

Nothing

Methods

rule :: String -> p -> p Source #

Subgrammar abstraction.

Instances

Instances details
(Ord rule, NonTerminalSymbol rule) => Ruled (Bnf rule) Source # 
Instance details

Defined in Control.Lens.Grammar.RegEx

Methods

rule :: String -> Bnf rule -> Bnf rule Source #

Ruled (ReadP a) Source # 
Instance details

Defined in Control.Lens.Grammar.BackusNaur

Methods

rule :: String -> ReadP a -> ReadP a Source #

Ruled (ReadPrec a) Source # 
Instance details

Defined in Control.Lens.Grammar.BackusNaur

Methods

rule :: String -> ReadPrec a -> ReadPrec a Source #

Ruled (p a b) => Ruled (Precedence p a b) Source # 
Instance details

Defined in Control.Lens.Grammar.Prec

Methods

rule :: String -> Precedence p a b -> Precedence p a b Source #

Ruled k => Ruled (Grammor k a b) Source # 
Instance details

Defined in Data.Profunctor.Grammar

Methods

rule :: String -> Grammor k a b -> Grammor k a b Source #

Ruled (Parsector s a b) Source # 
Instance details

Defined in Data.Profunctor.Grammar.Parsector

Methods

rule :: String -> Parsector s a b -> Parsector s a b Source #

Ruled (Prettor w f a b) Source # 
Instance details

Defined in Control.Lens.Grammar.Pretty

Methods

rule :: String -> Prettor w f a b -> Prettor w f a b Source #

Ruled (Parsor s m a b) Source # 
Instance details

Defined in Data.Profunctor.Grammar

Methods

rule :: String -> Parsor s m a b -> Parsor s m a b Source #

Ruled (Printor s m a b) Source # 
Instance details

Defined in Data.Profunctor.Grammar.Printor

Methods

rule :: String -> Printor s m a b -> Printor s m a b Source #

(forall x. Ruled (f x)) => Ruled (Joker f a b) Source # 
Instance details

Defined in Control.Lens.Grammar.BackusNaur

Methods

rule :: String -> Joker f a b -> Joker f a b Source #

class Tried p where Source #

Tried grammar combinators mark subgrammars to backtrack upon failure, by try, in a predictive parser, like Parsector. Use try on a subgrammar which isn't LL(1) but still is LL(∞). try doesn't change the language of a grammar, so the default, for grammars which can't record it, is

prop> try = id

Minimal complete definition

Nothing

Methods

try :: p -> p Source #

Backtracking upon failure.

Instances

Instances details
Tried rule => Tried (Bnf rule) Source #

try the start of a Bnf, recording it as its rules do.

Instance details

Defined in Control.Lens.Grammar.RegEx

Methods

try :: Bnf rule -> Bnf rule Source #

Tried (RegEx token) Source #

A RegEx records try, but for patterns of the empty word or none, which can't fail after reading a token.

Instance details

Defined in Control.Lens.Grammar.RegEx

Methods

try :: RegEx token -> RegEx token Source #

Tried (ReadP a) Source # 
Instance details

Defined in Control.Lens.Grammar.BackusNaur

Methods

try :: ReadP a -> ReadP a Source #

Tried (ReadPrec a) Source # 
Instance details

Defined in Control.Lens.Grammar.BackusNaur

Methods

try :: ReadPrec a -> ReadPrec a Source #

Tried (p a b) => Tried (Precedence p a b) Source # 
Instance details

Defined in Control.Lens.Grammar.Prec

Methods

try :: Precedence p a b -> Precedence p a b Source #

Tried k => Tried (Grammor k a b) Source # 
Instance details

Defined in Data.Profunctor.Grammar

Methods

try :: Grammor k a b -> Grammor k a b Source #

Tried (Parsector s a b) Source # 
Instance details

Defined in Data.Profunctor.Grammar.Parsector

Methods

try :: Parsector s a b -> Parsector s a b Source #

Tried (Prettor w f a b) Source # 
Instance details

Defined in Control.Lens.Grammar.Pretty

Methods

try :: Prettor w f a b -> Prettor w f a b Source #

Tried (Parsor s m a b) Source # 
Instance details

Defined in Data.Profunctor.Grammar

Methods

try :: Parsor s m a b -> Parsor s m a b Source #

Tried (Printor s m a b) Source # 
Instance details

Defined in Data.Profunctor.Grammar.Printor

Methods

try :: Printor s m a b -> Printor s m a b Source #

(forall x. Tried (f x)) => Tried (Joker f a b) Source # 
Instance details

Defined in Control.Lens.Grammar.BackusNaur

Methods

try :: Joker f a b -> Joker f a b Source #

class Applicative f => Alternative (f :: Type -> Type) where #

A monoid on applicative functors.

If defined, some and many should be the least solutions of the equations:

Examples

Expand
>>> Nothing <|> Just 42
Just 42
>>> [1, 2] <|> [3, 4]
[1,2,3,4]
>>> empty <|> print (2^15)
32768

Minimal complete definition

empty, (<|>)

Methods

empty :: f a #

The identity of <|>

empty <|> a     == a
a     <|> empty == a

(<|>) :: f a -> f a -> f a infixl 3 #

An associative binary operation

some :: f a -> f [a] #

One or more.

Examples

Expand
>>> some (putStr "la")
lalalalalalalalala... * goes on forever *
>>> some Nothing
nothing
>>> take 5 <$> some (Just 1)
* hangs forever *

Note that this function can be used with Parsers based on Applicatives. In that case some parser will attempt to parse parser one or more times until it fails.

many :: f a -> f [a] #

Zero or more.

Examples

Expand
>>> many (putStr "la")
lalalalalalalalala... * goes on forever *
>>> many Nothing
Just []
>>> take 5 <$> many (Just 1)
* hangs forever *

Note that this function can be used with Parsers based on Applicatives. In that case many parser will attempt to parse parser zero or more times until it fails.

Instances

Instances details
Alternative Seq #

Since: containers-0.5.4

Instance details

Defined in Data.Sequence.Internal

Methods

empty :: Seq a #

(<|>) :: Seq a -> Seq a -> Seq a #

some :: Seq a -> Seq [a] #

many :: Seq a -> Seq [a] #

Alternative ZipList #

Since: base-4.11.0.0

Instance details

Defined in GHC.Internal.Functor.ZipList

Methods

empty :: ZipList a #

(<|>) :: ZipList a -> ZipList a -> ZipList a #

some :: ZipList a -> ZipList [a] #

many :: ZipList a -> ZipList [a] #

Alternative P #

Since: base-4.5.0.0

Instance details

Defined in GHC.Internal.Text.ParserCombinators.ReadP

Methods

empty :: P a #

(<|>) :: P a -> P a -> P a #

some :: P a -> P [a] #

many :: P a -> P [a] #

Alternative ReadP #

Since: base-4.6.0.0

Instance details

Defined in GHC.Internal.Text.ParserCombinators.ReadP

Methods

empty :: ReadP a #

(<|>) :: ReadP a -> ReadP a -> ReadP a #

some :: ReadP a -> ReadP [a] #

many :: ReadP a -> ReadP [a] #

Alternative ReadPrec #

Since: base-4.6.0.0

Instance details

Defined in GHC.Internal.Text.ParserCombinators.ReadPrec

Methods

empty :: ReadPrec a #

(<|>) :: ReadPrec a -> ReadPrec a -> ReadPrec a #

some :: ReadPrec a -> ReadPrec [a] #

many :: ReadPrec a -> ReadPrec [a] #

Alternative IO #

Takes the first non-throwing IO action's result. empty throws an exception.

Since: base-4.9.0.0

Instance details

Defined in GHC.Internal.Base

Methods

empty :: IO a #

(<|>) :: IO a -> IO a -> IO a #

some :: IO a -> IO [a] #

many :: IO a -> IO [a] #

Alternative Deque # 
Instance details

Defined in Control.Lens.Internal.Deque

Methods

empty :: Deque a #

(<|>) :: Deque a -> Deque a -> Deque a #

some :: Deque a -> Deque [a] #

many :: Deque a -> Deque [a] #

Alternative Array # 
Instance details

Defined in Data.Primitive.Array

Methods

empty :: Array a #

(<|>) :: Array a -> Array a -> Array a #

some :: Array a -> Array [a] #

many :: Array a -> Array [a] #

Alternative SmallArray # 
Instance details

Defined in Data.Primitive.SmallArray

Alternative Vector # 
Instance details

Defined in Data.Vector

Methods

empty :: Vector a #

(<|>) :: Vector a -> Vector a -> Vector a #

some :: Vector a -> Vector [a] #

many :: Vector a -> Vector [a] #

Alternative Vector # 
Instance details

Defined in Data.Vector.Strict

Methods

empty :: Vector a #

(<|>) :: Vector a -> Vector a -> Vector a #

some :: Vector a -> Vector [a] #

many :: Vector a -> Vector [a] #

Alternative Maybe #

Picks the leftmost Just value, or, alternatively, Nothing.

Since: base-2.1

Instance details

Defined in GHC.Internal.Base

Methods

empty :: Maybe a #

(<|>) :: Maybe a -> Maybe a -> Maybe a #

some :: Maybe a -> Maybe [a] #

many :: Maybe a -> Maybe [a] #

Alternative [] #

Combines lists by concatenation, starting from the empty list.

Since: base-2.1

Instance details

Defined in GHC.Internal.Base

Methods

empty :: [a] #

(<|>) :: [a] -> [a] -> [a] #

some :: [a] -> [[a]] #

many :: [a] -> [[a]] #

MonadPlus m => Alternative (WrappedMonad m) #

Since: base-2.1

Instance details

Defined in Control.Applicative

Methods

empty :: WrappedMonad m a #

(<|>) :: WrappedMonad m a -> WrappedMonad m a -> WrappedMonad m a #

some :: WrappedMonad m a -> WrappedMonad m [a] #

many :: WrappedMonad m a -> WrappedMonad m [a] #

Alternative v => Alternative (Free v) #

This violates the Alternative laws, handle with care.

Instance details

Defined in Control.Monad.Free

Methods

empty :: Free v a #

(<|>) :: Free v a -> Free v a -> Free v a #

some :: Free v a -> Free v [a] #

many :: Free v a -> Free v [a] #

ArrowPlus a => Alternative (ArrowMonad a) #

Since: base-4.6.0.0

Instance details

Defined in GHC.Internal.Control.Arrow

Methods

empty :: ArrowMonad a a0 #

(<|>) :: ArrowMonad a a0 -> ArrowMonad a a0 -> ArrowMonad a a0 #

some :: ArrowMonad a a0 -> ArrowMonad a [a0] #

many :: ArrowMonad a a0 -> ArrowMonad a [a0] #

Alternative (Proxy :: Type -> Type) #

Since: base-4.9.0.0

Instance details

Defined in GHC.Internal.Data.Proxy

Methods

empty :: Proxy a #

(<|>) :: Proxy a -> Proxy a -> Proxy a #

some :: Proxy a -> Proxy [a] #

many :: Proxy a -> Proxy [a] #

Alternative (U1 :: Type -> Type) #

Since: base-4.9.0.0

Instance details

Defined in GHC.Internal.Generics

Methods

empty :: U1 a #

(<|>) :: U1 a -> U1 a -> U1 a #

some :: U1 a -> U1 [a] #

many :: U1 a -> U1 [a] #

Alternative f => Alternative (Yoneda f) # 
Instance details

Defined in Data.Functor.Yoneda

Methods

empty :: Yoneda f a #

(<|>) :: Yoneda f a -> Yoneda f a -> Yoneda f a #

some :: Yoneda f a -> Yoneda f [a] #

many :: Yoneda f a -> Yoneda f [a] #

Alternative (ReifiedFold s) # 
Instance details

Defined in Control.Lens.Reified

Methods

empty :: ReifiedFold s a #

(<|>) :: ReifiedFold s a -> ReifiedFold s a -> ReifiedFold s a #

some :: ReifiedFold s a -> ReifiedFold s [a] #

many :: ReifiedFold s a -> ReifiedFold s [a] #

Alternative (UniqueParser s) # 
Instance details

Defined in Prettyprinter.Render.Util.SimpleDocTree

Methods

empty :: UniqueParser s a #

(<|>) :: UniqueParser s a -> UniqueParser s a -> UniqueParser s a #

some :: UniqueParser s a -> UniqueParser s [a] #

many :: UniqueParser s a -> UniqueParser s [a] #

Alternative f => Alternative (Lift f) #

A combination is Pure only either part is.

Instance details

Defined in Control.Applicative.Lift

Methods

empty :: Lift f a #

(<|>) :: Lift f a -> Lift f a -> Lift f a #

some :: Lift f a -> Lift f [a] #

many :: Lift f a -> Lift f [a] #

(Functor m, Monad m) => Alternative (MaybeT m) # 
Instance details

Defined in Control.Monad.Trans.Maybe

Methods

empty :: MaybeT m a #

(<|>) :: MaybeT m a -> MaybeT m a -> MaybeT m a #

some :: MaybeT m a -> MaybeT m [a] #

many :: MaybeT m a -> MaybeT m [a] #

Alternative f => Alternative (WrappedFoldable f) # 
Instance details

Defined in Witherable

(ArrowZero a, ArrowPlus a) => Alternative (WrappedArrow a b) #

Since: base-2.1

Instance details

Defined in Control.Applicative

Methods

empty :: WrappedArrow a b a0 #

(<|>) :: WrappedArrow a b a0 -> WrappedArrow a b a0 -> WrappedArrow a b a0 #

some :: WrappedArrow a b a0 -> WrappedArrow a b [a0] #

many :: WrappedArrow a b a0 -> WrappedArrow a b [a0] #

Alternative (bi a) => Alternative (Biap bi a) # 
Instance details

Defined in Data.Bifunctor.Biap

Methods

empty :: Biap bi a a0 #

(<|>) :: Biap bi a a0 -> Biap bi a a0 -> Biap bi a a0 #

some :: Biap bi a a0 -> Biap bi a [a0] #

many :: Biap bi a a0 -> Biap bi a [a0] #

Alternator p => Alternative (UpperTriangular p a) # 
Instance details

Defined in Control.Lens.Prismoid

Methods

empty :: UpperTriangular p a a0 #

(<|>) :: UpperTriangular p a a0 -> UpperTriangular p a a0 -> UpperTriangular p a a0 #

some :: UpperTriangular p a a0 -> UpperTriangular p a [a0] #

many :: UpperTriangular p a a0 -> UpperTriangular p a [a0] #

Alternative (Altar a b) # 
Instance details

Defined in Control.Lens.Wither

Methods

empty :: Altar a b a0 #

(<|>) :: Altar a b a0 -> Altar a b a0 -> Altar a b a0 #

some :: Altar a b a0 -> Altar a b [a0] #

many :: Altar a b a0 -> Altar a b [a0] #

Alternative (p a) => Alternative (Monoidally p a) # 
Instance details

Defined in Data.Profunctor.Monoidal

Methods

empty :: Monoidally p a a0 #

(<|>) :: Monoidally p a a0 -> Monoidally p a a0 -> Monoidally p a a0 #

some :: Monoidally p a a0 -> Monoidally p a [a0] #

many :: Monoidally p a a0 -> Monoidally p a [a0] #

Alternative (p a) => Alternative (Precedence p a) Source # 
Instance details

Defined in Control.Lens.Grammar.Prec

Methods

empty :: Precedence p a a0 #

(<|>) :: Precedence p a a0 -> Precedence p a a0 -> Precedence p a a0 #

some :: Precedence p a a0 -> Precedence p a [a0] #

many :: Precedence p a a0 -> Precedence p a [a0] #

KleeneStarAlgebra k => Alternative (Grammor k a) Source # 
Instance details

Defined in Data.Profunctor.Grammar

Methods

empty :: Grammor k a a0 #

(<|>) :: Grammor k a a0 -> Grammor k a a0 -> Grammor k a a0 #

some :: Grammor k a a0 -> Grammor k a [a0] #

many :: Grammor k a a0 -> Grammor k a [a0] #

Categorized (Item s) => Alternative (Parsector s a) Source # 
Instance details

Defined in Data.Profunctor.Grammar.Parsector

Methods

empty :: Parsector s a a0 #

(<|>) :: Parsector s a a0 -> Parsector s a a0 -> Parsector s a a0 #

some :: Parsector s a a0 -> Parsector s a [a0] #

many :: Parsector s a a0 -> Parsector s a [a0] #

(Functor f, MonadPlus m) => Alternative (FreeT f m) # 
Instance details

Defined in Control.Monad.Trans.Free

Methods

empty :: FreeT f m a #

(<|>) :: FreeT f m a -> FreeT f m a -> FreeT f m a #

some :: FreeT f m a -> FreeT f m [a] #

many :: FreeT f m a -> FreeT f m [a] #

Alternative m => Alternative (Kleisli m a) #

Since: base-4.14.0.0

Instance details

Defined in GHC.Internal.Control.Arrow

Methods

empty :: Kleisli m a a0 #

(<|>) :: Kleisli m a a0 -> Kleisli m a a0 -> Kleisli m a a0 #

some :: Kleisli m a a0 -> Kleisli m a [a0] #

many :: Kleisli m a a0 -> Kleisli m a [a0] #

Alternative f => Alternative (Ap f) #

Since: base-4.12.0.0

Instance details

Defined in GHC.Internal.Data.Monoid

Methods

empty :: Ap f a #

(<|>) :: Ap f a -> Ap f a -> Ap f a #

some :: Ap f a -> Ap f [a] #

many :: Ap f a -> Ap f [a] #

Alternative f => Alternative (Alt f) #

Since: base-4.8.0.0

Instance details

Defined in GHC.Internal.Data.Semigroup.Internal

Methods

empty :: Alt f a #

(<|>) :: Alt f a -> Alt f a -> Alt f a #

some :: Alt f a -> Alt f [a] #

many :: Alt f a -> Alt f [a] #

(Generic1 f, Alternative (Rep1 f)) => Alternative (Generically1 f) #

Since: base-4.17.0.0

Instance details

Defined in GHC.Internal.Generics

Methods

empty :: Generically1 f a #

(<|>) :: Generically1 f a -> Generically1 f a -> Generically1 f a #

some :: Generically1 f a -> Generically1 f [a] #

many :: Generically1 f a -> Generically1 f [a] #

Alternative f => Alternative (Rec1 f) #

Since: base-4.9.0.0

Instance details

Defined in GHC.Internal.Generics

Methods

empty :: Rec1 f a #

(<|>) :: Rec1 f a -> Rec1 f a -> Rec1 f a #

some :: Rec1 f a -> Rec1 f [a] #

many :: Rec1 f a -> Rec1 f [a] #

(Profunctor p, ArrowPlus p) => Alternative (Closure p a) # 
Instance details

Defined in Data.Profunctor.Closed

Methods

empty :: Closure p a a0 #

(<|>) :: Closure p a a0 -> Closure p a a0 -> Closure p a a0 #

some :: Closure p a a0 -> Closure p a [a0] #

many :: Closure p a a0 -> Closure p a [a0] #

(Profunctor p, ArrowPlus p) => Alternative (Tambara p a) # 
Instance details

Defined in Data.Profunctor.Strong

Methods

empty :: Tambara p a a0 #

(<|>) :: Tambara p a a0 -> Tambara p a a0 -> Tambara p a a0 #

some :: Tambara p a a0 -> Tambara p a [a0] #

many :: Tambara p a a0 -> Tambara p a [a0] #

(Profunctor p, Alternative (p a)) => Alternative (Coyoneda p a) # 
Instance details

Defined in Control.Lens.Internal.Distributor.Orphanage

Methods

empty :: Coyoneda p a a0 #

(<|>) :: Coyoneda p a a0 -> Coyoneda p a a0 -> Coyoneda p a a0 #

some :: Coyoneda p a a0 -> Coyoneda p a [a0] #

many :: Coyoneda p a a0 -> Coyoneda p a [a0] #

(Profunctor p, Alternative (p a)) => Alternative (Yoneda p a) # 
Instance details

Defined in Control.Lens.Internal.Distributor.Orphanage

Methods

empty :: Yoneda p a a0 #

(<|>) :: Yoneda p a a0 -> Yoneda p a a0 -> Yoneda p a a0 #

some :: Yoneda p a a0 -> Yoneda p a [a0] #

many :: Yoneda p a a0 -> Yoneda p a [a0] #

Alternative f => Alternative (Backwards f) #

Try alternatives in the same order as f.

Instance details

Defined in Control.Applicative.Backwards

Methods

empty :: Backwards f a #

(<|>) :: Backwards f a -> Backwards f a -> Backwards f a #

some :: Backwards f a -> Backwards f [a] #

many :: Backwards f a -> Backwards f [a] #

(Monoid w, Functor m, MonadPlus m) => Alternative (AccumT w m) # 
Instance details

Defined in Control.Monad.Trans.Accum

Methods

empty :: AccumT w m a #

(<|>) :: AccumT w m a -> AccumT w m a -> AccumT w m a #

some :: AccumT w m a -> AccumT w m [a] #

many :: AccumT w m a -> AccumT w m [a] #

(Functor m, Monad m, Monoid e) => Alternative (ExceptT e m) # 
Instance details

Defined in Control.Monad.Trans.Except

Methods

empty :: ExceptT e m a #

(<|>) :: ExceptT e m a -> ExceptT e m a -> ExceptT e m a #

some :: ExceptT e m a -> ExceptT e m [a] #

many :: ExceptT e m a -> ExceptT e m [a] #

Alternative m => Alternative (IdentityT m) # 
Instance details

Defined in Control.Monad.Trans.Identity

Methods

empty :: IdentityT m a #

(<|>) :: IdentityT m a -> IdentityT m a -> IdentityT m a #

some :: IdentityT m a -> IdentityT m [a] #

many :: IdentityT m a -> IdentityT m [a] #

Alternative m => Alternative (ReaderT r m) # 
Instance details

Defined in Control.Monad.Trans.Reader

Methods

empty :: ReaderT r m a #

(<|>) :: ReaderT r m a -> ReaderT r m a -> ReaderT r m a #

some :: ReaderT r m a -> ReaderT r m [a] #

many :: ReaderT r m a -> ReaderT r m [a] #

(Functor m, MonadPlus m) => Alternative (SelectT r m) # 
Instance details

Defined in Control.Monad.Trans.Select

Methods

empty :: SelectT r m a #

(<|>) :: SelectT r m a -> SelectT r m a -> SelectT r m a #

some :: SelectT r m a -> SelectT r m [a] #

many :: SelectT r m a -> SelectT r m [a] #

(Functor m, MonadPlus m) => Alternative (StateT s m) # 
Instance details

Defined in Control.Monad.Trans.State.Lazy

Methods

empty :: StateT s m a #

(<|>) :: StateT s m a -> StateT s m a -> StateT s m a #

some :: StateT s m a -> StateT s m [a] #

many :: StateT s m a -> StateT s m [a] #

(Functor m, MonadPlus m) => Alternative (StateT s m) # 
Instance details

Defined in Control.Monad.Trans.State.Strict

Methods

empty :: StateT s m a #

(<|>) :: StateT s m a -> StateT s m a -> StateT s m a #

some :: StateT s m a -> StateT s m [a] #

many :: StateT s m a -> StateT s m [a] #

(Functor m, MonadPlus m) => Alternative (WriterT w m) # 
Instance details

Defined in Control.Monad.Trans.Writer.CPS

Methods

empty :: WriterT w m a #

(<|>) :: WriterT w m a -> WriterT w m a -> WriterT w m a #

some :: WriterT w m a -> WriterT w m [a] #

many :: WriterT w m a -> WriterT w m [a] #

(Monoid w, Alternative m) => Alternative (WriterT w m) # 
Instance details

Defined in Control.Monad.Trans.Writer.Lazy

Methods

empty :: WriterT w m a #

(<|>) :: WriterT w m a -> WriterT w m a -> WriterT w m a #

some :: WriterT w m a -> WriterT w m [a] #

many :: WriterT w m a -> WriterT w m [a] #

(Monoid w, Alternative m) => Alternative (WriterT w m) # 
Instance details

Defined in Control.Monad.Trans.Writer.Strict

Methods

empty :: WriterT w m a #

(<|>) :: WriterT w m a -> WriterT w m a -> WriterT w m a #

some :: WriterT w m a -> WriterT w m [a] #

many :: WriterT w m a -> WriterT w m [a] #

Alternative f => Alternative (Reverse f) #

Derived instance.

Instance details

Defined in Data.Functor.Reverse

Methods

empty :: Reverse f a #

(<|>) :: Reverse f a -> Reverse f a -> Reverse f a #

some :: Reverse f a -> Reverse f [a] #

many :: Reverse f a -> Reverse f [a] #

(Alternative f, Alternative g) => Alternative (Product f g) #

Since: base-4.9.0.0

Instance details

Defined in Data.Functor.Product

Methods

empty :: Product f g a #

(<|>) :: Product f g a -> Product f g a -> Product f g a #

some :: Product f g a -> Product f g [a] #

many :: Product f g a -> Product f g [a] #

Alternative (Binocular a b s) # 
Instance details

Defined in Control.Lens.Bifocal

Methods

empty :: Binocular a b s a0 #

(<|>) :: Binocular a b s a0 -> Binocular a b s a0 -> Binocular a b s a0 #

some :: Binocular a b s a0 -> Binocular a b s [a0] #

many :: Binocular a b s a0 -> Binocular a b s [a0] #

Alternative (Spectacle a b s) # 
Instance details

Defined in Control.Lens.Bifocal

Methods

empty :: Spectacle a b s a0 #

(<|>) :: Spectacle a b s a0 -> Spectacle a b s a0 -> Spectacle a b s a0 #

some :: Spectacle a b s a0 -> Spectacle a b s [a0] #

many :: Spectacle a b s a0 -> Spectacle a b s [a0] #

Alternative (Prismatoid a b s) # 
Instance details

Defined in Control.Lens.Prismoid

Methods

empty :: Prismatoid a b s a0 #

(<|>) :: Prismatoid a b s a0 -> Prismatoid a b s a0 -> Prismatoid a b s a0 #

some :: Prismatoid a b s a0 -> Prismatoid a b s [a0] #

many :: Prismatoid a b s a0 -> Prismatoid a b s [a0] #

Alternative (Prismocular a b s) # 
Instance details

Defined in Control.Lens.Prismoid

Methods

empty :: Prismocular a b s a0 #

(<|>) :: Prismocular a b s a0 -> Prismocular a b s a0 -> Prismocular a b s a0 #

some :: Prismocular a b s a0 -> Prismocular a b s [a0] #

many :: Prismocular a b s a0 -> Prismocular a b s [a0] #

(Monoid w, Alternative f) => Alternative (Prettor w f a) Source # 
Instance details

Defined in Control.Lens.Grammar.Pretty

Methods

empty :: Prettor w f a a0 #

(<|>) :: Prettor w f a a0 -> Prettor w f a a0 -> Prettor w f a a0 #

some :: Prettor w f a a0 -> Prettor w f a [a0] #

many :: Prettor w f a a0 -> Prettor w f a [a0] #

(Alternative m, Monad m) => Alternative (Parsor s m a) Source # 
Instance details

Defined in Data.Profunctor.Grammar

Methods

empty :: Parsor s m a a0 #

(<|>) :: Parsor s m a a0 -> Parsor s m a a0 -> Parsor s m a a0 #

some :: Parsor s m a a0 -> Parsor s m a [a0] #

many :: Parsor s m a a0 -> Parsor s m a [a0] #

Alternative f => Alternative (Printor s f a) Source # 
Instance details

Defined in Data.Profunctor.Grammar.Printor

Methods

empty :: Printor s f a a0 #

(<|>) :: Printor s f a a0 -> Printor s f a a0 -> Printor s f a a0 #

some :: Printor s f a a0 -> Printor s f a [a0] #

many :: Printor s f a a0 -> Printor s f a [a0] #

(Alternative f, Alternative g) => Alternative (f :*: g) #

Since: base-4.9.0.0

Instance details

Defined in GHC.Internal.Generics

Methods

empty :: (f :*: g) a #

(<|>) :: (f :*: g) a -> (f :*: g) a -> (f :*: g) a #

some :: (f :*: g) a -> (f :*: g) [a] #

many :: (f :*: g) a -> (f :*: g) [a] #

(Profunctor p, Alternative (p a), Applicative f) => Alternative (WrappedPafb f p a) # 
Instance details

Defined in Control.Lens.Internal.Distributor.Orphanage

Methods

empty :: WrappedPafb f p a a0 #

(<|>) :: WrappedPafb f p a a0 -> WrappedPafb f p a a0 -> WrappedPafb f p a a0 #

some :: WrappedPafb f p a a0 -> WrappedPafb f p a [a0] #

many :: WrappedPafb f p a a0 -> WrappedPafb f p a [a0] #

Alternative f => Alternative (Star f a) # 
Instance details

Defined in Data.Profunctor.Types

Methods

empty :: Star f a a0 #

(<|>) :: Star f a a0 -> Star f a a0 -> Star f a a0 #

some :: Star f a a0 -> Star f a [a0] #

many :: Star f a a0 -> Star f a [a0] #

(Alternative f, Applicative g) => Alternative (Compose f g) #

Since: base-4.9.0.0

Instance details

Defined in Data.Functor.Compose

Methods

empty :: Compose f g a #

(<|>) :: Compose f g a -> Compose f g a -> Compose f g a #

some :: Compose f g a -> Compose f g [a] #

many :: Compose f g a -> Compose f g [a] #

Alternative f => Alternative (Joker f a) # 
Instance details

Defined in Control.Lens.Internal.Distributor.Orphanage

Methods

empty :: Joker f a a0 #

(<|>) :: Joker f a a0 -> Joker f a a0 -> Joker f a a0 #

some :: Joker f a a0 -> Joker f a [a0] #

many :: Joker f a a0 -> Joker f a [a0] #

Monad m => Alternative (Varifocus a b m s) # 
Instance details

Defined in Control.Lens.Varifocal

Methods

empty :: Varifocus a b m s a0 #

(<|>) :: Varifocus a b m s a0 -> Varifocus a b m s a0 -> Varifocus a b m s a0 #

some :: Varifocus a b m s a0 -> Varifocus a b m s [a0] #

many :: Varifocus a b m s a0 -> Varifocus a b m s [a0] #

(Monoidal p, Alternative g) => Alternative (Zipporah p f g a) # 
Instance details

Defined in Data.Traversable.Homogeneous

Methods

empty :: Zipporah p f g a a0 #

(<|>) :: Zipporah p f g a a0 -> Zipporah p f g a a0 -> Zipporah p f g a a0 #

some :: Zipporah p f g a a0 -> Zipporah p f g a [a0] #

many :: Zipporah p f g a a0 -> Zipporah p f g a [a0] #

(Alternative f, Applicative g) => Alternative (f :.: g) #

Since: base-4.9.0.0

Instance details

Defined in GHC.Internal.Generics

Methods

empty :: (f :.: g) a #

(<|>) :: (f :.: g) a -> (f :.: g) a -> (f :.: g) a #

some :: (f :.: g) a -> (f :.: g) [a] #

many :: (f :.: g) a -> (f :.: g) [a] #

Alternative f => Alternative (M1 i c f) #

Since: base-4.9.0.0

Instance details

Defined in GHC.Internal.Generics

Methods

empty :: M1 i c f a #

(<|>) :: M1 i c f a -> M1 i c f a -> M1 i c f a #

some :: M1 i c f a -> M1 i c f [a] #

many :: M1 i c f a -> M1 i c f [a] #

(Functor m, MonadPlus m) => Alternative (RWST r w s m) # 
Instance details

Defined in Control.Monad.Trans.RWS.CPS

Methods

empty :: RWST r w s m a #

(<|>) :: RWST r w s m a -> RWST r w s m a -> RWST r w s m a #

some :: RWST r w s m a -> RWST r w s m [a] #

many :: RWST r w s m a -> RWST r w s m [a] #

(Monoid w, Functor m, MonadPlus m) => Alternative (RWST r w s m) # 
Instance details

Defined in Control.Monad.Trans.RWS.Lazy

Methods

empty :: RWST r w s m a #

(<|>) :: RWST r w s m a -> RWST r w s m a -> RWST r w s m a #

some :: RWST r w s m a -> RWST r w s m [a] #

many :: RWST r w s m a -> RWST r w s m [a] #

(Monoid w, Functor m, MonadPlus m) => Alternative (RWST r w s m) # 
Instance details

Defined in Control.Monad.Trans.RWS.Strict

Methods

empty :: RWST r w s m a #

(<|>) :: RWST r w s m a -> RWST r w s m a -> RWST r w s m a #

some :: RWST r w s m a -> RWST r w s m [a] #

many :: RWST r w s m a -> RWST r w s m [a] #

class (Alternative m, Monad m) => MonadPlus (m :: Type -> Type) where #

Monads that also support choice and failure.

Minimal complete definition

Nothing

Methods

mzero :: m a #

The identity of mplus. It should also satisfy the equations

mzero >>= f  =  mzero
v >> mzero   =  mzero

The default definition is

mzero = empty

mplus :: m a -> m a -> m a #

An associative operation. The default definition is

mplus = (<|>)

Instances

Instances details
MonadPlus Seq # 
Instance details

Defined in Data.Sequence.Internal

Methods

mzero :: Seq a #

mplus :: Seq a -> Seq a -> Seq a #

MonadPlus P #

Since: base-2.1

Instance details

Defined in GHC.Internal.Text.ParserCombinators.ReadP

Methods

mzero :: P a #

mplus :: P a -> P a -> P a #

MonadPlus ReadP #

Since: base-2.1

Instance details

Defined in GHC.Internal.Text.ParserCombinators.ReadP

Methods

mzero :: ReadP a #

mplus :: ReadP a -> ReadP a -> ReadP a #

MonadPlus ReadPrec #

Since: base-2.1

Instance details

Defined in GHC.Internal.Text.ParserCombinators.ReadPrec

Methods

mzero :: ReadPrec a #

mplus :: ReadPrec a -> ReadPrec a -> ReadPrec a #

MonadPlus IO #

Takes the first non-throwing IO action's result. mzero throws an exception.

Since: base-4.9.0.0

Instance details

Defined in GHC.Internal.Base

Methods

mzero :: IO a #

mplus :: IO a -> IO a -> IO a #

MonadPlus Deque # 
Instance details

Defined in Control.Lens.Internal.Deque

Methods

mzero :: Deque a #

mplus :: Deque a -> Deque a -> Deque a #

MonadPlus Array # 
Instance details

Defined in Data.Primitive.Array

Methods

mzero :: Array a #

mplus :: Array a -> Array a -> Array a #

MonadPlus SmallArray # 
Instance details

Defined in Data.Primitive.SmallArray

MonadPlus Vector # 
Instance details

Defined in Data.Vector

Methods

mzero :: Vector a #

mplus :: Vector a -> Vector a -> Vector a #

MonadPlus Vector # 
Instance details

Defined in Data.Vector.Strict

Methods

mzero :: Vector a #

mplus :: Vector a -> Vector a -> Vector a #

MonadPlus Maybe #

Picks the leftmost Just value, or, alternatively, Nothing.

Since: base-2.1

Instance details

Defined in GHC.Internal.Base

Methods

mzero :: Maybe a #

mplus :: Maybe a -> Maybe a -> Maybe a #

MonadPlus [] #

Combines lists by concatenation, starting from the empty list.

Since: base-2.1

Instance details

Defined in GHC.Internal.Base

Methods

mzero :: [a] #

mplus :: [a] -> [a] -> [a] #

MonadPlus v => MonadPlus (Free v) #

This violates the MonadPlus laws, handle with care.

Instance details

Defined in Control.Monad.Free

Methods

mzero :: Free v a #

mplus :: Free v a -> Free v a -> Free v a #

(ArrowApply a, ArrowPlus a) => MonadPlus (ArrowMonad a) #

Since: base-4.6.0.0

Instance details

Defined in GHC.Internal.Control.Arrow

Methods

mzero :: ArrowMonad a a0 #

mplus :: ArrowMonad a a0 -> ArrowMonad a a0 -> ArrowMonad a a0 #

MonadPlus (Proxy :: Type -> Type) #

Since: base-4.9.0.0

Instance details

Defined in GHC.Internal.Data.Proxy

Methods

mzero :: Proxy a #

mplus :: Proxy a -> Proxy a -> Proxy a #

MonadPlus (U1 :: Type -> Type) #

Since: base-4.9.0.0

Instance details

Defined in GHC.Internal.Generics

Methods

mzero :: U1 a #

mplus :: U1 a -> U1 a -> U1 a #

MonadPlus m => MonadPlus (Yoneda m) # 
Instance details

Defined in Data.Functor.Yoneda

Methods

mzero :: Yoneda m a #

mplus :: Yoneda m a -> Yoneda m a -> Yoneda m a #

MonadPlus (ReifiedFold s) # 
Instance details

Defined in Control.Lens.Reified

Methods

mzero :: ReifiedFold s a #

mplus :: ReifiedFold s a -> ReifiedFold s a -> ReifiedFold s a #

Monad m => MonadPlus (MaybeT m) # 
Instance details

Defined in Control.Monad.Trans.Maybe

Methods

mzero :: MaybeT m a #

mplus :: MaybeT m a -> MaybeT m a -> MaybeT m a #

MonadPlus (bi a) => MonadPlus (Biap bi a) # 
Instance details

Defined in Data.Bifunctor.Biap

Methods

mzero :: Biap bi a a0 #

mplus :: Biap bi a a0 -> Biap bi a a0 -> Biap bi a a0 #

Categorized (Item s) => MonadPlus (Parsector s a) Source # 
Instance details

Defined in Data.Profunctor.Grammar.Parsector

Methods

mzero :: Parsector s a a0 #

mplus :: Parsector s a a0 -> Parsector s a a0 -> Parsector s a a0 #

(Functor f, MonadPlus m) => MonadPlus (FreeT f m) # 
Instance details

Defined in Control.Monad.Trans.Free

Methods

mzero :: FreeT f m a #

mplus :: FreeT f m a -> FreeT f m a -> FreeT f m a #

MonadPlus m => MonadPlus (Kleisli m a) #

Since: base-4.14.0.0

Instance details

Defined in GHC.Internal.Control.Arrow

Methods

mzero :: Kleisli m a a0 #

mplus :: Kleisli m a a0 -> Kleisli m a a0 -> Kleisli m a a0 #

MonadPlus f => MonadPlus (Ap f) #

Since: base-4.12.0.0

Instance details

Defined in GHC.Internal.Data.Monoid

Methods

mzero :: Ap f a #

mplus :: Ap f a -> Ap f a -> Ap f a #

MonadPlus f => MonadPlus (Alt f) #

Since: base-4.8.0.0

Instance details

Defined in GHC.Internal.Data.Semigroup.Internal

Methods

mzero :: Alt f a #

mplus :: Alt f a -> Alt f a -> Alt f a #

MonadPlus f => MonadPlus (Rec1 f) #

Since: base-4.9.0.0

Instance details

Defined in GHC.Internal.Generics

Methods

mzero :: Rec1 f a #

mplus :: Rec1 f a -> Rec1 f a -> Rec1 f a #

(Monoid w, Functor m, MonadPlus m) => MonadPlus (AccumT w m) # 
Instance details

Defined in Control.Monad.Trans.Accum

Methods

mzero :: AccumT w m a #

mplus :: AccumT w m a -> AccumT w m a -> AccumT w m a #

(Monad m, Monoid e) => MonadPlus (ExceptT e m) # 
Instance details

Defined in Control.Monad.Trans.Except

Methods

mzero :: ExceptT e m a #

mplus :: ExceptT e m a -> ExceptT e m a -> ExceptT e m a #

MonadPlus m => MonadPlus (IdentityT m) # 
Instance details

Defined in Control.Monad.Trans.Identity

Methods

mzero :: IdentityT m a #

mplus :: IdentityT m a -> IdentityT m a -> IdentityT m a #

MonadPlus m => MonadPlus (ReaderT r m) # 
Instance details

Defined in Control.Monad.Trans.Reader

Methods

mzero :: ReaderT r m a #

mplus :: ReaderT r m a -> ReaderT r m a -> ReaderT r m a #

MonadPlus m => MonadPlus (SelectT r m) # 
Instance details

Defined in Control.Monad.Trans.Select

Methods

mzero :: SelectT r m a #

mplus :: SelectT r m a -> SelectT r m a -> SelectT r m a #

MonadPlus m => MonadPlus (StateT s m) # 
Instance details

Defined in Control.Monad.Trans.State.Lazy

Methods

mzero :: StateT s m a #

mplus :: StateT s m a -> StateT s m a -> StateT s m a #

MonadPlus m => MonadPlus (StateT s m) # 
Instance details

Defined in Control.Monad.Trans.State.Strict

Methods

mzero :: StateT s m a #

mplus :: StateT s m a -> StateT s m a -> StateT s m a #

(Functor m, MonadPlus m) => MonadPlus (WriterT w m) # 
Instance details

Defined in Control.Monad.Trans.Writer.CPS

Methods

mzero :: WriterT w m a #

mplus :: WriterT w m a -> WriterT w m a -> WriterT w m a #

(Monoid w, MonadPlus m) => MonadPlus (WriterT w m) # 
Instance details

Defined in Control.Monad.Trans.Writer.Lazy

Methods

mzero :: WriterT w m a #

mplus :: WriterT w m a -> WriterT w m a -> WriterT w m a #

(Monoid w, MonadPlus m) => MonadPlus (WriterT w m) # 
Instance details

Defined in Control.Monad.Trans.Writer.Strict

Methods

mzero :: WriterT w m a #

mplus :: WriterT w m a -> WriterT w m a -> WriterT w m a #

MonadPlus m => MonadPlus (Reverse m) #

Derived instance.

Instance details

Defined in Data.Functor.Reverse

Methods

mzero :: Reverse m a #

mplus :: Reverse m a -> Reverse m a -> Reverse m a #

(MonadPlus f, MonadPlus g) => MonadPlus (Product f g) #

Since: base-4.9.0.0

Instance details

Defined in Data.Functor.Product

Methods

mzero :: Product f g a #

mplus :: Product f g a -> Product f g a -> Product f g a #

(Alternative m, Monad m) => MonadPlus (Parsor s m a) Source # 
Instance details

Defined in Data.Profunctor.Grammar

Methods

mzero :: Parsor s m a a0 #

mplus :: Parsor s m a a0 -> Parsor s m a a0 -> Parsor s m a a0 #

(Alternative f, Monad f) => MonadPlus (Printor s f a) Source # 
Instance details

Defined in Data.Profunctor.Grammar.Printor

Methods

mzero :: Printor s f a a0 #

mplus :: Printor s f a a0 -> Printor s f a a0 -> Printor s f a a0 #

(MonadPlus f, MonadPlus g) => MonadPlus (f :*: g) #

Since: base-4.9.0.0

Instance details

Defined in GHC.Internal.Generics

Methods

mzero :: (f :*: g) a #

mplus :: (f :*: g) a -> (f :*: g) a -> (f :*: g) a #

MonadPlus f => MonadPlus (Star f a) # 
Instance details

Defined in Data.Profunctor.Types

Methods

mzero :: Star f a a0 #

mplus :: Star f a a0 -> Star f a a0 -> Star f a a0 #

MonadPlus m => MonadPlus (Joker m a) # 
Instance details

Defined in Control.Lens.Internal.Distributor.Orphanage

Methods

mzero :: Joker m a a0 #

mplus :: Joker m a a0 -> Joker m a a0 -> Joker m a a0 #

MonadPlus f => MonadPlus (M1 i c f) #

Since: base-4.9.0.0

Instance details

Defined in GHC.Internal.Generics

Methods

mzero :: M1 i c f a #

mplus :: M1 i c f a -> M1 i c f a -> M1 i c f a #

(Functor m, MonadPlus m) => MonadPlus (RWST r w s m) # 
Instance details

Defined in Control.Monad.Trans.RWS.CPS

Methods

mzero :: RWST r w s m a #

mplus :: RWST r w s m a -> RWST r w s m a -> RWST r w s m a #

(Monoid w, MonadPlus m) => MonadPlus (RWST r w s m) # 
Instance details

Defined in Control.Monad.Trans.RWS.Lazy

Methods

mzero :: RWST r w s m a #

mplus :: RWST r w s m a -> RWST r w s m a -> RWST r w s m a #

(Monoid w, MonadPlus m) => MonadPlus (RWST r w s m) # 
Instance details

Defined in Control.Monad.Trans.RWS.Strict

Methods

mzero :: RWST r w s m a #

mplus :: RWST r w s m a -> RWST r w s m a -> RWST r w s m a #

class Monad m => MonadFail (m :: Type -> Type) where #

When a value is bound in do-notation, the pattern on the left hand side of <- might not match. In this case, this class provides a function to recover.

A Monad without a MonadFail instance may only be used in conjunction with pattern that always match, such as newtypes, tuples, data types with only a single data constructor, and irrefutable patterns (~pat).

Instances of MonadFail should satisfy the following law: fail s should be a left zero for >>=,

fail s >>= f  =  fail s

If your Monad is also MonadPlus, a popular definition is

fail _ = mzero

fail s should be an action that runs in the monad itself, not an exception (except in instances of MonadIO). In particular, fail should not be implemented in terms of error.

Since: base-4.9.0.0

Methods

fail :: String -> m a #

Instances

Instances details
MonadFail Q # 
Instance details

Defined in GHC.Internal.TH.Syntax

Methods

fail :: String -> Q a #

MonadFail P #

Since: base-4.9.0.0

Instance details

Defined in GHC.Internal.Text.ParserCombinators.ReadP

Methods

fail :: String -> P a #

MonadFail ReadP #

Since: base-4.9.0.0

Instance details

Defined in GHC.Internal.Text.ParserCombinators.ReadP

Methods

fail :: String -> ReadP a #

MonadFail ReadPrec #

Since: base-4.9.0.0

Instance details

Defined in GHC.Internal.Text.ParserCombinators.ReadPrec

Methods

fail :: String -> ReadPrec a #

MonadFail IO #

Since: base-4.9.0.0

Instance details

Defined in GHC.Internal.Control.Monad.Fail

Methods

fail :: String -> IO a #

MonadFail Array # 
Instance details

Defined in Data.Primitive.Array

Methods

fail :: String -> Array a #

MonadFail SmallArray # 
Instance details

Defined in Data.Primitive.SmallArray

Methods

fail :: String -> SmallArray a #

MonadFail Vector #

Since: vector-0.12.1.0

Instance details

Defined in Data.Vector

Methods

fail :: String -> Vector a #

MonadFail Vector #

Since: vector-0.13.2.0

Instance details

Defined in Data.Vector.Strict

Methods

fail :: String -> Vector a #

MonadFail Maybe #

Since: base-4.9.0.0

Instance details

Defined in GHC.Internal.Control.Monad.Fail

Methods

fail :: String -> Maybe a #

MonadFail [] #

Since: base-4.9.0.0

Instance details

Defined in GHC.Internal.Control.Monad.Fail

Methods

fail :: String -> [a] #

Monad m => MonadFail (PropertyM m) # 
Instance details

Defined in Test.QuickCheck.Monadic

Methods

fail :: String -> PropertyM m a #

MonadFail (UniqueParser s) # 
Instance details

Defined in Prettyprinter.Render.Util.SimpleDocTree

Methods

fail :: String -> UniqueParser s a #

Monad m => MonadFail (MaybeT m) # 
Instance details

Defined in Control.Monad.Trans.Maybe

Methods

fail :: String -> MaybeT m a #

MonadFail (bi a) => MonadFail (Biap bi a) # 
Instance details

Defined in Data.Bifunctor.Biap

Methods

fail :: String -> Biap bi a a0 #

Categorized (Item s) => MonadFail (Parsector s a) Source # 
Instance details

Defined in Data.Profunctor.Grammar.Parsector

Methods

fail :: String -> Parsector s a a0 #

(Functor f, MonadFail m) => MonadFail (FreeT f m) # 
Instance details

Defined in Control.Monad.Trans.Free

Methods

fail :: String -> FreeT f m a #

MonadFail f => MonadFail (Ap f) #

Since: base-4.12.0.0

Instance details

Defined in GHC.Internal.Data.Monoid

Methods

fail :: String -> Ap f a #

(Monoid w, MonadFail m) => MonadFail (AccumT w m) # 
Instance details

Defined in Control.Monad.Trans.Accum

Methods

fail :: String -> AccumT w m a #

MonadFail m => MonadFail (ExceptT e m) # 
Instance details

Defined in Control.Monad.Trans.Except

Methods

fail :: String -> ExceptT e m a #

MonadFail m => MonadFail (IdentityT m) # 
Instance details

Defined in Control.Monad.Trans.Identity

Methods

fail :: String -> IdentityT m a #

MonadFail m => MonadFail (ReaderT r m) # 
Instance details

Defined in Control.Monad.Trans.Reader

Methods

fail :: String -> ReaderT r m a #

MonadFail m => MonadFail (SelectT r m) # 
Instance details

Defined in Control.Monad.Trans.Select

Methods

fail :: String -> SelectT r m a #

MonadFail m => MonadFail (StateT s m) # 
Instance details

Defined in Control.Monad.Trans.State.Lazy

Methods

fail :: String -> StateT s m a #

MonadFail m => MonadFail (StateT s m) # 
Instance details

Defined in Control.Monad.Trans.State.Strict

Methods

fail :: String -> StateT s m a #

MonadFail m => MonadFail (WriterT w m) # 
Instance details

Defined in Control.Monad.Trans.Writer.CPS

Methods

fail :: String -> WriterT w m a #

(Monoid w, MonadFail m) => MonadFail (WriterT w m) # 
Instance details

Defined in Control.Monad.Trans.Writer.Lazy

Methods

fail :: String -> WriterT w m a #

(Monoid w, MonadFail m) => MonadFail (WriterT w m) # 
Instance details

Defined in Control.Monad.Trans.Writer.Strict

Methods

fail :: String -> WriterT w m a #

MonadFail m => MonadFail (Reverse m) # 
Instance details

Defined in Data.Functor.Reverse

Methods

fail :: String -> Reverse m a #

(Alternative m, Monad m) => MonadFail (Parsor s m a) Source # 
Instance details

Defined in Data.Profunctor.Grammar

Methods

fail :: String -> Parsor s m a a0 #

(Alternative m, Monad m) => MonadFail (Printor s m a) Source # 
Instance details

Defined in Data.Profunctor.Grammar.Printor

Methods

fail :: String -> Printor s m a a0 #

MonadFail m => MonadFail (ContT r m) # 
Instance details

Defined in Control.Monad.Trans.Cont

Methods

fail :: String -> ContT r m a #

MonadFail m => MonadFail (Joker m a) # 
Instance details

Defined in Control.Lens.Internal.Distributor.Orphanage

Methods

fail :: String -> Joker m a a0 #

MonadFail m => MonadFail (RWST r w s m) # 
Instance details

Defined in Control.Monad.Trans.RWS.CPS

Methods

fail :: String -> RWST r w s m a #

(Monoid w, MonadFail m) => MonadFail (RWST r w s m) # 
Instance details

Defined in Control.Monad.Trans.RWS.Lazy

Methods

fail :: String -> RWST r w s m a #

(Monoid w, MonadFail m) => MonadFail (RWST r w s m) # 
Instance details

Defined in Control.Monad.Trans.RWS.Strict

Methods

fail :: String -> RWST r w s m a #

class Functor f => Filterable (f :: Type -> Type) where #

Like Functor, but you can remove elements instead of updating them.

Formally, the class Filterable represents a functor from Kleisli Maybe to Hask.

A definition of mapMaybe must satisfy the following laws:

conservation
mapMaybe (Just . f) ≡ fmap f
composition
mapMaybe f . mapMaybe g ≡ mapMaybe (f <=< g)

Minimal complete definition

mapMaybe | catMaybes

Methods

mapMaybe :: (a -> Maybe b) -> f a -> f b #

Like mapMaybe.

catMaybes :: f (Maybe a) -> f a #

filter :: (a -> Bool) -> f a -> f a #

filter f . filter g ≡ filter (liftA2 (&&) g f)

drain :: f a -> f b #

Empty a filterable.

drain ≡ mapMaybe (const Nothing)

Instances

Instances details
Filterable IntMap # 
Instance details

Defined in Witherable

Methods

mapMaybe :: (a -> Maybe b) -> IntMap a -> IntMap b #

catMaybes :: IntMap (Maybe a) -> IntMap a #

filter :: (a -> Bool) -> IntMap a -> IntMap a #

drain :: IntMap a -> IntMap b #

Filterable Seq # 
Instance details

Defined in Witherable

Methods

mapMaybe :: (a -> Maybe b) -> Seq a -> Seq b #

catMaybes :: Seq (Maybe a) -> Seq a #

filter :: (a -> Bool) -> Seq a -> Seq a #

drain :: Seq a -> Seq b #

Filterable ZipList # 
Instance details

Defined in Witherable

Methods

mapMaybe :: (a -> Maybe b) -> ZipList a -> ZipList b #

catMaybes :: ZipList (Maybe a) -> ZipList a #

filter :: (a -> Bool) -> ZipList a -> ZipList a #

drain :: ZipList a -> ZipList b #

Filterable ReadP # 
Instance details

Defined in Control.Lens.Internal.Distributor.Orphanage

Methods

mapMaybe :: (a -> Maybe b) -> ReadP a -> ReadP b #

catMaybes :: ReadP (Maybe a) -> ReadP a #

filter :: (a -> Bool) -> ReadP a -> ReadP a #

drain :: ReadP a -> ReadP b #

Filterable ReadPrec # 
Instance details

Defined in Control.Lens.Internal.Distributor.Orphanage

Methods

mapMaybe :: (a -> Maybe b) -> ReadPrec a -> ReadPrec b #

catMaybes :: ReadPrec (Maybe a) -> ReadPrec a #

filter :: (a -> Bool) -> ReadPrec a -> ReadPrec a #

drain :: ReadPrec a -> ReadPrec b #

Filterable Vector # 
Instance details

Defined in Witherable

Methods

mapMaybe :: (a -> Maybe b) -> Vector a -> Vector b #

catMaybes :: Vector (Maybe a) -> Vector a #

filter :: (a -> Bool) -> Vector a -> Vector a #

drain :: Vector a -> Vector b #

Filterable Maybe # 
Instance details

Defined in Witherable

Methods

mapMaybe :: (a -> Maybe b) -> Maybe a -> Maybe b #

catMaybes :: Maybe (Maybe a) -> Maybe a #

filter :: (a -> Bool) -> Maybe a -> Maybe a #

drain :: Maybe a -> Maybe b #

Filterable [] # 
Instance details

Defined in Witherable

Methods

mapMaybe :: (a -> Maybe b) -> [a] -> [b] #

catMaybes :: [Maybe a] -> [a] #

filter :: (a -> Bool) -> [a] -> [a] #

drain :: [a] -> [b] #

Filterable (Map k) # 
Instance details

Defined in Witherable

Methods

mapMaybe :: (a -> Maybe b) -> Map k a -> Map k b #

catMaybes :: Map k (Maybe a) -> Map k a #

filter :: (a -> Bool) -> Map k a -> Map k a #

drain :: Map k a -> Map k b #

Monoid e => Filterable (Either e) # 
Instance details

Defined in Witherable

Methods

mapMaybe :: (a -> Maybe b) -> Either e a -> Either e b #

catMaybes :: Either e (Maybe a) -> Either e a #

filter :: (a -> Bool) -> Either e a -> Either e a #

drain :: Either e a -> Either e b #

Filterable (Proxy :: Type -> Type) # 
Instance details

Defined in Witherable

Methods

mapMaybe :: (a -> Maybe b) -> Proxy a -> Proxy b #

catMaybes :: Proxy (Maybe a) -> Proxy a #

filter :: (a -> Bool) -> Proxy a -> Proxy a #

drain :: Proxy a -> Proxy b #

Filterable (U1 :: Type -> Type) # 
Instance details

Defined in Witherable

Methods

mapMaybe :: (a -> Maybe b) -> U1 a -> U1 b #

catMaybes :: U1 (Maybe a) -> U1 a #

filter :: (a -> Bool) -> U1 a -> U1 a #

drain :: U1 a -> U1 b #

Filterable (V1 :: Type -> Type) # 
Instance details

Defined in Witherable

Methods

mapMaybe :: (a -> Maybe b) -> V1 a -> V1 b #

catMaybes :: V1 (Maybe a) -> V1 a #

filter :: (a -> Bool) -> V1 a -> V1 a #

drain :: V1 a -> V1 b #

Functor f => Filterable (MaybeT f) # 
Instance details

Defined in Witherable

Methods

mapMaybe :: (a -> Maybe b) -> MaybeT f a -> MaybeT f b #

catMaybes :: MaybeT f (Maybe a) -> MaybeT f a #

filter :: (a -> Bool) -> MaybeT f a -> MaybeT f a #

drain :: MaybeT f a -> MaybeT f b #

(Eq k, Hashable k) => Filterable (HashMap k) # 
Instance details

Defined in Witherable

Methods

mapMaybe :: (a -> Maybe b) -> HashMap k a -> HashMap k b #

catMaybes :: HashMap k (Maybe a) -> HashMap k a #

filter :: (a -> Bool) -> HashMap k a -> HashMap k a #

drain :: HashMap k a -> HashMap k b #

(Foldable f, Alternative f) => Filterable (WrappedFoldable f) # 
Instance details

Defined in Witherable

Categorized (Item s) => Filterable (Parsector s a) Source # 
Instance details

Defined in Data.Profunctor.Grammar.Parsector

Methods

mapMaybe :: (a0 -> Maybe b) -> Parsector s a a0 -> Parsector s a b #

catMaybes :: Parsector s a (Maybe a0) -> Parsector s a a0 #

filter :: (a0 -> Bool) -> Parsector s a a0 -> Parsector s a a0 #

drain :: Parsector s a a0 -> Parsector s a b #

Filterable (Const r :: Type -> Type) # 
Instance details

Defined in Witherable

Methods

mapMaybe :: (a -> Maybe b) -> Const r a -> Const r b #

catMaybes :: Const r (Maybe a) -> Const r a #

filter :: (a -> Bool) -> Const r a -> Const r a #

drain :: Const r a -> Const r b #

Filterable f => Filterable (Rec1 f) # 
Instance details

Defined in Witherable

Methods

mapMaybe :: (a -> Maybe b) -> Rec1 f a -> Rec1 f b #

catMaybes :: Rec1 f (Maybe a) -> Rec1 f a #

filter :: (a -> Bool) -> Rec1 f a -> Rec1 f a #

drain :: Rec1 f a -> Rec1 f b #

(Profunctor p, Filterable (p a)) => Filterable (Coyoneda p a) # 
Instance details

Defined in Control.Lens.Internal.Distributor.Orphanage

Methods

mapMaybe :: (a0 -> Maybe b) -> Coyoneda p a a0 -> Coyoneda p a b #

catMaybes :: Coyoneda p a (Maybe a0) -> Coyoneda p a a0 #

filter :: (a0 -> Bool) -> Coyoneda p a a0 -> Coyoneda p a a0 #

drain :: Coyoneda p a a0 -> Coyoneda p a b #

(Profunctor p, Filterable (p a)) => Filterable (Yoneda p a) # 
Instance details

Defined in Control.Lens.Internal.Distributor.Orphanage

Methods

mapMaybe :: (a0 -> Maybe b) -> Yoneda p a a0 -> Yoneda p a b #

catMaybes :: Yoneda p a (Maybe a0) -> Yoneda p a a0 #

filter :: (a0 -> Bool) -> Yoneda p a a0 -> Yoneda p a a0 #

drain :: Yoneda p a a0 -> Yoneda p a b #

Filterable t => Filterable (Backwards t) # 
Instance details

Defined in Witherable

Methods

mapMaybe :: (a -> Maybe b) -> Backwards t a -> Backwards t b #

catMaybes :: Backwards t (Maybe a) -> Backwards t a #

filter :: (a -> Bool) -> Backwards t a -> Backwards t a #

drain :: Backwards t a -> Backwards t b #

Filterable f => Filterable (IdentityT f) # 
Instance details

Defined in Witherable

Methods

mapMaybe :: (a -> Maybe b) -> IdentityT f a -> IdentityT f b #

catMaybes :: IdentityT f (Maybe a) -> IdentityT f a #

filter :: (a -> Bool) -> IdentityT f a -> IdentityT f a #

drain :: IdentityT f a -> IdentityT f b #

Filterable t => Filterable (Reverse t) # 
Instance details

Defined in Witherable

Methods

mapMaybe :: (a -> Maybe b) -> Reverse t a -> Reverse t b #

catMaybes :: Reverse t (Maybe a) -> Reverse t a #

filter :: (a -> Bool) -> Reverse t a -> Reverse t a #

drain :: Reverse t a -> Reverse t b #

(Filterable f, Filterable g) => Filterable (Product f g) # 
Instance details

Defined in Witherable

Methods

mapMaybe :: (a -> Maybe b) -> Product f g a -> Product f g b #

catMaybes :: Product f g (Maybe a) -> Product f g a #

filter :: (a -> Bool) -> Product f g a -> Product f g a #

drain :: Product f g a -> Product f g b #

(Filterable f, Filterable g) => Filterable (Sum f g) # 
Instance details

Defined in Witherable

Methods

mapMaybe :: (a -> Maybe b) -> Sum f g a -> Sum f g b #

catMaybes :: Sum f g (Maybe a) -> Sum f g a #

filter :: (a -> Bool) -> Sum f g a -> Sum f g a #

drain :: Sum f g a -> Sum f g b #

Filterable (Binocular a b s) # 
Instance details

Defined in Control.Lens.Bifocal

Methods

mapMaybe :: (a0 -> Maybe b0) -> Binocular a b s a0 -> Binocular a b s b0 #

catMaybes :: Binocular a b s (Maybe a0) -> Binocular a b s a0 #

filter :: (a0 -> Bool) -> Binocular a b s a0 -> Binocular a b s a0 #

drain :: Binocular a b s a0 -> Binocular a b s b0 #

Filterable (Spectacle a b s) # 
Instance details

Defined in Control.Lens.Bifocal

Methods

mapMaybe :: (a0 -> Maybe b0) -> Spectacle a b s a0 -> Spectacle a b s b0 #

catMaybes :: Spectacle a b s (Maybe a0) -> Spectacle a b s a0 #

filter :: (a0 -> Bool) -> Spectacle a b s a0 -> Spectacle a b s a0 #

drain :: Spectacle a b s a0 -> Spectacle a b s b0 #

Filterable (PartialMarket a b s) # 
Instance details

Defined in Control.Lens.PartialIso

Methods

mapMaybe :: (a0 -> Maybe b0) -> PartialMarket a b s a0 -> PartialMarket a b s b0 #

catMaybes :: PartialMarket a b s (Maybe a0) -> PartialMarket a b s a0 #

filter :: (a0 -> Bool) -> PartialMarket a b s a0 -> PartialMarket a b s a0 #

drain :: PartialMarket a b s a0 -> PartialMarket a b s b0 #

Filterable f => Filterable (Parsor s f a) Source # 
Instance details

Defined in Data.Profunctor.Grammar

Methods

mapMaybe :: (a0 -> Maybe b) -> Parsor s f a a0 -> Parsor s f a b #

catMaybes :: Parsor s f a (Maybe a0) -> Parsor s f a a0 #

filter :: (a0 -> Bool) -> Parsor s f a a0 -> Parsor s f a a0 #

drain :: Parsor s f a a0 -> Parsor s f a b #

Filterable f => Filterable (Printor s f a) Source # 
Instance details

Defined in Data.Profunctor.Grammar.Printor

Methods

mapMaybe :: (a0 -> Maybe b) -> Printor s f a a0 -> Printor s f a b #

catMaybes :: Printor s f a (Maybe a0) -> Printor s f a a0 #

filter :: (a0 -> Bool) -> Printor s f a a0 -> Printor s f a a0 #

drain :: Printor s f a a0 -> Printor s f a b #

(Filterable f, Filterable g) => Filterable (f :*: g) # 
Instance details

Defined in Witherable

Methods

mapMaybe :: (a -> Maybe b) -> (f :*: g) a -> (f :*: g) b #

catMaybes :: (f :*: g) (Maybe a) -> (f :*: g) a #

filter :: (a -> Bool) -> (f :*: g) a -> (f :*: g) a #

drain :: (f :*: g) a -> (f :*: g) b #

(Filterable f, Filterable g) => Filterable (f :+: g) # 
Instance details

Defined in Witherable

Methods

mapMaybe :: (a -> Maybe b) -> (f :+: g) a -> (f :+: g) b #

catMaybes :: (f :+: g) (Maybe a) -> (f :+: g) a #

filter :: (a -> Bool) -> (f :+: g) a -> (f :+: g) a #

drain :: (f :+: g) a -> (f :+: g) b #

Filterable (K1 i c :: Type -> Type) # 
Instance details

Defined in Witherable

Methods

mapMaybe :: (a -> Maybe b) -> K1 i c a -> K1 i c b #

catMaybes :: K1 i c (Maybe a) -> K1 i c a #

filter :: (a -> Bool) -> K1 i c a -> K1 i c a #

drain :: K1 i c a -> K1 i c b #

(Profunctor p, Functor (p a), Filterable f) => Filterable (WrappedPafb f p a) # 
Instance details

Defined in Control.Lens.Internal.Distributor.Orphanage

Methods

mapMaybe :: (a0 -> Maybe b) -> WrappedPafb f p a a0 -> WrappedPafb f p a b #

catMaybes :: WrappedPafb f p a (Maybe a0) -> WrappedPafb f p a a0 #

filter :: (a0 -> Bool) -> WrappedPafb f p a a0 -> WrappedPafb f p a a0 #

drain :: WrappedPafb f p a a0 -> WrappedPafb f p a b #

Filterable (Forget r a :: Type -> Type) # 
Instance details

Defined in Control.Lens.Internal.Distributor.Orphanage

Methods

mapMaybe :: (a0 -> Maybe b) -> Forget r a a0 -> Forget r a b #

catMaybes :: Forget r a (Maybe a0) -> Forget r a a0 #

filter :: (a0 -> Bool) -> Forget r a a0 -> Forget r a a0 #

drain :: Forget r a a0 -> Forget r a b #

Filterable f => Filterable (Star f a) # 
Instance details

Defined in Control.Lens.Internal.Distributor.Orphanage

Methods

mapMaybe :: (a0 -> Maybe b) -> Star f a a0 -> Star f a b #

catMaybes :: Star f a (Maybe a0) -> Star f a a0 #

filter :: (a0 -> Bool) -> Star f a a0 -> Star f a a0 #

drain :: Star f a a0 -> Star f a b #

(Functor f, Filterable g) => Filterable (Compose f g) # 
Instance details

Defined in Witherable

Methods

mapMaybe :: (a -> Maybe b) -> Compose f g a -> Compose f g b #

catMaybes :: Compose f g (Maybe a) -> Compose f g a #

filter :: (a -> Bool) -> Compose f g a -> Compose f g a #

drain :: Compose f g a -> Compose f g b #

Filterable f => Filterable (Joker f a) # 
Instance details

Defined in Control.Lens.Internal.Distributor.Orphanage

Methods

mapMaybe :: (a0 -> Maybe b) -> Joker f a a0 -> Joker f a b #

catMaybes :: Joker f a (Maybe a0) -> Joker f a a0 #

filter :: (a0 -> Bool) -> Joker f a a0 -> Joker f a a0 #

drain :: Joker f a a0 -> Joker f a b #

Monad m => Filterable (Varifocus a b m s) # 
Instance details

Defined in Control.Lens.Varifocal

Methods

mapMaybe :: (a0 -> Maybe b0) -> Varifocus a b m s a0 -> Varifocus a b m s b0 #

catMaybes :: Varifocus a b m s (Maybe a0) -> Varifocus a b m s a0 #

filter :: (a0 -> Bool) -> Varifocus a b m s a0 -> Varifocus a b m s a0 #

drain :: Varifocus a b m s a0 -> Varifocus a b m s b0 #

(Profunctor p, Filterable g) => Filterable (Zipporah p f g a) # 
Instance details

Defined in Data.Traversable.Homogeneous

Methods

mapMaybe :: (a0 -> Maybe b) -> Zipporah p f g a a0 -> Zipporah p f g a b #

catMaybes :: Zipporah p f g a (Maybe a0) -> Zipporah p f g a a0 #

filter :: (a0 -> Bool) -> Zipporah p f g a a0 -> Zipporah p f g a a0 #

drain :: Zipporah p f g a a0 -> Zipporah p f g a b #

(Functor f, Filterable g) => Filterable (f :.: g) # 
Instance details

Defined in Witherable

Methods

mapMaybe :: (a -> Maybe b) -> (f :.: g) a -> (f :.: g) b #

catMaybes :: (f :.: g) (Maybe a) -> (f :.: g) a #

filter :: (a -> Bool) -> (f :.: g) a -> (f :.: g) a #

drain :: (f :.: g) a -> (f :.: g) b #

Filterable f => Filterable (M1 i c f) # 
Instance details

Defined in Witherable

Methods

mapMaybe :: (a -> Maybe b) -> M1 i c f a -> M1 i c f b #

catMaybes :: M1 i c f (Maybe a) -> M1 i c f a #

filter :: (a -> Bool) -> M1 i c f a -> M1 i c f a #

drain :: M1 i c f a -> M1 i c f b #