Copyright | (c) Matthew Sackman Ivan Lazar Miljenovic |
---|---|
License | 3-Clause BSD-style |
Maintainer | Ivan.Miljenovic@gmail.com |
Safe Haskell | Safe |
Language | Haskell2010 |
This module defines simple helper functions for use with Text.ParserCombinators.Poly.Lazy.
Note that the ParseDot
instances for Bool
, etc. match those
specified for use with Graphviz (e.g. non-zero integers are
equivalent to True
).
You should not be using this module; rather, it is here for
informative/documentative reasons. If you want to parse a
, you should use
DotRepr
rather than its parseDotGraph
ParseDot
instance.
Synopsis
- (<$) :: Functor f => a -> f b -> f a
- class Functor f => Applicative (f :: Type -> Type) where
- optional :: Alternative f => f a -> f (Maybe a)
- newtype WrappedMonad (m :: Type -> Type) a = WrapMonad {
- unwrapMonad :: m a
- newtype WrappedArrow (a :: Type -> Type -> Type) b c = WrapArrow {
- unwrapArrow :: a b c
- newtype ZipList a = ZipList {
- getZipList :: [a]
- newtype Const a (b :: k) :: forall k. Type -> k -> Type = Const {
- getConst :: a
- (<$>) :: Functor f => (a -> b) -> f a -> f b
- liftA3 :: Applicative f => (a -> b -> c -> d) -> f a -> f b -> f c -> f d
- liftA :: Applicative f => (a -> b) -> f a -> f b
- (<**>) :: Applicative f => f a -> f (a -> b) -> f b
- class Applicative f => Alternative (f :: Type -> Type) where
- reparse :: Text -> Parser s ()
- stGet :: Parser s s
- stQuery :: (s -> a) -> Parser s a
- stUpdate :: (s -> s) -> Parser s ()
- many1Satisfy :: (Char -> Bool) -> Parser s Text
- manySatisfy :: (Char -> Bool) -> Parser s Text
- onFail :: Parser s a -> Parser s a -> Parser s a
- satisfy :: (Char -> Bool) -> Parser s Char
- eof :: Parser s ()
- next :: Parser s Char
- newtype Parser s a = P (s -> Text -> Result (Text, s) a)
- data Result z a
- manyFinally' :: (PolyParse p, Show a) => p a -> p z -> p [a]
- manyFinally :: PolyParse p => p a -> p z -> p [a]
- bracket :: PolyParse p => p bra -> p ket -> p a -> p a
- bracketSep :: PolyParse p => p bra -> p sep -> p ket -> p a -> p [a]
- sepBy1 :: PolyParse p => p a -> p sep -> p [a]
- sepBy :: PolyParse p => p a -> p sep -> p [a]
- many1 :: PolyParse p => p a -> p [a]
- upto :: PolyParse p => Int -> p a -> p [a]
- exactly :: PolyParse p => Int -> p a -> p [a]
- oneOf :: PolyParse p => [p a] -> p a
- adjustErrBad :: PolyParse p => p a -> (String -> String) -> p a
- failBad :: PolyParse p => String -> p a
- discard :: PolyParse p => p a -> p b -> p a
- apply :: PolyParse p => p (a -> b) -> p a -> p b
- class Commitment (p :: Type -> Type) where
- class (Functor p, Monad p, MonadFail p, Applicative p, Alternative p, Commitment p) => PolyParse (p :: Type -> Type)
- type Parse a = Parser GraphvizState a
- class ParseDot a where
- parseIt :: ParseDot a => Text -> (a, Text)
- parseIt' :: ParseDot a => Text -> a
- runParser :: Parse a -> Text -> (Either String a, Text)
- runParser' :: Parse a -> Text -> a
- runParserWith :: (GraphvizState -> GraphvizState) -> Parse a -> Text -> (Either String a, Text)
- parseLiberally :: GraphvizState -> GraphvizState
- checkValidParse :: Either String a -> a
- checkValidParseWithRest :: (Either String a, Text) -> a
- ignoreSep :: (a -> b -> c) -> Parse a -> Parse sep -> Parse b -> Parse c
- onlyBool :: Parse Bool
- quotelessString :: Parse Text
- stringBlock :: Parse Text
- numString :: Bool -> Parse Text
- isNumString :: Bool -> Text -> Bool
- isIntString :: Text -> Bool
- quotedString :: Parse Text
- parseEscaped :: Bool -> [Char] -> [Char] -> Parse Text
- parseAndSpace :: Parse a -> Parse a
- string :: String -> Parse ()
- strings :: [String] -> Parse ()
- character :: Char -> Parse Char
- parseStrictFloat :: Bool -> Parse Double
- parseSignedFloat :: Bool -> Parse Double
- noneOf :: [Char] -> Parse Char
- whitespace1 :: Parse ()
- whitespace :: Parse ()
- wrapWhitespace :: Parse a -> Parse a
- optionalQuotedString :: String -> Parse ()
- optionalQuoted :: Parse a -> Parse a
- quotedParse :: Parse a -> Parse a
- orQuote :: Parse Char -> Parse Char
- quoteChar :: Char
- newline :: Parse ()
- newline' :: Parse ()
- parseComma :: Parse ()
- parseEq :: Parse ()
- tryParseList :: ParseDot a => Parse [a]
- tryParseList' :: Parse [a] -> Parse [a]
- consumeLine :: Parse Text
- commaSep :: (ParseDot a, ParseDot b) => Parse (a, b)
- commaSepUnqt :: (ParseDot a, ParseDot b) => Parse (a, b)
- commaSep' :: Parse a -> Parse b -> Parse (a, b)
- stringRep :: a -> String -> Parse a
- stringReps :: a -> [String] -> Parse a
- stringParse :: [(String, Parse a)] -> Parse a
- stringValue :: [(String, a)] -> Parse a
- parseAngled :: Parse a -> Parse a
- parseBraced :: Parse a -> Parse a
- parseColorScheme :: Bool -> Parse ColorScheme
Re-exporting pertinent parts of Polyparse.
class Functor f => Applicative (f :: Type -> Type) where #
A functor with application, providing operations to
A minimal complete definition must include implementations of pure
and of either <*>
or liftA2
. If it defines both, then they must behave
the same as their default definitions:
(<*>
) =liftA2
id
liftA2
f x y = f<$>
x<*>
y
Further, any definition must satisfy the following:
- identity
pure
id
<*>
v = v- composition
pure
(.)<*>
u<*>
v<*>
w = u<*>
(v<*>
w)- homomorphism
pure
f<*>
pure
x =pure
(f x)- interchange
u
<*>
pure
y =pure
($
y)<*>
u
The other methods have the following default definitions, which may be overridden with equivalent specialized implementations:
As a consequence of these laws, the Functor
instance for f
will satisfy
It may be useful to note that supposing
forall x y. p (q x y) = f x . g y
it follows from the above that
liftA2
p (liftA2
q u v) =liftA2
f u .liftA2
g v
If f
is also a Monad
, it should satisfy
(which implies that pure
and <*>
satisfy the applicative functor laws).
Lift a value.
(<*>) :: f (a -> b) -> f a -> f b infixl 4 #
Sequential application.
A few functors support an implementation of <*>
that is more
efficient than the default one.
liftA2 :: (a -> b -> c) -> f a -> f b -> f c #
Lift a binary function to actions.
Some functors support an implementation of liftA2
that is more
efficient than the default one. In particular, if fmap
is an
expensive operation, it is likely better to use liftA2
than to
fmap
over the structure and then use <*>
.
(*>) :: f a -> f b -> f b infixl 4 #
Sequence actions, discarding the value of the first argument.
(<*) :: f a -> f b -> f a infixl 4 #
Sequence actions, discarding the value of the second argument.
Instances
Applicative [] | Since: base-2.1 |
Applicative Maybe | Since: base-2.1 |
Applicative IO | Since: base-2.1 |
Applicative Par1 | Since: base-4.9.0.0 |
Applicative Q | |
Applicative Min | Since: base-4.9.0.0 |
Applicative Max | Since: base-4.9.0.0 |
Applicative First | Since: base-4.9.0.0 |
Applicative Last | Since: base-4.9.0.0 |
Applicative Option | Since: base-4.9.0.0 |
Applicative ZipList | f '<$>' 'ZipList' xs1 '<*>' ... '<*>' 'ZipList' xsN = 'ZipList' (zipWithN f xs1 ... xsN) where (\a b c -> stimes c [a, b]) <$> ZipList "abcd" <*> ZipList "567" <*> ZipList [1..] = ZipList (zipWith3 (\a b c -> stimes c [a, b]) "abcd" "567" [1..]) = ZipList {getZipList = ["a5","b6b6","c7c7c7"]} Since: base-2.1 |
Applicative Identity | Since: base-4.8.0.0 |
Applicative STM | Since: base-4.8.0.0 |
Applicative First | Since: base-4.8.0.0 |
Applicative Last | Since: base-4.8.0.0 |
Applicative Dual | Since: base-4.8.0.0 |
Applicative Sum | Since: base-4.8.0.0 |
Applicative Product | Since: base-4.8.0.0 |
Applicative Down | Since: base-4.11.0.0 |
Applicative ReadPrec | Since: base-4.6.0.0 |
Applicative ReadP | Since: base-4.6.0.0 |
Applicative NonEmpty | Since: base-4.9.0.0 |
Applicative Put | |
Applicative RGB | |
Applicative Tree | |
Applicative Seq | Since: containers-0.5.4 |
Applicative DList | |
Applicative P | Since: base-4.5.0.0 |
Applicative DotCodeM Source # | |
Applicative (Either e) | Since: base-3.0 |
Applicative (U1 :: Type -> Type) | Since: base-4.9.0.0 |
Monoid a => Applicative ((,) a) | For tuples, the ("hello ", (+15)) <*> ("world!", 2002) ("hello world!",2017) Since: base-2.1 |
Monad m => Applicative (WrappedMonad m) | Since: base-2.1 |
Defined in Control.Applicative pure :: a -> WrappedMonad m a # (<*>) :: WrappedMonad m (a -> b) -> WrappedMonad m a -> WrappedMonad m b # liftA2 :: (a -> b -> c) -> WrappedMonad m a -> WrappedMonad m b -> WrappedMonad m c # (*>) :: WrappedMonad m a -> WrappedMonad m b -> WrappedMonad m b # (<*) :: WrappedMonad m a -> WrappedMonad m b -> WrappedMonad m a # | |
Arrow a => Applicative (ArrowMonad a) | Since: base-4.6.0.0 |
Defined in Control.Arrow pure :: a0 -> ArrowMonad a a0 # (<*>) :: ArrowMonad a (a0 -> b) -> ArrowMonad a a0 -> ArrowMonad a b # liftA2 :: (a0 -> b -> c) -> ArrowMonad a a0 -> ArrowMonad a b -> ArrowMonad a c # (*>) :: ArrowMonad a a0 -> ArrowMonad a b -> ArrowMonad a b # (<*) :: ArrowMonad a a0 -> ArrowMonad a b -> ArrowMonad a a0 # | |
Applicative (Proxy :: Type -> Type) | Since: base-4.7.0.0 |
(Functor m, Monad m) => Applicative (MaybeT m) | |
Applicative m => Applicative (ListT m) | |
Applicative (Parser s) | |
Applicative (IParser t) | |
Applicative (DotM n) Source # | |
Applicative f => Applicative (Rec1 f) | Since: base-4.9.0.0 |
Arrow a => Applicative (WrappedArrow a b) | Since: base-2.1 |
Defined in Control.Applicative pure :: a0 -> WrappedArrow a b a0 # (<*>) :: WrappedArrow a b (a0 -> b0) -> WrappedArrow a b a0 -> WrappedArrow a b b0 # liftA2 :: (a0 -> b0 -> c) -> WrappedArrow a b a0 -> WrappedArrow a b b0 -> WrappedArrow a b c # (*>) :: WrappedArrow a b a0 -> WrappedArrow a b b0 -> WrappedArrow a b b0 # (<*) :: WrappedArrow a b a0 -> WrappedArrow a b b0 -> WrappedArrow a b a0 # | |
Monoid m => Applicative (Const m :: Type -> Type) | Since: base-2.0.1 |
Applicative f => Applicative (Ap f) | Since: base-4.12.0.0 |
Applicative f => Applicative (Alt f) | Since: base-4.8.0.0 |
(Applicative f, Monad f) => Applicative (WhenMissing f x) | Equivalent to Since: containers-0.5.9 |
Defined in Data.IntMap.Internal pure :: a -> WhenMissing f x a # (<*>) :: WhenMissing f x (a -> b) -> WhenMissing f x a -> WhenMissing f x b # liftA2 :: (a -> b -> c) -> WhenMissing f x a -> WhenMissing f x b -> WhenMissing f x c # (*>) :: WhenMissing f x a -> WhenMissing f x b -> WhenMissing f x b # (<*) :: WhenMissing f x a -> WhenMissing f x b -> WhenMissing f x a # | |
(Functor m, Monad m) => Applicative (ExceptT e m) | |
Defined in Control.Monad.Trans.Except | |
Applicative m => Applicative (IdentityT m) | |
Defined in Control.Monad.Trans.Identity | |
(Functor m, Monad m) => Applicative (ErrorT e m) | |
Defined in Control.Monad.Trans.Error | |
(Functor m, Monad m) => Applicative (StateT s m) | |
Defined in Control.Monad.Trans.State.Lazy | |
(Functor m, Monad m) => Applicative (StateT s m) | |
Defined in Control.Monad.Trans.State.Strict | |
(Monoid w, Applicative m) => Applicative (WriterT w m) | |
Defined in Control.Monad.Trans.Writer.Lazy | |
(Monoid w, Applicative m) => Applicative (WriterT w m) | |
Defined in Control.Monad.Trans.Writer.Strict | |
Applicative ((->) a :: Type -> Type) | Since: base-2.1 |
Monoid c => Applicative (K1 i c :: Type -> Type) | Since: base-4.12.0.0 |
(Applicative f, Applicative g) => Applicative (f :*: g) | Since: base-4.9.0.0 |
(Monad f, Applicative f) => Applicative (WhenMatched f x y) | Equivalent to Since: containers-0.5.9 |
Defined in Data.IntMap.Internal pure :: a -> WhenMatched f x y a # (<*>) :: WhenMatched f x y (a -> b) -> WhenMatched f x y a -> WhenMatched f x y b # liftA2 :: (a -> b -> c) -> WhenMatched f x y a -> WhenMatched f x y b -> WhenMatched f x y c # (*>) :: WhenMatched f x y a -> WhenMatched f x y b -> WhenMatched f x y b # (<*) :: WhenMatched f x y a -> WhenMatched f x y b -> WhenMatched f x y a # | |
(Applicative f, Monad f) => Applicative (WhenMissing f k x) | Equivalent to Since: containers-0.5.9 |
Defined in Data.Map.Internal pure :: a -> WhenMissing f k x a # (<*>) :: WhenMissing f k x (a -> b) -> WhenMissing f k x a -> WhenMissing f k x b # liftA2 :: (a -> b -> c) -> WhenMissing f k x a -> WhenMissing f k x b -> WhenMissing f k x c # (*>) :: WhenMissing f k x a -> WhenMissing f k x b -> WhenMissing f k x b # (<*) :: WhenMissing f k x a -> WhenMissing f k x b -> WhenMissing f k x a # | |
Applicative (ContT r m) | |
Applicative m => Applicative (ReaderT r m) | |
Defined in Control.Monad.Trans.Reader | |
Applicative f => Applicative (M1 i c f) | Since: base-4.9.0.0 |
(Applicative f, Applicative g) => Applicative (f :.: g) | Since: base-4.9.0.0 |
(Monad f, Applicative f) => Applicative (WhenMatched f k x y) | Equivalent to Since: containers-0.5.9 |
Defined in Data.Map.Internal pure :: a -> WhenMatched f k x y a # (<*>) :: WhenMatched f k x y (a -> b) -> WhenMatched f k x y a -> WhenMatched f k x y b # liftA2 :: (a -> b -> c) -> WhenMatched f k x y a -> WhenMatched f k x y b -> WhenMatched f k x y c # (*>) :: WhenMatched f k x y a -> WhenMatched f k x y b -> WhenMatched f k x y b # (<*) :: WhenMatched f k x y a -> WhenMatched f k x y b -> WhenMatched f k x y a # | |
(Monoid w, Functor m, Monad m) => Applicative (RWST r w s m) | |
Defined in Control.Monad.Trans.RWS.Lazy | |
(Monoid w, Functor m, Monad m) => Applicative (RWST r w s m) | |
Defined in Control.Monad.Trans.RWS.Strict |
optional :: Alternative f => f a -> f (Maybe a) #
One or none.
newtype WrappedMonad (m :: Type -> Type) a #
WrapMonad | |
|
Instances
newtype WrappedArrow (a :: Type -> Type -> Type) b c #
WrapArrow | |
|
Instances
Lists, but with an Applicative
functor based on zipping.
ZipList | |
|
Instances
Functor ZipList | Since: base-2.1 |
Applicative ZipList | f '<$>' 'ZipList' xs1 '<*>' ... '<*>' 'ZipList' xsN = 'ZipList' (zipWithN f xs1 ... xsN) where (\a b c -> stimes c [a, b]) <$> ZipList "abcd" <*> ZipList "567" <*> ZipList [1..] = ZipList (zipWith3 (\a b c -> stimes c [a, b]) "abcd" "567" [1..]) = ZipList {getZipList = ["a5","b6b6","c7c7c7"]} Since: base-2.1 |
Foldable ZipList | Since: base-4.9.0.0 |
Defined in Control.Applicative fold :: Monoid m => ZipList m -> m # foldMap :: Monoid m => (a -> m) -> ZipList a -> m # foldr :: (a -> b -> b) -> b -> ZipList a -> b # foldr' :: (a -> b -> b) -> b -> ZipList a -> b # foldl :: (b -> a -> b) -> b -> ZipList a -> b # foldl' :: (b -> a -> b) -> b -> ZipList a -> b # foldr1 :: (a -> a -> a) -> ZipList a -> a # foldl1 :: (a -> a -> a) -> ZipList a -> a # elem :: Eq a => a -> ZipList a -> Bool # maximum :: Ord a => ZipList a -> a # minimum :: Ord a => ZipList a -> a # | |
Traversable ZipList | Since: base-4.9.0.0 |
Alternative ZipList | Since: base-4.11.0.0 |
Eq a => Eq (ZipList a) | Since: base-4.7.0.0 |
Ord a => Ord (ZipList a) | Since: base-4.7.0.0 |
Defined in Control.Applicative | |
Read a => Read (ZipList a) | Since: base-4.7.0.0 |
Show a => Show (ZipList a) | Since: base-4.7.0.0 |
Generic (ZipList a) | |
Generic1 ZipList | |
type Rep (ZipList a) | Since: base-4.7.0.0 |
Defined in Control.Applicative | |
type Rep1 ZipList | Since: base-4.7.0.0 |
Defined in Control.Applicative |
newtype Const a (b :: k) :: forall k. Type -> k -> Type #
The Const
functor.
Instances
Generic1 (Const a :: k -> Type) | |
Eq2 (Const :: Type -> Type -> Type) | Since: base-4.9.0.0 |
Ord2 (Const :: Type -> Type -> Type) | Since: base-4.9.0.0 |
Defined in Data.Functor.Classes | |
Read2 (Const :: Type -> Type -> Type) | Since: base-4.9.0.0 |
Defined in Data.Functor.Classes liftReadsPrec2 :: (Int -> ReadS a) -> ReadS [a] -> (Int -> ReadS b) -> ReadS [b] -> Int -> ReadS (Const a b) # liftReadList2 :: (Int -> ReadS a) -> ReadS [a] -> (Int -> ReadS b) -> ReadS [b] -> ReadS [Const a b] # liftReadPrec2 :: ReadPrec a -> ReadPrec [a] -> ReadPrec b -> ReadPrec [b] -> ReadPrec (Const a b) # liftReadListPrec2 :: ReadPrec a -> ReadPrec [a] -> ReadPrec b -> ReadPrec [b] -> ReadPrec [Const a b] # | |
Show2 (Const :: Type -> Type -> Type) | Since: base-4.9.0.0 |
Functor (Const m :: Type -> Type) | Since: base-2.1 |
Monoid m => Applicative (Const m :: Type -> Type) | Since: base-2.0.1 |
Foldable (Const m :: Type -> Type) | Since: base-4.7.0.0 |
Defined in Data.Functor.Const fold :: Monoid m0 => Const m m0 -> m0 # foldMap :: Monoid m0 => (a -> m0) -> Const m a -> m0 # foldr :: (a -> b -> b) -> b -> Const m a -> b # foldr' :: (a -> b -> b) -> b -> Const m a -> b # foldl :: (b -> a -> b) -> b -> Const m a -> b # foldl' :: (b -> a -> b) -> b -> Const m a -> b # foldr1 :: (a -> a -> a) -> Const m a -> a # foldl1 :: (a -> a -> a) -> Const m a -> a # elem :: Eq a => a -> Const m a -> Bool # maximum :: Ord a => Const m a -> a # minimum :: Ord a => Const m a -> a # | |
Traversable (Const m :: Type -> Type) | Since: base-4.7.0.0 |
Eq a => Eq1 (Const a :: Type -> Type) | Since: base-4.9.0.0 |
Ord a => Ord1 (Const a :: Type -> Type) | Since: base-4.9.0.0 |
Defined in Data.Functor.Classes | |
Read a => Read1 (Const a :: Type -> Type) | Since: base-4.9.0.0 |
Defined in Data.Functor.Classes | |
Show a => Show1 (Const a :: Type -> Type) | Since: base-4.9.0.0 |
Bounded a => Bounded (Const a b) | Since: base-4.9.0.0 |
Enum a => Enum (Const a b) | Since: base-4.9.0.0 |
Defined in Data.Functor.Const succ :: Const a b -> Const a b # pred :: Const a b -> Const a b # fromEnum :: Const a b -> Int # enumFrom :: Const a b -> [Const a b] # enumFromThen :: Const a b -> Const a b -> [Const a b] # enumFromTo :: Const a b -> Const a b -> [Const a b] # enumFromThenTo :: Const a b -> Const a b -> Const a b -> [Const a b] # | |
Eq a => Eq (Const a b) | Since: base-4.9.0.0 |
Floating a => Floating (Const a b) | Since: base-4.9.0.0 |
Defined in Data.Functor.Const exp :: Const a b -> Const a b # log :: Const a b -> Const a b # sqrt :: Const a b -> Const a b # (**) :: Const a b -> Const a b -> Const a b # logBase :: Const a b -> Const a b -> Const a b # sin :: Const a b -> Const a b # cos :: Const a b -> Const a b # tan :: Const a b -> Const a b # asin :: Const a b -> Const a b # acos :: Const a b -> Const a b # atan :: Const a b -> Const a b # sinh :: Const a b -> Const a b # cosh :: Const a b -> Const a b # tanh :: Const a b -> Const a b # asinh :: Const a b -> Const a b # acosh :: Const a b -> Const a b # atanh :: Const a b -> Const a b # log1p :: Const a b -> Const a b # expm1 :: Const a b -> Const a b # | |
Fractional a => Fractional (Const a b) | Since: base-4.9.0.0 |
Integral a => Integral (Const a b) | Since: base-4.9.0.0 |
Defined in Data.Functor.Const | |
Num a => Num (Const a b) | Since: base-4.9.0.0 |
Ord a => Ord (Const a b) | Since: base-4.9.0.0 |
Defined in Data.Functor.Const | |
Read a => Read (Const a b) | This instance would be equivalent to the derived instances of the
Since: base-4.8.0.0 |
Real a => Real (Const a b) | Since: base-4.9.0.0 |
Defined in Data.Functor.Const toRational :: Const a b -> Rational # | |
RealFloat a => RealFloat (Const a b) | Since: base-4.9.0.0 |
Defined in Data.Functor.Const floatRadix :: Const a b -> Integer # floatDigits :: Const a b -> Int # floatRange :: Const a b -> (Int, Int) # decodeFloat :: Const a b -> (Integer, Int) # encodeFloat :: Integer -> Int -> Const a b # exponent :: Const a b -> Int # significand :: Const a b -> Const a b # scaleFloat :: Int -> Const a b -> Const a b # isInfinite :: Const a b -> Bool # isDenormalized :: Const a b -> Bool # isNegativeZero :: Const a b -> Bool # | |
RealFrac a => RealFrac (Const a b) | Since: base-4.9.0.0 |
Show a => Show (Const a b) | This instance would be equivalent to the derived instances of the
Since: base-4.8.0.0 |
Ix a => Ix (Const a b) | Since: base-4.9.0.0 |
Defined in Data.Functor.Const range :: (Const a b, Const a b) -> [Const a b] # index :: (Const a b, Const a b) -> Const a b -> Int # unsafeIndex :: (Const a b, Const a b) -> Const a b -> Int inRange :: (Const a b, Const a b) -> Const a b -> Bool # rangeSize :: (Const a b, Const a b) -> Int # unsafeRangeSize :: (Const a b, Const a b) -> Int | |
IsString a => IsString (Const a b) | Since: base-4.9.0.0 |
Defined in Data.String fromString :: String -> Const a b # | |
Generic (Const a b) | |
Semigroup a => Semigroup (Const a b) | Since: base-4.9.0.0 |
Monoid a => Monoid (Const a b) | Since: base-4.9.0.0 |
Storable a => Storable (Const a b) | Since: base-4.9.0.0 |
Defined in Data.Functor.Const | |
Bits a => Bits (Const a b) | Since: base-4.9.0.0 |
Defined in Data.Functor.Const (.&.) :: Const a b -> Const a b -> Const a b # (.|.) :: Const a b -> Const a b -> Const a b # xor :: Const a b -> Const a b -> Const a b # complement :: Const a b -> Const a b # shift :: Const a b -> Int -> Const a b # rotate :: Const a b -> Int -> Const a b # setBit :: Const a b -> Int -> Const a b # clearBit :: Const a b -> Int -> Const a b # complementBit :: Const a b -> Int -> Const a b # testBit :: Const a b -> Int -> Bool # bitSizeMaybe :: Const a b -> Maybe Int # isSigned :: Const a b -> Bool # shiftL :: Const a b -> Int -> Const a b # unsafeShiftL :: Const a b -> Int -> Const a b # shiftR :: Const a b -> Int -> Const a b # unsafeShiftR :: Const a b -> Int -> Const a b # rotateL :: Const a b -> Int -> Const a b # | |
FiniteBits a => FiniteBits (Const a b) | Since: base-4.9.0.0 |
Defined in Data.Functor.Const finiteBitSize :: Const a b -> Int # countLeadingZeros :: Const a b -> Int # countTrailingZeros :: Const a b -> Int # | |
type Rep1 (Const a :: k -> Type) | Since: base-4.9.0.0 |
Defined in Data.Functor.Const | |
type Rep (Const a b) | Since: base-4.9.0.0 |
Defined in Data.Functor.Const |
(<$>) :: Functor f => (a -> b) -> f a -> f b infixl 4 #
An infix synonym for fmap
.
The name of this operator is an allusion to $
.
Note the similarities between their types:
($) :: (a -> b) -> a -> b (<$>) :: Functor f => (a -> b) -> f a -> f b
Whereas $
is function application, <$>
is function
application lifted over a Functor
.
Examples
Convert from a
to a Maybe
Int
using Maybe
String
show
:
>>>
show <$> Nothing
Nothing>>>
show <$> Just 3
Just "3"
Convert from an
to an Either
Int
Int
Either
Int
String
using show
:
>>>
show <$> Left 17
Left 17>>>
show <$> Right 17
Right "17"
Double each element of a list:
>>>
(*2) <$> [1,2,3]
[2,4,6]
Apply even
to the second element of a pair:
>>>
even <$> (2,2)
(2,True)
liftA3 :: Applicative f => (a -> b -> c -> d) -> f a -> f b -> f c -> f d #
Lift a ternary function to actions.
liftA :: Applicative f => (a -> b) -> f a -> f b #
(<**>) :: Applicative f => f a -> f (a -> b) -> f b infixl 4 #
A variant of <*>
with the arguments reversed.
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:
Instances
reparse :: Text -> Parser s () #
Push some tokens back onto the front of the input stream and reparse. This is useful e.g. for recursively expanding macros. When the user-parser recognises a macro use, it can lookup the macro expansion from the parse state, lex it, and then stuff the lexed expansion back down into the parser.
many1Satisfy :: (Char -> Bool) -> Parser s Text #
many1Satisfy p
is a more efficient fused version of many1 (satisfy p)
manySatisfy :: (Char -> Bool) -> Parser s Text #
manySatisfy p
is a more efficient fused version of many (satisfy p)
onFail :: Parser s a -> Parser s a -> Parser s a #
p
means parse p, unless p fails, in which case
parse q instead.
Can be chained together to give multiple attempts to parse something.
(Note that q could itself be a failing parser, e.g. to change the error
message from that defined in p to something different.)
However, a severe failure in p cannot be ignored.onFail
q
satisfy :: (Char -> Bool) -> Parser s Char #
Return the next token if it satisfies the given predicate.
This Parser
datatype is a specialised parsing monad with error
reporting. Whereas the standard version can be used for arbitrary
token types, this version is specialised to Text input only.
Instances
Monad (Parser s) | |
Functor (Parser s) | |
MonadFail (Parser s) | |
Defined in Text.ParserCombinators.Poly.StateText | |
Applicative (Parser s) | |
Alternative (Parser s) | |
Commitment (Parser s) | |
PolyParse (Parser s) | |
Defined in Text.ParserCombinators.Poly.StateText |
A return type like Either, that distinguishes not only between right and wrong answers, but also has commitment, so that a failure cannot be undone. This should only be used for writing very primitive parsers - really it is an internal detail of the library. The z type is the remaining unconsumed input.
manyFinally' :: (PolyParse p, Show a) => p a -> p z -> p [a] #
manyFinally'
is like manyFinally
, except when the terminator
parser overlaps with the element parser. In manyFinally e t
,
the parser t
is tried only when parser e
fails, whereas in
manyFinally' e t
, the parser t
is always tried first, then
parser e
only if the terminator is not found. For instance,
manyFinally (accept "01") (accept "0")
on input "0101010"
returns
["01","01","01"]
, whereas manyFinally'
with the same arguments
and input returns []
.
manyFinally :: PolyParse p => p a -> p z -> p [a] #
manyFinally e t
parses a possibly-empty sequence of e
's,
terminated by a t
. The final t
is discarded. Any parse failures
could be due either to a badly-formed terminator or a badly-formed
element, so it raises both possible errors.
bracket :: PolyParse p => p bra -> p ket -> p a -> p a #
Parse a bracketed item, discarding the brackets.
If everything matches except the closing bracket, the whole
parse fails soft, which can give less-than-satisfying error messages.
If you want better error messages, try calling with e.g.
bracket open (commit close) item
bracketSep :: PolyParse p => p bra -> p sep -> p ket -> p a -> p [a] #
Parse a list of items, discarding the start, end, and separator items.
sepBy1 :: PolyParse p => p a -> p sep -> p [a] #
Parse a non-empty list of items separated by discarded junk.
upto :: PolyParse p => Int -> p a -> p [a] #
'upto n p' parses n or fewer items, using the parser p, in sequence.
exactly :: PolyParse p => Int -> p a -> p [a] #
'exactly n p' parses precisely n items, using the parser p, in sequence.
adjustErrBad :: PolyParse p => p a -> (String -> String) -> p a #
adjustErrBad
is just like adjustErr
except it also raises the
severity of the error.
failBad :: PolyParse p => String -> p a #
When a simple fail is not strong enough, use failBad for emphasis. An emphasised (severe) error cannot be overridden by choice operators.
discard :: PolyParse p => p a -> p b -> p a infixl 3 #
x
parses both x and y, but discards the result of y.
Rather like discard
yconst
lifted into parsers.
apply :: PolyParse p => p (a -> b) -> p a -> p b infixl 3 #
Apply a parsed function to a parsed value. Rather like ordinary function application lifted into parsers.
class Commitment (p :: Type -> Type) where #
The Commitment
class is an abstraction over all the current
concrete representations of monadic/applicative parser combinators in this
package. The common feature is two-level error-handling.
Some primitives must be implemented specific to each parser type
(e.g. depending on whether the parser has a running state, or
whether it is lazy). But given those primitives, large numbers of
combinators do not depend any further on the internal structure of
the particular parser.
Commit is a way of raising the severity of any errors found within its argument. Used in the middle of a parser definition, it means that any operations prior to commitment fail softly, but after commitment, they fail hard.
adjustErr :: p a -> (String -> String) -> p a #
p
applies the transformation adjustErr
ff
to any error message
generated in p
, having no effect if p
succeeds.
oneOf' :: [(String, p a)] -> p a #
Parse the first alternative that succeeds, but if none succeed, report only the severe errors, and if none of those, then report all the soft errors.
class (Functor p, Monad p, MonadFail p, Applicative p, Alternative p, Commitment p) => PolyParse (p :: Type -> Type) #
The PolyParse
class is an abstraction gathering all of the common
features that a two-level error-handling parser requires:
the applicative parsing interface, the monadic interface, and commitment.
There are two additional basic combinators that we expect to be implemented
afresh for every concrete type, but which (for technical reasons)
cannot be class methods. They are next
and satisfy
.
Instances
PolyParse (Parser s) | |
Defined in Text.ParserCombinators.Poly.StateText |
The ParseDot class.
class ParseDot a where Source #
parseUnqtList :: Parse [a] Source #
Instances
parseIt :: ParseDot a => Text -> (a, Text) Source #
Parse the required value, returning also the rest of the input
Text
that hasn't been parsed (for debugging purposes).
parseIt' :: ParseDot a => Text -> a Source #
Parse the required value with the assumption that it will parse
all of the input Text
.
runParser' :: Parse a -> Text -> a Source #
runParserWith :: (GraphvizState -> GraphvizState) -> Parse a -> Text -> (Either String a, Text) Source #
parseLiberally :: GraphvizState -> GraphvizState Source #
checkValidParse :: Either String a -> a Source #
If unable to parse Dot code properly, throw
a
GraphvizException
.
checkValidParseWithRest :: (Either String a, Text) -> a Source #
If unable to parse Dot code properly, throw
a
GraphvizException
, with the error containing the remaining
unparsed code..
Convenience parsing combinators.
ignoreSep :: (a -> b -> c) -> Parse a -> Parse sep -> Parse b -> Parse c Source #
The opposite of bracket
.
stringBlock :: Parse Text Source #
isNumString :: Bool -> Text -> Bool Source #
Determine if this String represents a number. Boolean parameter determines if exponents are considered part of numbers for this.
isIntString :: Text -> Bool Source #
quotedString :: Parse Text Source #
Used when quotes are explicitly required;
parseAndSpace :: Parse a -> Parse a Source #
character :: Char -> Parse Char Source #
Assumes that any letter is ASCII for case-insensitive comparisons.
parseStrictFloat :: Bool -> Parse Double Source #
Parse a floating point number that actually contains decimals. Bool flag indicates whether values that need to be quoted are parsed.
whitespace1 :: Parse () Source #
Parses at least one whitespace character.
whitespace :: Parse () Source #
Parses zero or more whitespace characters.
wrapWhitespace :: Parse a -> Parse a Source #
Parse and discard optional surrounding whitespace.
optionalQuotedString :: String -> Parse () Source #
optionalQuoted :: Parse a -> Parse a Source #
quotedParse :: Parse a -> Parse a Source #
Consume all whitespace and newlines until a line with non-whitespace is reached. The whitespace on that line is not consumed.
parseComma :: Parse () Source #
tryParseList :: ParseDot a => Parse [a] Source #
Try to parse a list of the specified type; returns an empty list if parsing fails.
tryParseList' :: Parse [a] -> Parse [a] Source #
Return an empty list if parsing a list fails.
consumeLine :: Parse Text Source #
Parses and returns all characters up till the end of the line, but does not touch the newline characters.
stringReps :: a -> [String] -> Parse a Source #
stringValue :: [(String, a)] -> Parse a Source #
parseAngled :: Parse a -> Parse a Source #
parseBraced :: Parse a -> Parse a Source #
parseColorScheme :: Bool -> Parse ColorScheme Source #