    {-# OPTIONS_GHC -fno-warn-unused-imports    #-}

    module Text.RE.ZeInternals.Types.Poss where

    import           Control.Monad.Fail

    data Poss a
      = Eek String
      | Yup a
      deriving (Poss a -> Poss a -> Bool
    (Poss a -> Poss a -> Bool)
    -> (Poss a -> Poss a -> Bool) -> Eq (Poss a)
    forall a. Eq a => Poss a -> Poss a -> Bool
    forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
    $c== :: forall a. Eq a => Poss a -> Poss a -> Bool
    == :: Poss a -> Poss a -> Bool
    $c/= :: forall a. Eq a => Poss a -> Poss a -> Bool
    /= :: Poss a -> Poss a -> Bool
    Eq,Eq (Poss a)
    Eq (Poss a) =>
    (Poss a -> Poss a -> Ordering)
    -> (Poss a -> Poss a -> Bool)
    -> (Poss a -> Poss a -> Bool)
    -> (Poss a -> Poss a -> Bool)
    -> (Poss a -> Poss a -> Bool)
    -> (Poss a -> Poss a -> Poss a)
    -> (Poss a -> Poss a -> Poss a)
    -> Ord (Poss a)
    Poss a -> Poss a -> Bool
    Poss a -> Poss a -> Ordering
    Poss a -> Poss a -> Poss a
    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
    forall a. Ord a => Eq (Poss a)
    forall a. Ord a => Poss a -> Poss a -> Bool
    forall a. Ord a => Poss a -> Poss a -> Ordering
    forall a. Ord a => Poss a -> Poss a -> Poss a
    $ccompare :: forall a. Ord a => Poss a -> Poss a -> Ordering
    compare :: Poss a -> Poss a -> Ordering
    $c< :: forall a. Ord a => Poss a -> Poss a -> Bool
    < :: Poss a -> Poss a -> Bool
    $c<= :: forall a. Ord a => Poss a -> Poss a -> Bool
    <= :: Poss a -> Poss a -> Bool
    $c> :: forall a. Ord a => Poss a -> Poss a -> Bool
    > :: Poss a -> Poss a -> Bool
    $c>= :: forall a. Ord a => Poss a -> Poss a -> Bool
    >= :: Poss a -> Poss a -> Bool
    $cmax :: forall a. Ord a => Poss a -> Poss a -> Poss a
    max :: Poss a -> Poss a -> Poss a
    $cmin :: forall a. Ord a => Poss a -> Poss a -> Poss a
    min :: Poss a -> Poss a -> Poss a
    Ord,Int -> Poss a -> ShowS
    [Poss a] -> ShowS
    Poss a -> String
    (Int -> Poss a -> ShowS)
    -> (Poss a -> String) -> ([Poss a] -> ShowS) -> Show (Poss a)
    forall a. Show a => Int -> Poss a -> ShowS
    forall a. Show a => [Poss a] -> ShowS
    forall a. Show a => Poss a -> String
    forall a.
    (Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
    $cshowsPrec :: forall a. Show a => Int -> Poss a -> ShowS
    showsPrec :: Int -> Poss a -> ShowS
    $cshow :: forall a. Show a => Poss a -> String
    show :: Poss a -> String
    $cshowList :: forall a. Show a => [Poss a] -> ShowS
    showList :: [Poss a] -> ShowS
    Show)

    instance Functor Poss where
      fmap :: forall a b. (a -> b) -> Poss a -> Poss b
    fmap a -> b
    f Poss a
    p = case Poss a
    p of
        Eek String
    m -> String -> Poss b
    forall a. String -> Poss a
    Eek String
    m
        Yup a
    x -> b -> Poss b
    forall a. a -> Poss a
    Yup (b -> Poss b) -> b -> Poss b
    forall a b. (a -> b) -> a -> b
    $ a -> b
    f a
    x

    instance Applicative Poss where
      pure :: forall a. a -> Poss a
    pure        = a -> Poss a
    forall a. a -> Poss a
    Yup
      <*> :: forall a b. Poss (a -> b) -> Poss a -> Poss b
    (<*>) Poss (a -> b)
    p1 Poss a
    p2 = case Poss (a -> b)
    p1 of
        Eek String
    m -> String -> Poss b
    forall a. String -> Poss a
    Eek String
    m
        Yup a -> b
    f -> case Poss a
    p2 of
          Eek String
    n -> String -> Poss b
    forall a. String -> Poss a
    Eek String
    n
          Yup a
    x -> b -> Poss b
    forall a. a -> Poss a
    Yup (b -> Poss b) -> b -> Poss b
    forall a b. (a -> b) -> a -> b
    $ a -> b
    f a
    x

    instance Monad Poss where
      return :: forall a. a -> Poss a
    return = a -> Poss a
    forall a. a -> Poss a
    forall (f :: * -> *) a. Applicative f => a -> f a
    pure
      >>= :: forall a b. Poss a -> (a -> Poss b) -> Poss b
    (>>=) Poss a
    p a -> Poss b
    f = case Poss a
    p of
        Eek String
    m -> String -> Poss b
    forall a. String -> Poss a
    Eek String
    m
        Yup a
    x -> a -> Poss b
    f a
    x

    instance MonadFail Poss where
      fail :: forall a. String -> Poss a
    fail = String -> Poss a
    forall a. String -> Poss a
    Eek

    poss :: (String->b) -> (a->b) -> Poss a -> b
    poss :: forall b a. (String -> b) -> (a -> b) -> Poss a -> b
    poss String -> b
    f a -> b
    _ (Eek String
    s) = String -> b
    f String
    s
    poss String -> b
    _ a -> b
    g (Yup a
    x) = a -> b
    g a
    x

    poss2either :: Poss a -> Either String a
    poss2either :: forall a. Poss a -> Either String a
    poss2either (Eek String
    m) = String -> Either String a
    forall a b. a -> Either a b
    Left  String
    m
    poss2either (Yup a
    x) = a -> Either String a
    forall a b. b -> Either a b
    Right a
    x