-- Hoogle documentation, generated by Haddock
-- See Hoogle, http://www.haskell.org/hoogle/


-- | Open Union and Open Product Types
--   
--   Please see <a>README.md</a>.
@package world-peace
@version 0.1.0.0


-- | These functions are for working with Optics popularized by the
--   <a>lens</a> package. Documentation can be found in the lens package.
--   These functions are redefined here to remove the dependency on the
--   lens package.
module Data.WorldPeace.Internal.Prism
type Prism s t a b = forall p f. (Choice p, Applicative f) => p a (f b) -> p s (f t)
prism :: (b -> t) -> (s -> Either t a) -> Prism s t a b
type Prism' s a = Prism s s a a
prism' :: (a -> s) -> (s -> Maybe a) -> Prism' s a
type Iso s t a b = forall p f. (Profunctor p, Functor f) => p a (f b) -> p s (f t)
iso :: (s -> a) -> (b -> t) -> Iso s t a b
review :: Prism' t b -> b -> t
preview :: Prism' s a -> s -> Maybe a
(<>~) :: Monoid a => ASetter s t a a -> a -> s -> t
infixr 4 <>~

module Data.WorldPeace.Internal


-- | This module defines an open product type. This is used in the
--   case-analysis handler for the open sum type (<a>catchesUnion</a>).
module Data.WorldPeace.Product

-- | An extensible product type. This is similar to <a>Union</a>, except a
--   product type instead of a sum type.
data Product (f :: u -> *) (as :: [u])
[Nil] :: Product f '[]
[Cons] :: !(f a) -> Product f as -> Product f (a : as)

-- | This type class provides a way to turn a tuple into a <a>Product</a>.
class ToProduct (tuple :: *) (f :: u -> *) (as :: [u]) | f as -> tuple

-- | Convert a tuple into a <a>Product</a>. See <a>tupleToProduct</a> for
--   examples.
toProduct :: ToProduct tuple f as => tuple -> Product f as

-- | Convert a single value into a <a>Product</a>.

-- | Convert a tuple into a <a>Product</a>.

-- | Convert a 3-tuple into a <a>Product</a>.

-- | Convert a 4-tuple into a <a>Product</a>.

-- | Turn a tuple into a <a>Product</a>.
--   
--   <pre>
--   &gt;&gt;&gt; tupleToProduct (Identity 1, Identity 2.0) :: Product Identity '[Int, Double]
--   Cons (Identity 1) (Cons (Identity 2.0) Nil)
--   </pre>
tupleToProduct :: ToProduct t f as => t -> Product f as

-- | <tt><a>Product</a> <a>Identity</a></tt> is used as a standard open
--   product type.
type OpenProduct = Product Identity

-- | <a>ToOpenProduct</a> gives us a way to convert a tuple to an
--   <a>OpenProduct</a>. See <a>tupleToOpenProduct</a>.
class ToOpenProduct (tuple :: *) (as :: [*]) | as -> tuple
toOpenProduct :: ToOpenProduct tuple as => tuple -> OpenProduct as

-- | Convert a single value into an <a>OpenProduct</a>.

-- | Convert a tuple into an <a>OpenProduct</a>.

-- | Convert a 3-tuple into an <a>OpenProduct</a>.

-- | Convert a 4-tuple into an <a>OpenProduct</a>.

-- | Turn a tuple into an <a>OpenProduct</a>.
--   
--   <h4><b>Examples</b></h4>
--   
--   Turn a triple into an <a>OpenProduct</a>:
--   
--   <pre>
--   &gt;&gt;&gt; tupleToOpenProduct (1, 2.0, "hello") :: OpenProduct '[Int, Double, String]
--   Cons (Identity 1) (Cons (Identity 2.0) (Cons (Identity "hello") Nil))
--   </pre>
--   
--   Turn a single value into an <a>OpenProduct</a>:
--   
--   <pre>
--   &gt;&gt;&gt; tupleToOpenProduct 'c' :: OpenProduct '[Char]
--   Cons (Identity 'c') Nil
--   </pre>
tupleToOpenProduct :: ToOpenProduct t as => t -> OpenProduct as

-- | Show <a>Nil</a> values.

-- | Show <a>Cons</a> values.
instance Data.WorldPeace.Product.ToOpenProduct a '[a]
instance Data.WorldPeace.Product.ToOpenProduct (a, b) '[a, b]
instance Data.WorldPeace.Product.ToOpenProduct (a, b, c) '[a, b, c]
instance Data.WorldPeace.Product.ToOpenProduct (a, b, c, d) '[a, b, c, d]
instance forall u (f :: u -> *) (a :: u). Data.WorldPeace.Product.ToProduct (f a) f '[a]
instance forall u (f :: u -> *) (a :: u) (b :: u). Data.WorldPeace.Product.ToProduct (f a, f b) f '[a, b]
instance forall u (f :: u -> *) (a :: u) (b :: u) (c :: u). Data.WorldPeace.Product.ToProduct (f a, f b, f c) f '[a, b, c]
instance forall u (f :: u -> *) (a :: u) (b :: u) (c :: u) (d :: u). Data.WorldPeace.Product.ToProduct (f a, f b, f c, f d) f '[a, b, c, d]
instance forall u (f :: u -> *). GHC.Show.Show (Data.WorldPeace.Product.Product f '[])
instance forall a1 (f :: a1 -> *) (a2 :: a1) (as :: [a1]). (GHC.Show.Show (f a2), GHC.Show.Show (Data.WorldPeace.Product.Product f as)) => GHC.Show.Show (Data.WorldPeace.Product.Product f (a2 : as))


-- | This module defines extensible sum-types. This is similar to how
--   <a>vinyl</a> defines extensible records.
--   
--   A large portion of the code from this module was taken from the
--   <a>union</a> package.
module Data.WorldPeace.Union

-- | A <a>Union</a> is parameterized by a universe <tt>u</tt>, an
--   interpretation <tt>f</tt> and a list of labels <tt>as</tt>. The labels
--   of the union are given by inhabitants of the kind <tt>u</tt>; the type
--   of values at any label <tt>a :: u</tt> is given by its interpretation
--   <tt>f a :: *</tt>.
--   
--   What does this mean in practice? It means that a type like
--   <tt><a>Union</a> <a>Identity</a> '[<a>String</a>, <a>Int</a>]</tt> can
--   be _either_ an <tt><a>Identity</a> <a>String</a></tt> or an
--   <tt><a>Identity</a> <a>Int</a></tt>.
--   
--   You need to pattern match on the <a>This</a> and <a>That</a>
--   constructors to figure out whether you are holding a <a>String</a> or
--   <a>Int</a>:
--   
--   <pre>
--   &gt;&gt;&gt; let u = That (This (Identity 1)) :: Union Identity '[String, Int]
--   
--   &gt;&gt;&gt; :{
--     case u of
--       This (Identity str) -&gt; "we got a string: " ++ str
--       That (This (Identity int)) -&gt; "we got an int: " ++ show int
--   :}
--   "we got an int: 1"
--   </pre>
--   
--   There are multiple functions that let you perform this pattern
--   matching easier: <a>union</a>, <a>catchesUnion</a>, <a>unionMatch</a>
--   
--   There is also a type synonym <a>OpenUnion</a> for the common case of
--   <tt><a>Union</a> <tt>Indentity</tt></tt>, as well as helper functions
--   for working with it.
data Union (f :: u -> *) (as :: [u])
[This] :: !(f a) -> Union f (a : as)
[That] :: !(Union f as) -> Union f (a : as)

-- | Case analysis for <a>Union</a>.
--   
--   <h4><b>Examples</b></h4>
--   
--   Here is an example of matching on a <a>This</a>:
--   
--   <pre>
--   &gt;&gt;&gt; let u = This (Identity "hello") :: Union Identity '[String, Int]
--   
--   &gt;&gt;&gt; let runIdent = runIdentity :: Identity String -&gt; String
--   
--   &gt;&gt;&gt; union (const "not a String") runIdent u
--   "hello"
--   </pre>
--   
--   Here is an example of matching on a <a>That</a>:
--   
--   <pre>
--   &gt;&gt;&gt; let v = That (This (Identity 3.3)) :: Union Identity '[String, Double, Int]
--   
--   &gt;&gt;&gt; union (const "not a String") runIdent v
--   "not a String"
--   </pre>
union :: (Union f as -> c) -> (f a -> c) -> Union f (a : as) -> c

-- | An alternate case anaylsis for a <a>Union</a>. This method uses a
--   tuple containing handlers for each potential value of the
--   <a>Union</a>. This is somewhat similar to the <a>catches</a> function.
--   
--   <h4><b>Examples</b></h4>
--   
--   Here is an example of handling a <a>Union</a> with two possible
--   values. Notice that a normal tuple is used:
--   
--   <pre>
--   &gt;&gt;&gt; let u = This $ Identity 3 :: Union Identity '[Int, String]
--   
--   &gt;&gt;&gt; let intHandler = (Identity $ \int -&gt; show int) :: Identity (Int -&gt; String)
--   
--   &gt;&gt;&gt; let strHandler = (Identity $ \str -&gt; str) :: Identity (String -&gt; String)
--   
--   &gt;&gt;&gt; catchesUnion (intHandler, strHandler) u :: Identity String
--   Identity "3"
--   </pre>
--   
--   Given a <a>Union</a> like <tt><a>Union</a> <a>Identity</a>
--   '[<a>Int</a>, <a>String</a>]</tt>, the type of <a>catchesUnion</a>
--   becomes the following:
--   
--   <pre>
--   <a>catchesUnion</a>
--     :: (<a>Identity</a> (<a>Int</a> -&gt; <a>String</a>), <a>Identity</a> (<a>String</a> -&gt; <a>String</a>))
--     -&gt; <a>Union</a> <a>Identity</a> '[<a>Int</a>, <a>String</a>]
--     -&gt; <a>Identity</a> <a>String</a>
--   </pre>
--   
--   Checkout <a>catchesOpenUnion</a> for more examples.
catchesUnion :: (Applicative f, ToProduct tuple f (ReturnX x as)) => tuple -> Union f as -> f x

-- | Since a union with an empty list of labels is uninhabited, we can
--   recover any type from it.
absurdUnion :: Union f '[] -> a

-- | Map over the interpretation <tt>f</tt> in the <a>Union</a>.
--   
--   <h4><b>Examples</b></h4>
--   
--   Here is an example of changing a <tt><a>Union</a> <a>Identity</a>
--   '[<a>String</a>, <a>Int</a>]</tt> to <tt><a>Union</a> <a>Maybe</a>
--   '[<a>String</a>, <a>Int</a>]</tt>:
--   
--   <pre>
--   &gt;&gt;&gt; let u = This (Identity "hello") :: Union Identity '[String, Int]
--   
--   &gt;&gt;&gt; umap (Just . runIdentity) u :: Union Maybe '[String, Int]
--   Just "hello"
--   </pre>
umap :: (forall a. f a -> g a) -> Union f as -> Union g as

-- | Lens-compatible <a>Prism</a> for <a>This</a>.
--   
--   <h4><b>Examples</b></h4>
--   
--   Use <a>_This</a> to construct a <a>Union</a>:
--   
--   <pre>
--   &gt;&gt;&gt; review _This (Just "hello") :: Union Maybe '[String]
--   Just "hello"
--   </pre>
--   
--   Use <a>_This</a> to try to destruct a <a>Union</a> into a <tt>f
--   a</tt>:
--   
--   <pre>
--   &gt;&gt;&gt; let u = This (Identity "hello") :: Union Identity '[String, Int]
--   
--   &gt;&gt;&gt; preview _This u :: Maybe (Identity String)
--   Just (Identity "hello")
--   </pre>
--   
--   Use <a>_This</a> to try to destruct a <a>Union</a> into a <tt>f a</tt>
--   (unsuccessfully):
--   
--   <pre>
--   &gt;&gt;&gt; let v = That (This (Identity 3.3)) :: Union Identity '[String, Double, Int]
--   
--   &gt;&gt;&gt; preview _This v :: Maybe (Identity String)
--   Nothing
--   </pre>
_This :: Prism (Union f (a : as)) (Union f (b : as)) (f a) (f b)

-- | Lens-compatible <a>Prism</a> for <a>That</a>.
--   
--   <h4><b>Examples</b></h4>
--   
--   Use <a>_That</a> to construct a <a>Union</a>:
--   
--   <pre>
--   &gt;&gt;&gt; let u = This (Just "hello") :: Union Maybe '[String]
--   
--   &gt;&gt;&gt; review _That u :: Union Maybe '[Double, String]
--   Just "hello"
--   </pre>
--   
--   Use <a>_That</a> to try to peel off a <a>That</a> from a <a>Union</a>:
--   
--   <pre>
--   &gt;&gt;&gt; let v = That (This (Identity "hello")) :: Union Identity '[Int, String]
--   
--   &gt;&gt;&gt; preview _That v :: Maybe (Union Identity '[String])
--   Just (Identity "hello")
--   </pre>
--   
--   Use <a>_That</a> to try to peel off a <a>That</a> from a <a>Union</a>
--   (unsuccessfully):
--   
--   <pre>
--   &gt;&gt;&gt; let w = This (Identity 3.5) :: Union Identity '[Double, String]
--   
--   &gt;&gt;&gt; preview _That w :: Maybe (Union Identity '[String])
--   Nothing
--   </pre>
_That :: Prism (Union f (a : as)) (Union f (a : bs)) (Union f as) (Union f bs)

-- | A mere approximation of the natural numbers. And their image as lifted
--   by <tt>-XDataKinds</tt> corresponds to the actual natural numbers.
data Nat
Z :: Nat
S :: !Nat -> Nat

-- | A partial relation that gives the index of a value in a list.
--   
--   <h4><b>Examples</b></h4>
--   
--   Find the first item:
--   
--   <pre>
--   &gt;&gt;&gt; import Data.Type.Equality ((:~:)(Refl))
--   
--   &gt;&gt;&gt; Refl :: RIndex String '[String, Int] :~: 'Z
--   Refl
--   </pre>
--   
--   Find the third item:
--   
--   <pre>
--   &gt;&gt;&gt; Refl :: RIndex Char '[String, Int, Char] :~: 'S ('S 'Z)
--   Refl
--   </pre>

-- | Change a list of types into a list of functions that take the given
--   type and return <tt>x</tt>.
--   
--   <pre>
--   &gt;&gt;&gt; import Data.Type.Equality ((:~:)(Refl))
--   
--   &gt;&gt;&gt; Refl :: ReturnX Double '[String, Int] :~: '[String -&gt; Double, Int -&gt; Double]
--   Refl
--   </pre>
--   
--   Don't do anything with an empty list:
--   
--   <pre>
--   &gt;&gt;&gt; Refl :: ReturnX Double '[] :~: '[]
--   Refl
--   </pre>

-- | <tt><a>UElem</a> a as i</tt> provides a way to potentially get an
--   <tt>f a</tt> out of a <tt><a>Union</a> f as</tt> (<a>unionMatch</a>).
--   It also provides a way to create a <tt><a>Union</a> f as</tt> from an
--   <tt>f a</tt> (<a>unionLift</a>).
--   
--   This is safe because of the <a>RIndex</a> contraint. This
--   <a>RIndex</a> constraint tells us that there <i>actually is</i> an
--   <tt>a</tt> in <tt>as</tt> at index <tt>i</tt>.
--   
--   As an end-user, you should never need to implement an additional
--   instance of this typeclass.
class i ~ RIndex a as => UElem (a :: u) (as :: [u]) (i :: Nat)

-- | This is implemented as <tt><a>prism'</a> <a>unionLift</a>
--   <a>unionMatch</a></tt>.
unionPrism :: UElem a as i => Prism' (Union f as) (f a)

-- | This is implemented as <tt><a>review</a> <a>unionPrism</a></tt>.
unionLift :: UElem a as i => f a -> Union f as

-- | This is implemented as <tt><a>preview</a> <a>unionPrism</a></tt>.
unionMatch :: UElem a as i => Union f as -> Maybe (f a)

-- | This is a helpful <tt>Constraint</tt> synonym to assert that
--   <tt>a</tt> is a member of <tt>as</tt>. You can see how it is used in
--   functions like <a>openUnionLift</a>.
type IsMember (a :: u) (as :: [u]) = UElem a as (RIndex a as)

-- | We can use <tt><a>Union</a> <a>Identity</a></tt> as a standard open
--   sum type.
type OpenUnion = Union Identity

-- | Case analysis for <a>OpenUnion</a>.
--   
--   <h4><b>Examples</b></h4>
--   
--   Here is an example of successfully matching:
--   
--   <pre>
--   &gt;&gt;&gt; let string = "hello" :: String
--   
--   &gt;&gt;&gt; let o = openUnionLift string :: OpenUnion '[String, Int]
--   
--   &gt;&gt;&gt; openUnion (const "not a String") id o
--   "hello"
--   </pre>
--   
--   Here is an example of unsuccessfully matching:
--   
--   <pre>
--   &gt;&gt;&gt; let double = 3.3 :: Double
--   
--   &gt;&gt;&gt; let p = openUnionLift double :: OpenUnion '[String, Double, Int]
--   
--   &gt;&gt;&gt; openUnion (const "not a String") id p
--   "not a String"
--   </pre>
openUnion :: (OpenUnion as -> c) -> (a -> c) -> OpenUnion (a : as) -> c

-- | This is similar to <tt>fromMaybe</tt> for an <a>OpenUnion</a>.
--   
--   <h4><b>Examples</b></h4>
--   
--   Here is an example of successfully matching:
--   
--   <pre>
--   &gt;&gt;&gt; let string = "hello" :: String
--   
--   &gt;&gt;&gt; let o = openUnionLift string :: OpenUnion '[String, Int]
--   
--   &gt;&gt;&gt; fromOpenUnion (const "not a String") o
--   "hello"
--   </pre>
--   
--   Here is an example of unsuccessfully matching:
--   
--   <pre>
--   &gt;&gt;&gt; let double = 3.3 :: Double
--   
--   &gt;&gt;&gt; let p = openUnionLift double :: OpenUnion '[String, Double, Int]
--   
--   &gt;&gt;&gt; fromOpenUnion (const "not a String") p
--   "not a String"
--   </pre>
fromOpenUnion :: (OpenUnion as -> a) -> OpenUnion (a : as) -> a

-- | Flipped version of <a>fromOpenUnion</a>.
fromOpenUnionOr :: OpenUnion (a : as) -> (OpenUnion as -> a) -> a

-- | Just like <a>unionPrism</a> but for <a>OpenUnion</a>.
openUnionPrism :: forall a as. IsMember a as => Prism' (OpenUnion as) a

-- | Just like <a>unionLift</a> but for <a>OpenUnion</a>.
--   
--   Creating an <a>OpenUnion</a>:
--   
--   <pre>
--   &gt;&gt;&gt; let string = "hello" :: String
--   
--   &gt;&gt;&gt; openUnionLift string :: OpenUnion '[Double, String, Int]
--   Identity "hello"
--   </pre>
openUnionLift :: forall a as. IsMember a as => a -> OpenUnion as

-- | Just like <a>unionMatch</a> but for <a>OpenUnion</a>.
--   
--   <h4><b>Examples</b></h4>
--   
--   Successful matching:
--   
--   <pre>
--   &gt;&gt;&gt; let string = "hello" :: String
--   
--   &gt;&gt;&gt; let o = openUnionLift string :: OpenUnion '[Double, String, Int]
--   
--   &gt;&gt;&gt; openUnionMatch o :: Maybe String
--   Just "hello"
--   </pre>
--   
--   Failure matching:
--   
--   <pre>
--   &gt;&gt;&gt; let double = 3.3 :: Double
--   
--   &gt;&gt;&gt; let p = openUnionLift double :: OpenUnion '[Double, String]
--   
--   &gt;&gt;&gt; openUnionMatch p :: Maybe String
--   Nothing
--   </pre>
openUnionMatch :: forall a as. IsMember a as => OpenUnion as -> Maybe a

-- | An alternate case anaylsis for an <a>OpenUnion</a>. This method uses a
--   tuple containing handlers for each potential value of the
--   <a>OpenUnion</a>. This is somewhat similar to the <a>catches</a>
--   function.
--   
--   When working with large <a>OpenUnion</a>s, it can be easier to use
--   <a>catchesOpenUnion</a> than <a>openUnion</a>.
--   
--   <h4><b>Examples</b></h4>
--   
--   Here is an example of handling an <a>OpenUnion</a> with two possible
--   values. Notice that a normal tuple is used:
--   
--   <pre>
--   &gt;&gt;&gt; let u = openUnionLift (3 :: Int) :: OpenUnion '[Int, String]
--   
--   &gt;&gt;&gt; let intHandler = (\int -&gt; show int) :: Int -&gt; String
--   
--   &gt;&gt;&gt; let strHandler = (\str -&gt; str) :: String -&gt; String
--   
--   &gt;&gt;&gt; catchesOpenUnion (intHandler, strHandler) u :: String
--   "3"
--   </pre>
--   
--   Given an <a>OpenUnion</a> like <tt><a>OpenUnion</a> '[<a>Int</a>,
--   <a>String</a>]</tt>, the type of <a>catchesOpenUnion</a> becomes the
--   following:
--   
--   <pre>
--   <a>catchesOpenUnion</a>
--     :: (<a>Int</a> -&gt; x, <a>String</a> -&gt; x)
--     -&gt; <a>OpenUnion</a> '[<a>Int</a>, <a>String</a>]
--     -&gt; x
--   </pre>
--   
--   Here is an example of handling an <a>OpenUnion</a> with three possible
--   values:
--   
--   <pre>
--   &gt;&gt;&gt; let u = openUnionLift ("hello" :: String) :: OpenUnion '[Int, String, Double]
--   
--   &gt;&gt;&gt; let intHandler = (\int -&gt; show int) :: Int -&gt; String
--   
--   &gt;&gt;&gt; let strHandler = (\str -&gt; str) :: String -&gt; String
--   
--   &gt;&gt;&gt; let dblHandler = (\dbl -&gt; "got a double") :: Double -&gt; String
--   
--   &gt;&gt;&gt; catchesOpenUnion (intHandler, strHandler, dblHandler) u :: String
--   "hello"
--   </pre>
--   
--   Here is an example of handling an <a>OpenUnion</a> with only one
--   possible value. Notice how a tuple is not used, just a single value:
--   
--   <pre>
--   &gt;&gt;&gt; let u = openUnionLift (2.2 :: Double) :: OpenUnion '[Double]
--   
--   &gt;&gt;&gt; let dblHandler = (\dbl -&gt; "got a double") :: Double -&gt; String
--   
--   &gt;&gt;&gt; catchesOpenUnion dblHandler u :: String
--   "got a double"
--   </pre>
catchesOpenUnion :: ToOpenProduct tuple (ReturnX x as) => tuple -> OpenUnion as -> x
instance forall a1 (a2 :: a1) (as :: [a1]). Data.WorldPeace.Union.UElem a2 (a2 : as) 'Data.WorldPeace.Union.Z
instance forall a1 (a2 :: a1) (b :: a1) (as :: [a1]) (i :: Data.WorldPeace.Union.Nat). (Data.WorldPeace.Union.RIndex a2 (b : as) ~ 'Data.WorldPeace.Union.S i, Data.WorldPeace.Union.UElem a2 as i) => Data.WorldPeace.Union.UElem a2 (b : as) ('Data.WorldPeace.Union.S i)
instance forall u (f :: u -> *). Control.DeepSeq.NFData (Data.WorldPeace.Union.Union f '[])
instance forall a1 (f :: a1 -> *) (a2 :: a1) (as :: [a1]). (Control.DeepSeq.NFData (f a2), Control.DeepSeq.NFData (Data.WorldPeace.Union.Union f as)) => Control.DeepSeq.NFData (Data.WorldPeace.Union.Union f (a2 : as))
instance forall u (f :: u -> *). GHC.Show.Show (Data.WorldPeace.Union.Union f '[])
instance forall a1 (f :: a1 -> *) (a2 :: a1) (as :: [a1]). (GHC.Show.Show (f a2), GHC.Show.Show (Data.WorldPeace.Union.Union f as)) => GHC.Show.Show (Data.WorldPeace.Union.Union f (a2 : as))
instance forall u (f :: u -> *). GHC.Read.Read (Data.WorldPeace.Union.Union f '[])
instance forall a1 (f :: a1 -> *) (a2 :: a1) (as :: [a1]). (GHC.Read.Read (f a2), GHC.Read.Read (Data.WorldPeace.Union.Union f as)) => GHC.Read.Read (Data.WorldPeace.Union.Union f (a2 : as))
instance forall u (f :: u -> *). GHC.Classes.Eq (Data.WorldPeace.Union.Union f '[])
instance forall a1 (f :: a1 -> *) (a2 :: a1) (as :: [a1]). (GHC.Classes.Eq (f a2), GHC.Classes.Eq (Data.WorldPeace.Union.Union f as)) => GHC.Classes.Eq (Data.WorldPeace.Union.Union f (a2 : as))
instance forall u (f :: u -> *). GHC.Classes.Ord (Data.WorldPeace.Union.Union f '[])
instance forall a1 (f :: a1 -> *) (a2 :: a1) (as :: [a1]). (GHC.Classes.Ord (f a2), GHC.Classes.Ord (Data.WorldPeace.Union.Union f as)) => GHC.Classes.Ord (Data.WorldPeace.Union.Union f (a2 : as))
instance forall u (f :: u -> *). Data.Aeson.Types.ToJSON.ToJSON (Data.WorldPeace.Union.Union f '[])
instance forall a1 (f :: a1 -> *) (a2 :: a1) (as :: [a1]). (Data.Aeson.Types.ToJSON.ToJSON (f a2), Data.Aeson.Types.ToJSON.ToJSON (Data.WorldPeace.Union.Union f as)) => Data.Aeson.Types.ToJSON.ToJSON (Data.WorldPeace.Union.Union f (a2 : as))
instance forall u (f :: u -> *). Data.Aeson.Types.FromJSON.FromJSON (Data.WorldPeace.Union.Union f '[])
instance forall a1 (f :: a1 -> *) (a2 :: a1) (as :: [a1]). (Data.Aeson.Types.FromJSON.FromJSON (f a2), Data.Aeson.Types.FromJSON.FromJSON (Data.WorldPeace.Union.Union f as)) => Data.Aeson.Types.FromJSON.FromJSON (Data.WorldPeace.Union.Union f (a2 : as))


-- | This package defines a type called <a>OpenUnion</a>. This represents
--   an open union of possible types (also called an open sum type).
--   
--   Here is an example of taking a <a>String</a>, and lifting it up into
--   an open union of a <a>String</a> and <a>Int</a>:
--   
--   <pre>
--   let int = 3 :: <a>Int</a>
--   let o = <a>openUnionLift</a> int :: <a>OpenUnion</a> '[<a>String</a>, <a>Int</a>]
--   </pre>
--   
--   There are a couple different ways to pattern match on a
--   <a>OpenUnion</a>.
--   
--   The easiest one is to use <a>catchesOpenUnion</a>, which takes a tuple
--   of handlers for each possible type in the <a>OpenUnion</a>:
--   
--   <pre>
--   let strHandler = (str -&gt; "got a String: " <a>++</a> str) :: <a>String</a> -&gt; <a>String</a>
--       intHandler = (int -&gt; "got an Int: " <a>++</a> <a>show</a> int) :: <a>Int</a> -&gt; <a>String</a>
--   in <a>catchesOpenUnion</a> (strHandler, intHandler) u :: <a>String</a>
--   </pre>
--   
--   The above will print <tt>got an Int: 3</tt>.
--   
--   There is also the <a>openUnionMatch</a> function, as well as
--   <a>fromOpenUnion</a> and <a>openUnion</a>. Read the documentation
--   below for more information.
module Data.WorldPeace

-- | We can use <tt><a>Union</a> <a>Identity</a></tt> as a standard open
--   sum type.
type OpenUnion = Union Identity

-- | Case analysis for <a>OpenUnion</a>.
--   
--   <h4><b>Examples</b></h4>
--   
--   Here is an example of successfully matching:
--   
--   <pre>
--   &gt;&gt;&gt; let string = "hello" :: String
--   
--   &gt;&gt;&gt; let o = openUnionLift string :: OpenUnion '[String, Int]
--   
--   &gt;&gt;&gt; openUnion (const "not a String") id o
--   "hello"
--   </pre>
--   
--   Here is an example of unsuccessfully matching:
--   
--   <pre>
--   &gt;&gt;&gt; let double = 3.3 :: Double
--   
--   &gt;&gt;&gt; let p = openUnionLift double :: OpenUnion '[String, Double, Int]
--   
--   &gt;&gt;&gt; openUnion (const "not a String") id p
--   "not a String"
--   </pre>
openUnion :: (OpenUnion as -> c) -> (a -> c) -> OpenUnion (a : as) -> c

-- | This is similar to <tt>fromMaybe</tt> for an <a>OpenUnion</a>.
--   
--   <h4><b>Examples</b></h4>
--   
--   Here is an example of successfully matching:
--   
--   <pre>
--   &gt;&gt;&gt; let string = "hello" :: String
--   
--   &gt;&gt;&gt; let o = openUnionLift string :: OpenUnion '[String, Int]
--   
--   &gt;&gt;&gt; fromOpenUnion (const "not a String") o
--   "hello"
--   </pre>
--   
--   Here is an example of unsuccessfully matching:
--   
--   <pre>
--   &gt;&gt;&gt; let double = 3.3 :: Double
--   
--   &gt;&gt;&gt; let p = openUnionLift double :: OpenUnion '[String, Double, Int]
--   
--   &gt;&gt;&gt; fromOpenUnion (const "not a String") p
--   "not a String"
--   </pre>
fromOpenUnion :: (OpenUnion as -> a) -> OpenUnion (a : as) -> a

-- | Flipped version of <a>fromOpenUnion</a>.
fromOpenUnionOr :: OpenUnion (a : as) -> (OpenUnion as -> a) -> a

-- | Just like <a>unionPrism</a> but for <a>OpenUnion</a>.
openUnionPrism :: forall a as. IsMember a as => Prism' (OpenUnion as) a

-- | Just like <a>unionLift</a> but for <a>OpenUnion</a>.
--   
--   Creating an <a>OpenUnion</a>:
--   
--   <pre>
--   &gt;&gt;&gt; let string = "hello" :: String
--   
--   &gt;&gt;&gt; openUnionLift string :: OpenUnion '[Double, String, Int]
--   Identity "hello"
--   </pre>
openUnionLift :: forall a as. IsMember a as => a -> OpenUnion as

-- | Just like <a>unionMatch</a> but for <a>OpenUnion</a>.
--   
--   <h4><b>Examples</b></h4>
--   
--   Successful matching:
--   
--   <pre>
--   &gt;&gt;&gt; let string = "hello" :: String
--   
--   &gt;&gt;&gt; let o = openUnionLift string :: OpenUnion '[Double, String, Int]
--   
--   &gt;&gt;&gt; openUnionMatch o :: Maybe String
--   Just "hello"
--   </pre>
--   
--   Failure matching:
--   
--   <pre>
--   &gt;&gt;&gt; let double = 3.3 :: Double
--   
--   &gt;&gt;&gt; let p = openUnionLift double :: OpenUnion '[Double, String]
--   
--   &gt;&gt;&gt; openUnionMatch p :: Maybe String
--   Nothing
--   </pre>
openUnionMatch :: forall a as. IsMember a as => OpenUnion as -> Maybe a

-- | An alternate case anaylsis for an <a>OpenUnion</a>. This method uses a
--   tuple containing handlers for each potential value of the
--   <a>OpenUnion</a>. This is somewhat similar to the <a>catches</a>
--   function.
--   
--   When working with large <a>OpenUnion</a>s, it can be easier to use
--   <a>catchesOpenUnion</a> than <a>openUnion</a>.
--   
--   <h4><b>Examples</b></h4>
--   
--   Here is an example of handling an <a>OpenUnion</a> with two possible
--   values. Notice that a normal tuple is used:
--   
--   <pre>
--   &gt;&gt;&gt; let u = openUnionLift (3 :: Int) :: OpenUnion '[Int, String]
--   
--   &gt;&gt;&gt; let intHandler = (\int -&gt; show int) :: Int -&gt; String
--   
--   &gt;&gt;&gt; let strHandler = (\str -&gt; str) :: String -&gt; String
--   
--   &gt;&gt;&gt; catchesOpenUnion (intHandler, strHandler) u :: String
--   "3"
--   </pre>
--   
--   Given an <a>OpenUnion</a> like <tt><a>OpenUnion</a> '[<a>Int</a>,
--   <a>String</a>]</tt>, the type of <a>catchesOpenUnion</a> becomes the
--   following:
--   
--   <pre>
--   <a>catchesOpenUnion</a>
--     :: (<a>Int</a> -&gt; x, <a>String</a> -&gt; x)
--     -&gt; <a>OpenUnion</a> '[<a>Int</a>, <a>String</a>]
--     -&gt; x
--   </pre>
--   
--   Here is an example of handling an <a>OpenUnion</a> with three possible
--   values:
--   
--   <pre>
--   &gt;&gt;&gt; let u = openUnionLift ("hello" :: String) :: OpenUnion '[Int, String, Double]
--   
--   &gt;&gt;&gt; let intHandler = (\int -&gt; show int) :: Int -&gt; String
--   
--   &gt;&gt;&gt; let strHandler = (\str -&gt; str) :: String -&gt; String
--   
--   &gt;&gt;&gt; let dblHandler = (\dbl -&gt; "got a double") :: Double -&gt; String
--   
--   &gt;&gt;&gt; catchesOpenUnion (intHandler, strHandler, dblHandler) u :: String
--   "hello"
--   </pre>
--   
--   Here is an example of handling an <a>OpenUnion</a> with only one
--   possible value. Notice how a tuple is not used, just a single value:
--   
--   <pre>
--   &gt;&gt;&gt; let u = openUnionLift (2.2 :: Double) :: OpenUnion '[Double]
--   
--   &gt;&gt;&gt; let dblHandler = (\dbl -&gt; "got a double") :: Double -&gt; String
--   
--   &gt;&gt;&gt; catchesOpenUnion dblHandler u :: String
--   "got a double"
--   </pre>
catchesOpenUnion :: ToOpenProduct tuple (ReturnX x as) => tuple -> OpenUnion as -> x

-- | This is a helpful <tt>Constraint</tt> synonym to assert that
--   <tt>a</tt> is a member of <tt>as</tt>. You can see how it is used in
--   functions like <a>openUnionLift</a>.
type IsMember (a :: u) (as :: [u]) = UElem a as (RIndex a as)

-- | A <a>Union</a> is parameterized by a universe <tt>u</tt>, an
--   interpretation <tt>f</tt> and a list of labels <tt>as</tt>. The labels
--   of the union are given by inhabitants of the kind <tt>u</tt>; the type
--   of values at any label <tt>a :: u</tt> is given by its interpretation
--   <tt>f a :: *</tt>.
--   
--   What does this mean in practice? It means that a type like
--   <tt><a>Union</a> <a>Identity</a> '[<a>String</a>, <a>Int</a>]</tt> can
--   be _either_ an <tt><a>Identity</a> <a>String</a></tt> or an
--   <tt><a>Identity</a> <a>Int</a></tt>.
--   
--   You need to pattern match on the <a>This</a> and <a>That</a>
--   constructors to figure out whether you are holding a <a>String</a> or
--   <a>Int</a>:
--   
--   <pre>
--   &gt;&gt;&gt; let u = That (This (Identity 1)) :: Union Identity '[String, Int]
--   
--   &gt;&gt;&gt; :{
--     case u of
--       This (Identity str) -&gt; "we got a string: " ++ str
--       That (This (Identity int)) -&gt; "we got an int: " ++ show int
--   :}
--   "we got an int: 1"
--   </pre>
--   
--   There are multiple functions that let you perform this pattern
--   matching easier: <a>union</a>, <a>catchesUnion</a>, <a>unionMatch</a>
--   
--   There is also a type synonym <a>OpenUnion</a> for the common case of
--   <tt><a>Union</a> <tt>Indentity</tt></tt>, as well as helper functions
--   for working with it.
data Union (f :: u -> *) (as :: [u])
[This] :: !(f a) -> Union f (a : as)
[That] :: !(Union f as) -> Union f (a : as)

-- | Case analysis for <a>Union</a>.
--   
--   <h4><b>Examples</b></h4>
--   
--   Here is an example of matching on a <a>This</a>:
--   
--   <pre>
--   &gt;&gt;&gt; let u = This (Identity "hello") :: Union Identity '[String, Int]
--   
--   &gt;&gt;&gt; let runIdent = runIdentity :: Identity String -&gt; String
--   
--   &gt;&gt;&gt; union (const "not a String") runIdent u
--   "hello"
--   </pre>
--   
--   Here is an example of matching on a <a>That</a>:
--   
--   <pre>
--   &gt;&gt;&gt; let v = That (This (Identity 3.3)) :: Union Identity '[String, Double, Int]
--   
--   &gt;&gt;&gt; union (const "not a String") runIdent v
--   "not a String"
--   </pre>
union :: (Union f as -> c) -> (f a -> c) -> Union f (a : as) -> c

-- | Since a union with an empty list of labels is uninhabited, we can
--   recover any type from it.
absurdUnion :: Union f '[] -> a

-- | Map over the interpretation <tt>f</tt> in the <a>Union</a>.
--   
--   <h4><b>Examples</b></h4>
--   
--   Here is an example of changing a <tt><a>Union</a> <a>Identity</a>
--   '[<a>String</a>, <a>Int</a>]</tt> to <tt><a>Union</a> <a>Maybe</a>
--   '[<a>String</a>, <a>Int</a>]</tt>:
--   
--   <pre>
--   &gt;&gt;&gt; let u = This (Identity "hello") :: Union Identity '[String, Int]
--   
--   &gt;&gt;&gt; umap (Just . runIdentity) u :: Union Maybe '[String, Int]
--   Just "hello"
--   </pre>
umap :: (forall a. f a -> g a) -> Union f as -> Union g as

-- | An alternate case anaylsis for a <a>Union</a>. This method uses a
--   tuple containing handlers for each potential value of the
--   <a>Union</a>. This is somewhat similar to the <a>catches</a> function.
--   
--   <h4><b>Examples</b></h4>
--   
--   Here is an example of handling a <a>Union</a> with two possible
--   values. Notice that a normal tuple is used:
--   
--   <pre>
--   &gt;&gt;&gt; let u = This $ Identity 3 :: Union Identity '[Int, String]
--   
--   &gt;&gt;&gt; let intHandler = (Identity $ \int -&gt; show int) :: Identity (Int -&gt; String)
--   
--   &gt;&gt;&gt; let strHandler = (Identity $ \str -&gt; str) :: Identity (String -&gt; String)
--   
--   &gt;&gt;&gt; catchesUnion (intHandler, strHandler) u :: Identity String
--   Identity "3"
--   </pre>
--   
--   Given a <a>Union</a> like <tt><a>Union</a> <a>Identity</a>
--   '[<a>Int</a>, <a>String</a>]</tt>, the type of <a>catchesUnion</a>
--   becomes the following:
--   
--   <pre>
--   <a>catchesUnion</a>
--     :: (<a>Identity</a> (<a>Int</a> -&gt; <a>String</a>), <a>Identity</a> (<a>String</a> -&gt; <a>String</a>))
--     -&gt; <a>Union</a> <a>Identity</a> '[<a>Int</a>, <a>String</a>]
--     -&gt; <a>Identity</a> <a>String</a>
--   </pre>
--   
--   Checkout <a>catchesOpenUnion</a> for more examples.
catchesUnion :: (Applicative f, ToProduct tuple f (ReturnX x as)) => tuple -> Union f as -> f x

-- | Lens-compatible <a>Prism</a> for <a>This</a>.
--   
--   <h4><b>Examples</b></h4>
--   
--   Use <a>_This</a> to construct a <a>Union</a>:
--   
--   <pre>
--   &gt;&gt;&gt; review _This (Just "hello") :: Union Maybe '[String]
--   Just "hello"
--   </pre>
--   
--   Use <a>_This</a> to try to destruct a <a>Union</a> into a <tt>f
--   a</tt>:
--   
--   <pre>
--   &gt;&gt;&gt; let u = This (Identity "hello") :: Union Identity '[String, Int]
--   
--   &gt;&gt;&gt; preview _This u :: Maybe (Identity String)
--   Just (Identity "hello")
--   </pre>
--   
--   Use <a>_This</a> to try to destruct a <a>Union</a> into a <tt>f a</tt>
--   (unsuccessfully):
--   
--   <pre>
--   &gt;&gt;&gt; let v = That (This (Identity 3.3)) :: Union Identity '[String, Double, Int]
--   
--   &gt;&gt;&gt; preview _This v :: Maybe (Identity String)
--   Nothing
--   </pre>
_This :: Prism (Union f (a : as)) (Union f (b : as)) (f a) (f b)

-- | Lens-compatible <a>Prism</a> for <a>That</a>.
--   
--   <h4><b>Examples</b></h4>
--   
--   Use <a>_That</a> to construct a <a>Union</a>:
--   
--   <pre>
--   &gt;&gt;&gt; let u = This (Just "hello") :: Union Maybe '[String]
--   
--   &gt;&gt;&gt; review _That u :: Union Maybe '[Double, String]
--   Just "hello"
--   </pre>
--   
--   Use <a>_That</a> to try to peel off a <a>That</a> from a <a>Union</a>:
--   
--   <pre>
--   &gt;&gt;&gt; let v = That (This (Identity "hello")) :: Union Identity '[Int, String]
--   
--   &gt;&gt;&gt; preview _That v :: Maybe (Union Identity '[String])
--   Just (Identity "hello")
--   </pre>
--   
--   Use <a>_That</a> to try to peel off a <a>That</a> from a <a>Union</a>
--   (unsuccessfully):
--   
--   <pre>
--   &gt;&gt;&gt; let w = This (Identity 3.5) :: Union Identity '[Double, String]
--   
--   &gt;&gt;&gt; preview _That w :: Maybe (Union Identity '[String])
--   Nothing
--   </pre>
_That :: Prism (Union f (a : as)) (Union f (a : bs)) (Union f as) (Union f bs)

-- | A mere approximation of the natural numbers. And their image as lifted
--   by <tt>-XDataKinds</tt> corresponds to the actual natural numbers.
data Nat
Z :: Nat
S :: !Nat -> Nat

-- | A partial relation that gives the index of a value in a list.
--   
--   <h4><b>Examples</b></h4>
--   
--   Find the first item:
--   
--   <pre>
--   &gt;&gt;&gt; import Data.Type.Equality ((:~:)(Refl))
--   
--   &gt;&gt;&gt; Refl :: RIndex String '[String, Int] :~: 'Z
--   Refl
--   </pre>
--   
--   Find the third item:
--   
--   <pre>
--   &gt;&gt;&gt; Refl :: RIndex Char '[String, Int, Char] :~: 'S ('S 'Z)
--   Refl
--   </pre>

-- | <tt><a>UElem</a> a as i</tt> provides a way to potentially get an
--   <tt>f a</tt> out of a <tt><a>Union</a> f as</tt> (<a>unionMatch</a>).
--   It also provides a way to create a <tt><a>Union</a> f as</tt> from an
--   <tt>f a</tt> (<a>unionLift</a>).
--   
--   This is safe because of the <a>RIndex</a> contraint. This
--   <a>RIndex</a> constraint tells us that there <i>actually is</i> an
--   <tt>a</tt> in <tt>as</tt> at index <tt>i</tt>.
--   
--   As an end-user, you should never need to implement an additional
--   instance of this typeclass.
class i ~ RIndex a as => UElem (a :: u) (as :: [u]) (i :: Nat)

-- | This is implemented as <tt><a>prism'</a> <a>unionLift</a>
--   <a>unionMatch</a></tt>.
unionPrism :: UElem a as i => Prism' (Union f as) (f a)

-- | This is implemented as <tt><a>review</a> <a>unionPrism</a></tt>.
unionLift :: UElem a as i => f a -> Union f as

-- | This is implemented as <tt><a>preview</a> <a>unionPrism</a></tt>.
unionMatch :: UElem a as i => Union f as -> Maybe (f a)

-- | <tt><a>Product</a> <a>Identity</a></tt> is used as a standard open
--   product type.
type OpenProduct = Product Identity

-- | An extensible product type. This is similar to <a>Union</a>, except a
--   product type instead of a sum type.
data Product (f :: u -> *) (as :: [u])
[Nil] :: Product f '[]
[Cons] :: !(f a) -> Product f as -> Product f (a : as)

-- | <a>ToOpenProduct</a> gives us a way to convert a tuple to an
--   <a>OpenProduct</a>. See <a>tupleToOpenProduct</a>.
class ToOpenProduct (tuple :: *) (as :: [*]) | as -> tuple

-- | Turn a tuple into an <a>OpenProduct</a>.
--   
--   <h4><b>Examples</b></h4>
--   
--   Turn a triple into an <a>OpenProduct</a>:
--   
--   <pre>
--   &gt;&gt;&gt; tupleToOpenProduct (1, 2.0, "hello") :: OpenProduct '[Int, Double, String]
--   Cons (Identity 1) (Cons (Identity 2.0) (Cons (Identity "hello") Nil))
--   </pre>
--   
--   Turn a single value into an <a>OpenProduct</a>:
--   
--   <pre>
--   &gt;&gt;&gt; tupleToOpenProduct 'c' :: OpenProduct '[Char]
--   Cons (Identity 'c') Nil
--   </pre>
tupleToOpenProduct :: ToOpenProduct t as => t -> OpenProduct as

-- | This type class provides a way to turn a tuple into a <a>Product</a>.
class ToProduct (tuple :: *) (f :: u -> *) (as :: [u]) | f as -> tuple

-- | Turn a tuple into a <a>Product</a>.
--   
--   <pre>
--   &gt;&gt;&gt; tupleToProduct (Identity 1, Identity 2.0) :: Product Identity '[Int, Double]
--   Cons (Identity 1) (Cons (Identity 2.0) Nil)
--   </pre>
tupleToProduct :: ToProduct t f as => t -> Product f as

-- | Change a list of types into a list of functions that take the given
--   type and return <tt>x</tt>.
--   
--   <pre>
--   &gt;&gt;&gt; import Data.Type.Equality ((:~:)(Refl))
--   
--   &gt;&gt;&gt; Refl :: ReturnX Double '[String, Int] :~: '[String -&gt; Double, Int -&gt; Double]
--   Refl
--   </pre>
--   
--   Don't do anything with an empty list:
--   
--   <pre>
--   &gt;&gt;&gt; Refl :: ReturnX Double '[] :~: '[]
--   Refl
--   </pre>
