    {-# LANGUAGE GADTs #-}
    {-# LANGUAGE RankNTypes #-}
    {-# LANGUAGE ScopedTypeVariables #-}
    {-# LANGUAGE CPP #-}
    module Text.Regex.Applicative.Types where

    import Control.Applicative
    import Control.Monad ((<=<))
    import Data.Filtrable (Filtrable (..))
    import Data.Functor.Identity (Identity (..))
    import Data.String
    #if !MIN_VERSION_base(4,11,0)
    import Data.Semigroup
    #endif

    newtype ThreadId = ThreadId Int

    -- | A thread either is a result or corresponds to a symbol in the regular
    -- expression, which is expected by that thread.
    data Thread s r
        = Thread
            { forall s r. Thread s r -> ThreadId
    threadId_ :: ThreadId
            , forall s r. Thread s r -> s -> [Thread s r]
    _threadCont :: s -> [Thread s r]
            }
        | Accept r

    -- | Returns thread identifier. This will be 'Just' for ordinary threads and
    -- 'Nothing' for results.
    threadId :: Thread s r -> Maybe ThreadId
    threadId :: forall s r. Thread s r -> Maybe ThreadId
    threadId Thread { threadId_ :: forall s r. Thread s r -> ThreadId
    threadId_ = ThreadId
    i } = ThreadId -> Maybe ThreadId
    forall a. a -> Maybe a
    Just ThreadId
    i
    threadId Thread s r
    _ = Maybe ThreadId
    forall a. Maybe a
    Nothing

    data Greediness = Greedy | NonGreedy
        deriving (Int -> Greediness -> ShowS
    [Greediness] -> ShowS
    Greediness -> String
    (Int -> Greediness -> ShowS)
    -> (Greediness -> String)
    -> ([Greediness] -> ShowS)
    -> Show Greediness
    forall a.
    (Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
    $cshowsPrec :: Int -> Greediness -> ShowS
    showsPrec :: Int -> Greediness -> ShowS
    $cshow :: Greediness -> String
    show :: Greediness -> String
    $cshowList :: [Greediness] -> ShowS
    showList :: [Greediness] -> ShowS
    Show, ReadPrec [Greediness]
    ReadPrec Greediness
    Int -> ReadS Greediness
    ReadS [Greediness]
    (Int -> ReadS Greediness)
    -> ReadS [Greediness]
    -> ReadPrec Greediness
    -> ReadPrec [Greediness]
    -> Read Greediness
    forall a.
    (Int -> ReadS a)
    -> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
    $creadsPrec :: Int -> ReadS Greediness
    readsPrec :: Int -> ReadS Greediness
    $creadList :: ReadS [Greediness]
    readList :: ReadS [Greediness]
    $creadPrec :: ReadPrec Greediness
    readPrec :: ReadPrec Greediness
    $creadListPrec :: ReadPrec [Greediness]
    readListPrec :: ReadPrec [Greediness]
    Read, Greediness -> Greediness -> Bool
    (Greediness -> Greediness -> Bool)
    -> (Greediness -> Greediness -> Bool) -> Eq Greediness
    forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
    $c== :: Greediness -> Greediness -> Bool
    == :: Greediness -> Greediness -> Bool
    $c/= :: Greediness -> Greediness -> Bool
    /= :: Greediness -> Greediness -> Bool
    Eq, Eq Greediness
    Eq Greediness =>
    (Greediness -> Greediness -> Ordering)
    -> (Greediness -> Greediness -> Bool)
    -> (Greediness -> Greediness -> Bool)
    -> (Greediness -> Greediness -> Bool)
    -> (Greediness -> Greediness -> Bool)
    -> (Greediness -> Greediness -> Greediness)
    -> (Greediness -> Greediness -> Greediness)
    -> Ord Greediness
    Greediness -> Greediness -> Bool
    Greediness -> Greediness -> Ordering
    Greediness -> Greediness -> Greediness
    forall a.
    Eq a =>
    (a -> a -> Ordering)
    -> (a -> a -> Bool)
    -> (a -> a -> Bool)
    -> (a -> a -> Bool)
    -> (a -> a -> Bool)
    -> (a -> a -> a)
    -> (a -> a -> a)
    -> Ord a
    $ccompare :: Greediness -> Greediness -> Ordering
    compare :: Greediness -> Greediness -> Ordering
    $c< :: Greediness -> Greediness -> Bool
    < :: Greediness -> Greediness -> Bool
    $c<= :: Greediness -> Greediness -> Bool
    <= :: Greediness -> Greediness -> Bool
    $c> :: Greediness -> Greediness -> Bool
    > :: Greediness -> Greediness -> Bool
    $c>= :: Greediness -> Greediness -> Bool
    >= :: Greediness -> Greediness -> Bool
    $cmax :: Greediness -> Greediness -> Greediness
    max :: Greediness -> Greediness -> Greediness
    $cmin :: Greediness -> Greediness -> Greediness
    min :: Greediness -> Greediness -> Greediness
    Ord, Int -> Greediness
    Greediness -> Int
    Greediness -> [Greediness]
    Greediness -> Greediness
    Greediness -> Greediness -> [Greediness]
    Greediness -> Greediness -> Greediness -> [Greediness]
    (Greediness -> Greediness)
    -> (Greediness -> Greediness)
    -> (Int -> Greediness)
    -> (Greediness -> Int)
    -> (Greediness -> [Greediness])
    -> (Greediness -> Greediness -> [Greediness])
    -> (Greediness -> Greediness -> [Greediness])
    -> (Greediness -> Greediness -> Greediness -> [Greediness])
    -> Enum Greediness
    forall a.
    (a -> a)
    -> (a -> a)
    -> (Int -> a)
    -> (a -> Int)
    -> (a -> [a])
    -> (a -> a -> [a])
    -> (a -> a -> [a])
    -> (a -> a -> a -> [a])
    -> Enum a
    $csucc :: Greediness -> Greediness
    succ :: Greediness -> Greediness
    $cpred :: Greediness -> Greediness
    pred :: Greediness -> Greediness
    $ctoEnum :: Int -> Greediness
    toEnum :: Int -> Greediness
    $cfromEnum :: Greediness -> Int
    fromEnum :: Greediness -> Int
    $cenumFrom :: Greediness -> [Greediness]
    enumFrom :: Greediness -> [Greediness]
    $cenumFromThen :: Greediness -> Greediness -> [Greediness]
    enumFromThen :: Greediness -> Greediness -> [Greediness]
    $cenumFromTo :: Greediness -> Greediness -> [Greediness]
    enumFromTo :: Greediness -> Greediness -> [Greediness]
    $cenumFromThenTo :: Greediness -> Greediness -> Greediness -> [Greediness]
    enumFromThenTo :: Greediness -> Greediness -> Greediness -> [Greediness]
    Enum)

    -- | Type of regular expressions that recognize symbols of type @s@ and
    -- produce a result of type @a@.
    --
    -- Regular expressions can be built using 'Functor', 'Applicative',
    -- 'Alternative', and 'Filtrable' instances in the following natural way:
    --
    -- * @f@ '<$>' @ra@ matches iff @ra@ matches, and its return value is the result
    -- of applying @f@ to the return value of @ra@.
    --
    -- * 'pure' @x@ matches the empty string (i.e. it does not consume any symbols),
    -- and its return value is @x@
    --
    -- * @rf@ '<*>' @ra@ matches a string iff it is a concatenation of two
    -- strings: one matched by @rf@ and the other matched by @ra@. The return value
    -- is @f a@, where @f@ and @a@ are the return values of @rf@ and @ra@
    -- respectively.
    --
    -- * @ra@ '<|>' @rb@ matches a string which is accepted by either @ra@ or @rb@.
    -- It is left-biased, so if both can match, the result of @ra@ is used.
    --
    -- * 'empty' is a regular expression which does not match any string.
    --
    -- * 'many' @ra@ matches concatenation of zero or more strings matched by @ra@
    -- and returns the list of @ra@'s return values on those strings.
    --
    -- * 'some' @ra@ matches concatenation of one or more strings matched by @ra@
    -- and returns the list of @ra@'s return values on those strings.
    --
    -- * 'catMaybes' @ram@ matches iff @ram@ matches and produces 'Just _'.
    --
    -- * @ra@ '<>' @rb@ matches @ra@ followed by @rb@. The return value is @a <> b@,
    -- where @a@ and @b@ are the return values of @ra@ and @rb@ respectively.
    -- (See <https://github.com/feuerbach/regex-applicative/issues/37#issue-499781703>
    -- for an example usage.)
    --
    -- * 'mempty' matches the empty string (i.e. it does not consume any symbols),
    -- and its return value is the 'mempty' value of type @a@.
    data RE s a where
        Eps :: RE s ()
        Symbol :: ThreadId -> (s -> Maybe a) -> RE s a
        Alt :: RE s a -> RE s a -> RE s a
        App :: RE s (a -> b) -> RE s a -> RE s b
        Fmap :: (a -> b) -> RE s a -> RE s b
        CatMaybes :: RE s (Maybe a) -> RE s a
        Fail :: RE s a
        Rep :: Greediness    -- repetition may be greedy or not
            -> (b -> a -> b) -- folding function (like in foldl)
            -> b             -- the value for zero matches, and also the initial value
                             -- for the folding function
            -> RE s a
            -> RE s b
        Void :: RE s a -> RE s ()

    -- | Traverse each (reflexive, transitive) subexpression of a 'RE', depth-first and post-order.
    traversePostorder :: forall s a m . Monad m => (forall a . RE s a -> m (RE s a)) -> RE s a -> m (RE s a)
    traversePostorder :: forall s a (m :: * -> *).
    Monad m =>
    (forall a. RE s a -> m (RE s a)) -> RE s a -> m (RE s a)
    traversePostorder forall a. RE s a -> m (RE s a)
    f = RE s a -> m (RE s a)
    forall a. RE s a -> m (RE s a)
    go
      where
        go :: forall a . RE s a -> m (RE s a)
        go :: forall a. RE s a -> m (RE s a)
    go = RE s a -> m (RE s a)
    forall a. RE s a -> m (RE s a)
    f (RE s a -> m (RE s a))
    -> (RE s a -> m (RE s a)) -> RE s a -> m (RE s a)
    forall (m :: * -> *) b c a.
    Monad m =>
    (b -> m c) -> (a -> m b) -> a -> m c
    <=< \ case
            RE s a
    Eps -> RE s a -> m (RE s a)
    forall a. a -> m a
    forall (f :: * -> *) a. Applicative f => a -> f a
    pure RE s a
    RE s ()
    forall s. RE s ()
    Eps
            Symbol ThreadId
    i s -> Maybe a
    p -> RE s a -> m (RE s a)
    forall a. a -> m a
    forall (f :: * -> *) a. Applicative f => a -> f a
    pure (ThreadId -> (s -> Maybe a) -> RE s a
    forall s a. ThreadId -> (s -> Maybe a) -> RE s a
    Symbol ThreadId
    i s -> Maybe a
    p)
            Alt RE s a
    a RE s a
    b -> RE s a -> RE s a -> RE s a
    forall s a. RE s a -> RE s a -> RE s a
    Alt (RE s a -> RE s a -> RE s a) -> m (RE s a) -> m (RE s a -> RE s a)
    forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
    <$> RE s a -> m (RE s a)
    forall a. RE s a -> m (RE s a)
    go RE s a
    a m (RE s a -> RE s a) -> m (RE s a) -> m (RE s a)
    forall a b. m (a -> b) -> m a -> m b
    forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
    <*> RE s a -> m (RE s a)
    forall a. RE s a -> m (RE s a)
    go RE s a
    b
            App RE s (a -> a)
    a RE s a
    b -> RE s (a -> a) -> RE s a -> RE s a
    forall s a b. RE s (a -> b) -> RE s a -> RE s b
    App (RE s (a -> a) -> RE s a -> RE s a)
    -> m (RE s (a -> a)) -> m (RE s a -> RE s a)
    forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
    <$> RE s (a -> a) -> m (RE s (a -> a))
    forall a. RE s a -> m (RE s a)
    go RE s (a -> a)
    a m (RE s a -> RE s a) -> m (RE s a) -> m (RE s a)
    forall a b. m (a -> b) -> m a -> m b
    forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
    <*> RE s a -> m (RE s a)
    forall a. RE s a -> m (RE s a)
    go RE s a
    b
            Fmap a -> a
    g RE s a
    a -> (a -> a) -> RE s a -> RE s a
    forall a b s. (a -> b) -> RE s a -> RE s b
    Fmap a -> a
    g (RE s a -> RE s a) -> m (RE s a) -> m (RE s a)
    forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
    <$> RE s a -> m (RE s a)
    forall a. RE s a -> m (RE s a)
    go RE s a
    a
            CatMaybes RE s (Maybe a)
    a -> RE s (Maybe a) -> RE s a
    forall s a. RE s (Maybe a) -> RE s a
    CatMaybes (RE s (Maybe a) -> RE s a) -> m (RE s (Maybe a)) -> m (RE s a)
    forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
    <$> RE s (Maybe a) -> m (RE s (Maybe a))
    forall a. RE s a -> m (RE s a)
    go RE s (Maybe a)
    a
            RE s a
    Fail -> RE s a -> m (RE s a)
    forall a. a -> m a
    forall (f :: * -> *) a. Applicative f => a -> f a
    pure RE s a
    forall s a. RE s a
    Fail
            Rep Greediness
    greed a -> a -> a
    g a
    b RE s a
    a -> Greediness -> (a -> a -> a) -> a -> RE s a -> RE s a
    forall b a s. Greediness -> (b -> a -> b) -> b -> RE s a -> RE s b
    Rep Greediness
    greed a -> a -> a
    g a
    b (RE s a -> RE s a) -> m (RE s a) -> m (RE s a)
    forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
    <$> RE s a -> m (RE s a)
    forall a. RE s a -> m (RE s a)
    go RE s a
    a
            Void RE s a
    a -> RE s a -> RE s a
    RE s a -> RE s ()
    forall s a. RE s a -> RE s ()
    Void (RE s a -> RE s a) -> m (RE s a) -> m (RE s a)
    forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
    <$> RE s a -> m (RE s a)
    forall a. RE s a -> m (RE s a)
    go RE s a
    a

    -- | Fold each (reflexive, transitive) subexpression of a 'RE', depth-first and post-order.
    foldMapPostorder :: Monoid b => (forall a . RE s a -> b) -> RE s a -> b
    foldMapPostorder :: forall b s a. Monoid b => (forall a. RE s a -> b) -> RE s a -> b
    foldMapPostorder forall a. RE s a -> b
    f = (b, RE s a) -> b
    forall a b. (a, b) -> a
    fst ((b, RE s a) -> b) -> (RE s a -> (b, RE s a)) -> RE s a -> b
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . (forall a. RE s a -> (b, RE s a)) -> RE s a -> (b, RE s a)
    forall s a (m :: * -> *).
    Monad m =>
    (forall a. RE s a -> m (RE s a)) -> RE s a -> m (RE s a)
    traversePostorder ((,) (b -> RE s a -> (b, RE s a))
    -> (RE s a -> b) -> RE s a -> RE s a -> (b, RE s a)
    forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
    <$> RE s a -> b
    forall a. RE s a -> b
    f (RE s a -> RE s a -> (b, RE s a))
    -> (RE s a -> RE s a) -> RE s a -> (b, RE s a)
    forall a b. (RE s a -> a -> b) -> (RE s a -> a) -> RE s a -> b
    forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
    <*> RE s a -> RE s a
    forall a. a -> a
    id)

    -- | Map each (reflexive, transitive) subexpression of a 'RE'.
    mapRE :: (forall a . RE s a -> RE s a) -> RE s a -> RE s a
    mapRE :: forall s a. (forall a. RE s a -> RE s a) -> RE s a -> RE s a
    mapRE forall a. RE s a -> RE s a
    f = Identity (RE s a) -> RE s a
    forall a. Identity a -> a
    runIdentity (Identity (RE s a) -> RE s a)
    -> (RE s a -> Identity (RE s a)) -> RE s a -> RE s a
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . (forall a. RE s a -> Identity (RE s a))
    -> RE s a -> Identity (RE s a)
    forall s a (m :: * -> *).
    Monad m =>
    (forall a. RE s a -> m (RE s a)) -> RE s a -> m (RE s a)
    traversePostorder (RE s a -> Identity (RE s a)
    forall a. a -> Identity a
    Identity (RE s a -> Identity (RE s a))
    -> (RE s a -> RE s a) -> RE s a -> Identity (RE s a)
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . RE s a -> RE s a
    forall a. RE s a -> RE s a
    f)

    instance Functor (RE s) where
        fmap :: forall a b. (a -> b) -> RE s a -> RE s b
    fmap a -> b
    f RE s a
    x = (a -> b) -> RE s a -> RE s b
    forall a b s. (a -> b) -> RE s a -> RE s b
    Fmap a -> b
    f RE s a
    x
        a
    f <$ :: forall a b. a -> RE s b -> RE s a
    <$ RE s b
    x = a -> RE s a
    forall a. a -> RE s a
    forall (f :: * -> *) a. Applicative f => a -> f a
    pure a
    f RE s a -> RE s b -> RE s a
    forall a b. RE s a -> RE s b -> RE s a
    forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
    <* RE s b
    x

    instance Applicative (RE s) where
        pure :: forall a. a -> RE s a
    pure a
    x = a -> () -> a
    forall a b. a -> b -> a
    const a
    x (() -> a) -> RE s () -> RE s a
    forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
    <$> RE s ()
    forall s. RE s ()
    Eps
        RE s (a -> b)
    a1 <*> :: forall a b. RE s (a -> b) -> RE s a -> RE s b
    <*> RE s a
    a2 = RE s (a -> b) -> RE s a -> RE s b
    forall s a b. RE s (a -> b) -> RE s a -> RE s b
    App RE s (a -> b)
    a1 RE s a
    a2
        RE s a
    a *> :: forall a b. RE s a -> RE s b -> RE s b
    *> RE s b
    b = (() -> b -> b) -> RE s (() -> b -> b)
    forall a. a -> RE s a
    forall (f :: * -> *) a. Applicative f => a -> f a
    pure ((b -> b) -> () -> b -> b
    forall a b. a -> b -> a
    const b -> b
    forall a. a -> a
    id) RE s (() -> b -> b) -> RE s () -> RE s (b -> b)
    forall a b. RE s (a -> b) -> RE s a -> RE s b
    forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
    <*> RE s a -> RE s ()
    forall s a. RE s a -> RE s ()
    Void RE s a
    a RE s (b -> b) -> RE s b -> RE s b
    forall a b. RE s (a -> b) -> RE s a -> RE s b
    forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
    <*> RE s b
    b
        RE s a
    a <* :: forall a b. RE s a -> RE s b -> RE s a
    <* RE s b
    b = (a -> () -> a) -> RE s (a -> () -> a)
    forall a. a -> RE s a
    forall (f :: * -> *) a. Applicative f => a -> f a
    pure a -> () -> a
    forall a b. a -> b -> a
    const RE s (a -> () -> a) -> RE s a -> RE s (() -> a)
    forall a b. RE s (a -> b) -> RE s a -> RE s b
    forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
    <*> RE s a
    a RE s (() -> a) -> RE s () -> RE s a
    forall a b. RE s (a -> b) -> RE s a -> RE s b
    forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
    <*> RE s b -> RE s ()
    forall s a. RE s a -> RE s ()
    Void RE s b
    b

    instance Alternative (RE s) where
        RE s a
    a1 <|> :: forall a. RE s a -> RE s a -> RE s a
    <|> RE s a
    a2 = RE s a -> RE s a -> RE s a
    forall s a. RE s a -> RE s a -> RE s a
    Alt RE s a
    a1 RE s a
    a2
        empty :: forall a. RE s a
    empty = RE s a
    forall s a. RE s a
    Fail
        many :: forall a. RE s a -> RE s [a]
    many RE s a
    a = [a] -> [a]
    forall a. [a] -> [a]
    reverse ([a] -> [a]) -> RE s [a] -> RE s [a]
    forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
    <$> Greediness -> ([a] -> a -> [a]) -> [a] -> RE s a -> RE s [a]
    forall b a s. Greediness -> (b -> a -> b) -> b -> RE s a -> RE s b
    Rep Greediness
    Greedy ((a -> [a] -> [a]) -> [a] -> a -> [a]
    forall a b c. (a -> b -> c) -> b -> a -> c
    flip (:)) [] RE s a
    a
        some :: forall a. RE s a -> RE s [a]
    some RE s a
    a = (:) (a -> [a] -> [a]) -> RE s a -> RE s ([a] -> [a])
    forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
    <$> RE s a
    a RE s ([a] -> [a]) -> RE s [a] -> RE s [a]
    forall a b. RE s (a -> b) -> RE s a -> RE s b
    forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
    <*> RE s a -> RE s [a]
    forall a. RE s a -> RE s [a]
    forall (f :: * -> *) a. Alternative f => f a -> f [a]
    many RE s a
    a

    -- | @since 0.3.4
    instance Filtrable (RE s) where
        catMaybes :: forall a. RE s (Maybe a) -> RE s a
    catMaybes = RE s (Maybe a) -> RE s a
    forall s a. RE s (Maybe a) -> RE s a
    CatMaybes

    instance (char ~ Char, string ~ String) => IsString (RE char string) where
        fromString :: String -> RE char string
    fromString = String -> RE char string
    String -> RE Char String
    forall a. Eq a => [a] -> RE a [a]
    string

    -- | @since 0.3.4
    instance Semigroup a => Semigroup (RE s a) where
        RE s a
    x <> :: RE s a -> RE s a -> RE s a
    <> RE s a
    y = a -> a -> a
    forall a. Semigroup a => a -> a -> a
    (<>) (a -> a -> a) -> RE s a -> RE s (a -> a)
    forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
    <$> RE s a
    x RE s (a -> a) -> RE s a -> RE s a
    forall a b. RE s (a -> b) -> RE s a -> RE s b
    forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
    <*> RE s a
    y

    -- | @since 0.3.4
    instance Monoid a => Monoid (RE s a) where
        mempty :: RE s a
    mempty = a -> RE s a
    forall a. a -> RE s a
    forall (f :: * -> *) a. Applicative f => a -> f a
    pure a
    forall a. Monoid a => a
    mempty

    -- | Match and return the given sequence of symbols.
    --
    -- Note that there is an 'IsString' instance for regular expression, so
    -- if you enable the @OverloadedStrings@ language extension, you can write
    -- @string \"foo\"@ simply as @\"foo\"@.
    --
    -- Example:
    --
    -- >{-# LANGUAGE OverloadedStrings #-}
    -- >import Text.Regex.Applicative
    -- >
    -- >number = "one" *> pure 1  <|>  "two" *> pure 2
    -- >
    -- >main = print $ "two" =~ number
    string :: Eq a => [a] -> RE a [a]
    string :: forall a. Eq a => [a] -> RE a [a]
    string = (a -> RE a a) -> [a] -> RE a [a]
    forall (t :: * -> *) (f :: * -> *) a b.
    (Traversable t, Applicative f) =>
    (a -> f b) -> t a -> f (t b)
    forall (f :: * -> *) a b.
    Applicative f =>
    (a -> f b) -> [a] -> f [b]
    traverse a -> RE a a
    forall s. Eq s => s -> RE s s
    sym

    -- | Match and return a single symbol which satisfies the predicate
    psym :: (s -> Bool) -> RE s s
    psym :: forall s. (s -> Bool) -> RE s s
    psym s -> Bool
    p = (s -> Maybe s) -> RE s s
    forall s a. (s -> Maybe a) -> RE s a
    msym (\s
    s -> if s -> Bool
    p s
    s then s -> Maybe s
    forall a. a -> Maybe a
    Just s
    s else Maybe s
    forall a. Maybe a
    Nothing)

    -- | Like 'psym', but allows to return a computed value instead of the
    -- original symbol
    msym :: (s -> Maybe a) -> RE s a
    msym :: forall s a. (s -> Maybe a) -> RE s a
    msym s -> Maybe a
    p = ThreadId -> (s -> Maybe a) -> RE s a
    forall s a. ThreadId -> (s -> Maybe a) -> RE s a
    Symbol (String -> ThreadId
    forall a. HasCallStack => String -> a
    error String
    "Not numbered symbol") s -> Maybe a
    p

    -- | Match and return the given symbol
    sym :: Eq s => s -> RE s s
    sym :: forall s. Eq s => s -> RE s s
    sym s
    s = (s -> Bool) -> RE s s
    forall s. (s -> Bool) -> RE s s
    psym (s
    s s -> s -> Bool
    forall a. Eq a => a -> a -> Bool
    ==)