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


-- | Convert values from one type into another.
--   
--   Witch converts values from one type into another.
@package witch
@version 0.2.0.2

module Witch.Cast

-- | This type class is for converting values from some <tt>source</tt>
--   type into some other <tt>target</tt> type. The constraint <tt>Cast
--   source target</tt> measn that you can convert from a value of type
--   <tt>source</tt> into a value of type <tt>target</tt>.
--   
--   This type class is for conversions that cannot fail. If your
--   conversion can fail, consider implementing <tt>TryCast</tt> instead.
class Cast source target

-- | This method implements the conversion of a value between types. At
--   call sites you will usually want to use <tt>from</tt> or <tt>into</tt>
--   instead of this method.
--   
--   The default implementation of this method simply calls <a>coerce</a>,
--   which works for types that have the same runtime representation. This
--   means that for <tt>newtype</tt>s you do not need to implement this
--   method at all. For example:
--   
--   <pre>
--   &gt;&gt;&gt; newtype Name = Name String
--   
--   &gt;&gt;&gt; instance Cast Name String
--   
--   &gt;&gt;&gt; instance Cast String Name
--   </pre>
cast :: Cast source target => source -> target

-- | This method implements the conversion of a value between types. At
--   call sites you will usually want to use <tt>from</tt> or <tt>into</tt>
--   instead of this method.
--   
--   The default implementation of this method simply calls <a>coerce</a>,
--   which works for types that have the same runtime representation. This
--   means that for <tt>newtype</tt>s you do not need to implement this
--   method at all. For example:
--   
--   <pre>
--   &gt;&gt;&gt; newtype Name = Name String
--   
--   &gt;&gt;&gt; instance Cast Name String
--   
--   &gt;&gt;&gt; instance Cast String Name
--   </pre>
cast :: (Cast source target, Coercible source target) => source -> target

module Witch.Identity

-- | This is an ugly hack used to make GHC require type applications for
--   certain functions. See this Twitter thread for a discussion:
--   <a>https://twitter.com/taylorfausak/status/1329084033003782148</a>.
type family Identity a

-- | Never use this type for anything! It only exists to make the
--   <a>Identity</a> type family non-trivial.
data Never

module Witch.TryCastException

-- | This exception is thrown when a <tt>TryCast</tt> conversion fails. It
--   has the original <tt>source</tt> value that caused the failure and it
--   knows the <tt>target</tt> type it was trying to convert into. It also
--   has an optional <a>SomeException</a> for communicating what went wrong
--   while converting.
data TryCastException source target
TryCastException :: source -> Maybe SomeException -> TryCastException source target
instance (GHC.Show.Show source, Data.Typeable.Internal.Typeable source, Data.Typeable.Internal.Typeable target) => GHC.Show.Show (Witch.TryCastException.TryCastException source target)
instance (GHC.Show.Show source, Data.Typeable.Internal.Typeable source, Data.Typeable.Internal.Typeable target) => GHC.Exception.Type.Exception (Witch.TryCastException.TryCastException source target)

module Witch.TryCast

-- | This type class is for converting values from some <tt>source</tt>
--   type into some other <tt>target</tt> type. The constraint <tt>TryCast
--   source target</tt> means that you may be able to convert from a value
--   of type <tt>source</tt> into a value of type <tt>target</tt>, but that
--   conversion may fail at runtime.
--   
--   This type class is for conversions that can fail. If your conversion
--   cannot fail, consider implementing <tt>Cast</tt> instead.
class TryCast source target

-- | This method implements the conversion of a value between types. At
--   call sites you will usually want to use <tt>tryFrom</tt> or
--   <tt>tryInto</tt> instead of this method.
tryCast :: TryCast source target => source -> Either (TryCastException source target) target

module Witch.Utility

-- | This is the same as <a>id</a> except that it requires a type
--   application. This can be an ergonomic way to pin down a polymorphic
--   type in a function pipeline. For example:
--   
--   <pre>
--   -- Avoid this:
--   f . (\ x -&gt; x :: Int) . g
--   
--   -- Prefer this:
--   f . as @Int . g
--   </pre>
as :: forall s source. Identity s ~ source => source -> source

-- | This is the same as <a>cast</a> except that it requires a type
--   application for the <tt>source</tt> type.
--   
--   <pre>
--   -- Avoid this:
--   cast (x :: s)
--   
--   -- Prefer this:
--   from @s x
--   </pre>
from :: forall s target source. (Identity s ~ source, Cast source target) => source -> target

-- | This is the same as <a>cast</a> except that it requires a type
--   application for the <tt>target</tt> type.
--   
--   <pre>
--   -- Avoid this:
--   cast x :: t
--   
--   -- Prefer this:
--   into @t x
--   </pre>
into :: forall t source target. (Identity t ~ target, Cast source target) => source -> target

-- | This function converts from some <tt>source</tt> type into some
--   <tt>target</tt> type, applies the given function, then converts back
--   into the <tt>source</tt> type. This is useful when you have two types
--   that are isomorphic but some function that only works with one of
--   them.
--   
--   <pre>
--   -- Avoid this:
--   from @t . f . from @s
--   
--   -- Prefer this:
--   over @t f
--   </pre>
over :: forall t source target. (Identity t ~ target, Cast source target, Cast target source) => (target -> target) -> source -> source

-- | This function first converts from some <tt>source</tt> type into some
--   <tt>through</tt> type, and then converts that into some
--   <tt>target</tt> type. Usually this is used when writing <a>Cast</a>
--   instances. Sometimes this can be used to work around the lack of an
--   instance that should probably exist.
--   
--   <pre>
--   -- Avoid this:
--   from @u . into @u
--   
--   -- Prefer this:
--   via @u
--   </pre>
via :: forall u source target through. (Identity u ~ through, Cast source through, Cast through target) => source -> target

-- | This is the same as <a>tryCast</a> except that it requires a type
--   application for the <tt>source</tt> type.
--   
--   <pre>
--   -- Avoid this:
--   tryCast (x :: s)
--   
--   -- Prefer this:
--   tryFrom @s x
--   </pre>
tryFrom :: forall s target source. (Identity s ~ source, TryCast source target) => source -> Either (TryCastException source target) target

-- | This is the same as <a>tryCast</a> except that it requires a type
--   application for the <tt>target</tt> type.
--   
--   <pre>
--   -- Avoid this:
--   tryCast x :: Either (TryCastException s t) t
--   
--   -- Prefer this:
--   tryInto @t x
--   </pre>
tryInto :: forall t source target. (Identity t ~ target, TryCast source target) => source -> Either (TryCastException source target) target

-- | This function can be used to implement <a>tryCast</a> with a function
--   that returns <a>Maybe</a>. For example:
--   
--   <pre>
--   -- Avoid this:
--   tryCast s = case f s of
--     Nothing -&gt; Left $ TryCastException s Nothing
--     Just t -&gt; Right t
--   
--   -- Prefer this:
--   tryCast = maybeTryCast f
--   </pre>
maybeTryCast :: (source -> Maybe target) -> source -> Either (TryCastException source target) target

-- | This function can be used to implement <a>tryCast</a> with a function
--   that returns <a>Either</a>. For example:
--   
--   <pre>
--   -- Avoid this:
--   tryCast s = case f s of
--     Left e -&gt; Left . TryCastException s . Just $ toException e
--     Right t -&gt; Right t
--   
--   -- Prefer this:
--   tryCast = eitherTryCast f
--   </pre>
eitherTryCast :: Exception exception => (source -> Either exception target) -> source -> Either (TryCastException source target) target

-- | This is similar to <a>via</a> except that it works with <a>TryCast</a>
--   instances instead. This function is especially convenient because
--   juggling the types in the <a>TryCastException</a> can be tedious.
--   
--   <pre>
--   -- Avoid this:
--   fmap (tryFrom @u) . tryInto @u
--   
--   -- Prefer this:
--   tryVia @u
--   </pre>
tryVia :: forall u source target through. (Identity u ~ through, TryCast source through, TryCast through target) => source -> Either (TryCastException source target) target

-- | This function is like <a>tryCast</a> except that it will throw an
--   impure exception if the conversion fails.
--   
--   <pre>
--   -- Avoid this:
--   either throw id . cast
--   
--   -- Prefer this:
--   unsafeCast
--   </pre>
unsafeCast :: forall source target. (HasCallStack, TryCast source target, Show source, Typeable source, Typeable target) => source -> target

-- | This function is like <a>from</a> except that it will throw an impure
--   exception if the conversion fails.
--   
--   <pre>
--   -- Avoid this:
--   either throw id . from @s
--   
--   -- Prefer this:
--   unsafeFrom @s
--   </pre>
unsafeFrom :: forall s target source. (Identity s ~ source, HasCallStack, TryCast source target, Show source, Typeable source, Typeable target) => source -> target

-- | This function is like <a>into</a> except that it will throw an impure
--   exception if the conversion fails.
--   
--   <pre>
--   -- Avoid this:
--   either throw id . into @t
--   
--   -- Prefer this:
--   unsafeInto @t
--   </pre>
unsafeInto :: forall t source target. (Identity t ~ target, HasCallStack, TryCast source target, Show source, Typeable source, Typeable target) => source -> target

module Witch.Lift

-- | This is like <a>unsafeCast</a> except that it works at compile time
--   rather than runtime.
--   
--   <pre>
--   -- Avoid this:
--   unsafeCast "some literal"
--   
--   -- Prefer this:
--   $$(liftedCast "some literal")
--   </pre>
liftedCast :: forall source target m. (TryCast source target, Lift target, Show source, Typeable source, Typeable target, Quote m) => source -> Code m target

-- | This is like <a>unsafeFrom</a> except that it works at compile time
--   rather than runtime.
--   
--   <pre>
--   -- Avoid this:
--   unsafeFrom @s "some literal"
--   
--   -- Prefer this:
--   $$(liftedFrom @s "some literal")
--   </pre>
liftedFrom :: forall s target m source. (Identity s ~ source, TryCast source target, Lift target, Show source, Typeable source, Typeable target, Quote m) => source -> Code m target

-- | This is like <a>unsafeInto</a> except that it works at compile time
--   rather than runtime.
--   
--   <pre>
--   -- Avoid this:
--   unsafeInto @t "some literal"
--   
--   -- Prefer this:
--   $$(liftedInto @t "some literal")
--   </pre>
liftedInto :: forall t source m target. (Identity t ~ target, TryCast source target, Lift target, Show source, Typeable source, Typeable target, Quote m) => source -> Code m target

module Witch.Instances
fromNonNegativeIntegral :: (Integral s, Num t) => s -> Either ArithException t

-- | The maximum integral value that can be unambiguously represented as a
--   <a>Float</a>. Equal to 16,777,215.
maxFloat :: Num a => a

-- | The maximum integral value that can be unambiguously represented as a
--   <a>Double</a>. Equal to 9,007,199,254,740,991.
maxDouble :: Num a => a
instance Witch.Cast.Cast GHC.Int.Int8 GHC.Int.Int16
instance Witch.Cast.Cast GHC.Int.Int8 GHC.Int.Int32
instance Witch.Cast.Cast GHC.Int.Int8 GHC.Int.Int64
instance Witch.Cast.Cast GHC.Int.Int8 GHC.Types.Int
instance Witch.Cast.Cast GHC.Int.Int8 GHC.Num.Integer.Integer
instance Witch.TryCast.TryCast GHC.Int.Int8 GHC.Word.Word8
instance Witch.TryCast.TryCast GHC.Int.Int8 GHC.Word.Word16
instance Witch.TryCast.TryCast GHC.Int.Int8 GHC.Word.Word32
instance Witch.TryCast.TryCast GHC.Int.Int8 GHC.Word.Word64
instance Witch.TryCast.TryCast GHC.Int.Int8 GHC.Types.Word
instance Witch.TryCast.TryCast GHC.Int.Int8 GHC.Num.Natural.Natural
instance Witch.Cast.Cast GHC.Int.Int8 GHC.Types.Float
instance Witch.Cast.Cast GHC.Int.Int8 GHC.Types.Double
instance Witch.TryCast.TryCast GHC.Int.Int16 GHC.Int.Int8
instance Witch.Cast.Cast GHC.Int.Int16 GHC.Int.Int32
instance Witch.Cast.Cast GHC.Int.Int16 GHC.Int.Int64
instance Witch.Cast.Cast GHC.Int.Int16 GHC.Types.Int
instance Witch.Cast.Cast GHC.Int.Int16 GHC.Num.Integer.Integer
instance Witch.TryCast.TryCast GHC.Int.Int16 GHC.Word.Word8
instance Witch.TryCast.TryCast GHC.Int.Int16 GHC.Word.Word16
instance Witch.TryCast.TryCast GHC.Int.Int16 GHC.Word.Word32
instance Witch.TryCast.TryCast GHC.Int.Int16 GHC.Word.Word64
instance Witch.TryCast.TryCast GHC.Int.Int16 GHC.Types.Word
instance Witch.TryCast.TryCast GHC.Int.Int16 GHC.Num.Natural.Natural
instance Witch.Cast.Cast GHC.Int.Int16 GHC.Types.Float
instance Witch.Cast.Cast GHC.Int.Int16 GHC.Types.Double
instance Witch.TryCast.TryCast GHC.Int.Int32 GHC.Int.Int8
instance Witch.TryCast.TryCast GHC.Int.Int32 GHC.Int.Int16
instance Witch.Cast.Cast GHC.Int.Int32 GHC.Int.Int64
instance Witch.TryCast.TryCast GHC.Int.Int32 GHC.Types.Int
instance Witch.Cast.Cast GHC.Int.Int32 GHC.Num.Integer.Integer
instance Witch.TryCast.TryCast GHC.Int.Int32 GHC.Word.Word8
instance Witch.TryCast.TryCast GHC.Int.Int32 GHC.Word.Word16
instance Witch.TryCast.TryCast GHC.Int.Int32 GHC.Word.Word32
instance Witch.TryCast.TryCast GHC.Int.Int32 GHC.Word.Word64
instance Witch.TryCast.TryCast GHC.Int.Int32 GHC.Types.Word
instance Witch.TryCast.TryCast GHC.Int.Int32 GHC.Num.Natural.Natural
instance Witch.TryCast.TryCast GHC.Int.Int32 GHC.Types.Float
instance Witch.Cast.Cast GHC.Int.Int32 GHC.Types.Double
instance Witch.TryCast.TryCast GHC.Int.Int64 GHC.Int.Int8
instance Witch.TryCast.TryCast GHC.Int.Int64 GHC.Int.Int16
instance Witch.TryCast.TryCast GHC.Int.Int64 GHC.Int.Int32
instance Witch.TryCast.TryCast GHC.Int.Int64 GHC.Types.Int
instance Witch.Cast.Cast GHC.Int.Int64 GHC.Num.Integer.Integer
instance Witch.TryCast.TryCast GHC.Int.Int64 GHC.Word.Word8
instance Witch.TryCast.TryCast GHC.Int.Int64 GHC.Word.Word16
instance Witch.TryCast.TryCast GHC.Int.Int64 GHC.Word.Word32
instance Witch.TryCast.TryCast GHC.Int.Int64 GHC.Word.Word64
instance Witch.TryCast.TryCast GHC.Int.Int64 GHC.Types.Word
instance Witch.TryCast.TryCast GHC.Int.Int64 GHC.Num.Natural.Natural
instance Witch.TryCast.TryCast GHC.Int.Int64 GHC.Types.Float
instance Witch.TryCast.TryCast GHC.Int.Int64 GHC.Types.Double
instance Witch.TryCast.TryCast GHC.Types.Int GHC.Int.Int8
instance Witch.TryCast.TryCast GHC.Types.Int GHC.Int.Int16
instance Witch.TryCast.TryCast GHC.Types.Int GHC.Int.Int32
instance Witch.Cast.Cast GHC.Types.Int GHC.Int.Int64
instance Witch.Cast.Cast GHC.Types.Int GHC.Num.Integer.Integer
instance Witch.TryCast.TryCast GHC.Types.Int GHC.Word.Word8
instance Witch.TryCast.TryCast GHC.Types.Int GHC.Word.Word16
instance Witch.TryCast.TryCast GHC.Types.Int GHC.Word.Word32
instance Witch.TryCast.TryCast GHC.Types.Int GHC.Word.Word64
instance Witch.TryCast.TryCast GHC.Types.Int GHC.Types.Word
instance Witch.TryCast.TryCast GHC.Types.Int GHC.Num.Natural.Natural
instance Witch.TryCast.TryCast GHC.Types.Int GHC.Types.Float
instance Witch.TryCast.TryCast GHC.Types.Int GHC.Types.Double
instance Witch.TryCast.TryCast GHC.Num.Integer.Integer GHC.Int.Int8
instance Witch.TryCast.TryCast GHC.Num.Integer.Integer GHC.Int.Int16
instance Witch.TryCast.TryCast GHC.Num.Integer.Integer GHC.Int.Int32
instance Witch.TryCast.TryCast GHC.Num.Integer.Integer GHC.Int.Int64
instance Witch.TryCast.TryCast GHC.Num.Integer.Integer GHC.Types.Int
instance Witch.TryCast.TryCast GHC.Num.Integer.Integer GHC.Word.Word8
instance Witch.TryCast.TryCast GHC.Num.Integer.Integer GHC.Word.Word16
instance Witch.TryCast.TryCast GHC.Num.Integer.Integer GHC.Word.Word32
instance Witch.TryCast.TryCast GHC.Num.Integer.Integer GHC.Word.Word64
instance Witch.TryCast.TryCast GHC.Num.Integer.Integer GHC.Types.Word
instance Witch.TryCast.TryCast GHC.Num.Integer.Integer GHC.Num.Natural.Natural
instance Witch.TryCast.TryCast GHC.Num.Integer.Integer GHC.Types.Float
instance Witch.TryCast.TryCast GHC.Num.Integer.Integer GHC.Types.Double
instance Witch.Cast.Cast GHC.Word.Word8 GHC.Word.Word16
instance Witch.Cast.Cast GHC.Word.Word8 GHC.Word.Word32
instance Witch.Cast.Cast GHC.Word.Word8 GHC.Word.Word64
instance Witch.Cast.Cast GHC.Word.Word8 GHC.Types.Word
instance Witch.Cast.Cast GHC.Word.Word8 GHC.Num.Natural.Natural
instance Witch.TryCast.TryCast GHC.Word.Word8 GHC.Int.Int8
instance Witch.Cast.Cast GHC.Word.Word8 GHC.Int.Int16
instance Witch.Cast.Cast GHC.Word.Word8 GHC.Int.Int32
instance Witch.Cast.Cast GHC.Word.Word8 GHC.Int.Int64
instance Witch.Cast.Cast GHC.Word.Word8 GHC.Types.Int
instance Witch.Cast.Cast GHC.Word.Word8 GHC.Num.Integer.Integer
instance Witch.Cast.Cast GHC.Word.Word8 GHC.Types.Float
instance Witch.Cast.Cast GHC.Word.Word8 GHC.Types.Double
instance Witch.TryCast.TryCast GHC.Word.Word16 GHC.Word.Word8
instance Witch.Cast.Cast GHC.Word.Word16 GHC.Word.Word32
instance Witch.Cast.Cast GHC.Word.Word16 GHC.Word.Word64
instance Witch.Cast.Cast GHC.Word.Word16 GHC.Types.Word
instance Witch.Cast.Cast GHC.Word.Word16 GHC.Num.Natural.Natural
instance Witch.TryCast.TryCast GHC.Word.Word16 GHC.Int.Int8
instance Witch.TryCast.TryCast GHC.Word.Word16 GHC.Int.Int16
instance Witch.Cast.Cast GHC.Word.Word16 GHC.Int.Int32
instance Witch.Cast.Cast GHC.Word.Word16 GHC.Int.Int64
instance Witch.Cast.Cast GHC.Word.Word16 GHC.Types.Int
instance Witch.Cast.Cast GHC.Word.Word16 GHC.Num.Integer.Integer
instance Witch.Cast.Cast GHC.Word.Word16 GHC.Types.Float
instance Witch.Cast.Cast GHC.Word.Word16 GHC.Types.Double
instance Witch.TryCast.TryCast GHC.Word.Word32 GHC.Word.Word8
instance Witch.TryCast.TryCast GHC.Word.Word32 GHC.Word.Word16
instance Witch.Cast.Cast GHC.Word.Word32 GHC.Word.Word64
instance Witch.TryCast.TryCast GHC.Word.Word32 GHC.Types.Word
instance Witch.Cast.Cast GHC.Word.Word32 GHC.Num.Natural.Natural
instance Witch.TryCast.TryCast GHC.Word.Word32 GHC.Int.Int8
instance Witch.TryCast.TryCast GHC.Word.Word32 GHC.Int.Int16
instance Witch.TryCast.TryCast GHC.Word.Word32 GHC.Int.Int32
instance Witch.Cast.Cast GHC.Word.Word32 GHC.Int.Int64
instance Witch.TryCast.TryCast GHC.Word.Word32 GHC.Types.Int
instance Witch.Cast.Cast GHC.Word.Word32 GHC.Num.Integer.Integer
instance Witch.TryCast.TryCast GHC.Word.Word32 GHC.Types.Float
instance Witch.Cast.Cast GHC.Word.Word32 GHC.Types.Double
instance Witch.TryCast.TryCast GHC.Word.Word64 GHC.Word.Word8
instance Witch.TryCast.TryCast GHC.Word.Word64 GHC.Word.Word16
instance Witch.TryCast.TryCast GHC.Word.Word64 GHC.Word.Word32
instance Witch.TryCast.TryCast GHC.Word.Word64 GHC.Types.Word
instance Witch.Cast.Cast GHC.Word.Word64 GHC.Num.Natural.Natural
instance Witch.TryCast.TryCast GHC.Word.Word64 GHC.Int.Int8
instance Witch.TryCast.TryCast GHC.Word.Word64 GHC.Int.Int16
instance Witch.TryCast.TryCast GHC.Word.Word64 GHC.Int.Int32
instance Witch.TryCast.TryCast GHC.Word.Word64 GHC.Int.Int64
instance Witch.TryCast.TryCast GHC.Word.Word64 GHC.Types.Int
instance Witch.Cast.Cast GHC.Word.Word64 GHC.Num.Integer.Integer
instance Witch.TryCast.TryCast GHC.Word.Word64 GHC.Types.Float
instance Witch.TryCast.TryCast GHC.Word.Word64 GHC.Types.Double
instance Witch.TryCast.TryCast GHC.Types.Word GHC.Word.Word8
instance Witch.TryCast.TryCast GHC.Types.Word GHC.Word.Word16
instance Witch.TryCast.TryCast GHC.Types.Word GHC.Word.Word32
instance Witch.Cast.Cast GHC.Types.Word GHC.Word.Word64
instance Witch.Cast.Cast GHC.Types.Word GHC.Num.Natural.Natural
instance Witch.TryCast.TryCast GHC.Types.Word GHC.Int.Int8
instance Witch.TryCast.TryCast GHC.Types.Word GHC.Int.Int16
instance Witch.TryCast.TryCast GHC.Types.Word GHC.Int.Int32
instance Witch.TryCast.TryCast GHC.Types.Word GHC.Int.Int64
instance Witch.TryCast.TryCast GHC.Types.Word GHC.Types.Int
instance Witch.Cast.Cast GHC.Types.Word GHC.Num.Integer.Integer
instance Witch.TryCast.TryCast GHC.Types.Word GHC.Types.Float
instance Witch.TryCast.TryCast GHC.Types.Word GHC.Types.Double
instance Witch.TryCast.TryCast GHC.Num.Natural.Natural GHC.Word.Word8
instance Witch.TryCast.TryCast GHC.Num.Natural.Natural GHC.Word.Word16
instance Witch.TryCast.TryCast GHC.Num.Natural.Natural GHC.Word.Word32
instance Witch.TryCast.TryCast GHC.Num.Natural.Natural GHC.Word.Word64
instance Witch.TryCast.TryCast GHC.Num.Natural.Natural GHC.Types.Word
instance Witch.TryCast.TryCast GHC.Num.Natural.Natural GHC.Int.Int8
instance Witch.TryCast.TryCast GHC.Num.Natural.Natural GHC.Int.Int16
instance Witch.TryCast.TryCast GHC.Num.Natural.Natural GHC.Int.Int32
instance Witch.TryCast.TryCast GHC.Num.Natural.Natural GHC.Int.Int64
instance Witch.TryCast.TryCast GHC.Num.Natural.Natural GHC.Types.Int
instance Witch.Cast.Cast GHC.Num.Natural.Natural GHC.Num.Integer.Integer
instance Witch.TryCast.TryCast GHC.Num.Natural.Natural GHC.Types.Float
instance Witch.TryCast.TryCast GHC.Num.Natural.Natural GHC.Types.Double
instance Witch.TryCast.TryCast GHC.Types.Float GHC.Int.Int8
instance Witch.TryCast.TryCast GHC.Types.Float GHC.Int.Int16
instance Witch.TryCast.TryCast GHC.Types.Float GHC.Int.Int32
instance Witch.TryCast.TryCast GHC.Types.Float GHC.Int.Int64
instance Witch.TryCast.TryCast GHC.Types.Float GHC.Types.Int
instance Witch.TryCast.TryCast GHC.Types.Float GHC.Num.Integer.Integer
instance Witch.TryCast.TryCast GHC.Types.Float GHC.Word.Word8
instance Witch.TryCast.TryCast GHC.Types.Float GHC.Word.Word16
instance Witch.TryCast.TryCast GHC.Types.Float GHC.Word.Word32
instance Witch.TryCast.TryCast GHC.Types.Float GHC.Word.Word64
instance Witch.TryCast.TryCast GHC.Types.Float GHC.Types.Word
instance Witch.TryCast.TryCast GHC.Types.Float GHC.Num.Natural.Natural
instance Witch.TryCast.TryCast GHC.Types.Float GHC.Real.Rational
instance Witch.Cast.Cast GHC.Types.Float GHC.Types.Double
instance Witch.TryCast.TryCast GHC.Types.Double GHC.Int.Int8
instance Witch.TryCast.TryCast GHC.Types.Double GHC.Int.Int16
instance Witch.TryCast.TryCast GHC.Types.Double GHC.Int.Int32
instance Witch.TryCast.TryCast GHC.Types.Double GHC.Int.Int64
instance Witch.TryCast.TryCast GHC.Types.Double GHC.Types.Int
instance Witch.TryCast.TryCast GHC.Types.Double GHC.Num.Integer.Integer
instance Witch.TryCast.TryCast GHC.Types.Double GHC.Word.Word8
instance Witch.TryCast.TryCast GHC.Types.Double GHC.Word.Word16
instance Witch.TryCast.TryCast GHC.Types.Double GHC.Word.Word32
instance Witch.TryCast.TryCast GHC.Types.Double GHC.Word.Word64
instance Witch.TryCast.TryCast GHC.Types.Double GHC.Types.Word
instance Witch.TryCast.TryCast GHC.Types.Double GHC.Num.Natural.Natural
instance Witch.TryCast.TryCast GHC.Types.Double GHC.Real.Rational
instance Witch.Cast.Cast GHC.Types.Double GHC.Types.Float
instance GHC.Real.Integral a => Witch.Cast.Cast a (GHC.Real.Ratio a)
instance (GHC.Classes.Eq a, GHC.Num.Num a) => Witch.TryCast.TryCast (GHC.Real.Ratio a) a
instance Witch.Cast.Cast GHC.Real.Rational GHC.Types.Float
instance Witch.Cast.Cast GHC.Real.Rational GHC.Types.Double
instance Witch.Cast.Cast GHC.Num.Integer.Integer (Data.Fixed.Fixed a)
instance Witch.Cast.Cast (Data.Fixed.Fixed a) GHC.Num.Integer.Integer
instance GHC.Num.Num a => Witch.Cast.Cast a (Data.Complex.Complex a)
instance (GHC.Classes.Eq a, GHC.Num.Num a) => Witch.TryCast.TryCast (Data.Complex.Complex a) a
instance Witch.TryCast.TryCast [a] (GHC.Base.NonEmpty a)
instance Witch.Cast.Cast (GHC.Base.NonEmpty a) [a]
instance GHC.Classes.Ord a => Witch.Cast.Cast [a] (Data.Set.Internal.Set a)
instance Witch.Cast.Cast (Data.Set.Internal.Set a) [a]
instance Witch.Cast.Cast [GHC.Types.Int] Data.IntSet.Internal.IntSet
instance Witch.Cast.Cast Data.IntSet.Internal.IntSet [GHC.Types.Int]
instance GHC.Classes.Ord k => Witch.Cast.Cast [(k, v)] (Data.Map.Internal.Map k v)
instance Witch.Cast.Cast (Data.Map.Internal.Map k v) [(k, v)]
instance Witch.Cast.Cast [(GHC.Types.Int, v)] (Data.IntMap.Internal.IntMap v)
instance Witch.Cast.Cast (Data.IntMap.Internal.IntMap v) [(GHC.Types.Int, v)]
instance Witch.Cast.Cast [a] (Data.Sequence.Internal.Seq a)
instance Witch.Cast.Cast (Data.Sequence.Internal.Seq a) [a]
instance Witch.Cast.Cast [GHC.Word.Word8] Data.ByteString.Internal.ByteString
instance Witch.Cast.Cast Data.ByteString.Internal.ByteString [GHC.Word.Word8]
instance Witch.Cast.Cast Data.ByteString.Internal.ByteString Data.ByteString.Lazy.Internal.ByteString
instance Witch.Cast.Cast Data.ByteString.Internal.ByteString Data.ByteString.Short.Internal.ShortByteString
instance Witch.TryCast.TryCast Data.ByteString.Internal.ByteString Data.Text.Internal.Text
instance Witch.Cast.Cast [GHC.Word.Word8] Data.ByteString.Lazy.Internal.ByteString
instance Witch.Cast.Cast Data.ByteString.Lazy.Internal.ByteString [GHC.Word.Word8]
instance Witch.Cast.Cast Data.ByteString.Lazy.Internal.ByteString Data.ByteString.Internal.ByteString
instance Witch.TryCast.TryCast Data.ByteString.Lazy.Internal.ByteString Data.Text.Internal.Lazy.Text
instance Witch.Cast.Cast [GHC.Word.Word8] Data.ByteString.Short.Internal.ShortByteString
instance Witch.Cast.Cast Data.ByteString.Short.Internal.ShortByteString [GHC.Word.Word8]
instance Witch.Cast.Cast Data.ByteString.Short.Internal.ShortByteString Data.ByteString.Internal.ByteString
instance Witch.Cast.Cast GHC.Base.String Data.Text.Internal.Text
instance Witch.Cast.Cast Data.Text.Internal.Text GHC.Base.String
instance Witch.Cast.Cast Data.Text.Internal.Text Data.Text.Internal.Lazy.Text
instance Witch.Cast.Cast Data.Text.Internal.Text Data.ByteString.Internal.ByteString
instance Witch.Cast.Cast GHC.Base.String Data.Text.Internal.Lazy.Text
instance Witch.Cast.Cast Data.Text.Internal.Lazy.Text GHC.Base.String
instance Witch.Cast.Cast Data.Text.Internal.Lazy.Text Data.Text.Internal.Text
instance Witch.Cast.Cast Data.Text.Internal.Lazy.Text Data.ByteString.Lazy.Internal.ByteString
instance Witch.Cast.Cast (Witch.TryCastException.TryCastException s u) (Witch.TryCastException.TryCastException s t)
instance (GHC.Show.Show s, Data.Typeable.Internal.Typeable s, Data.Typeable.Internal.Typeable t) => Witch.Cast.Cast (Witch.TryCastException.TryCastException s t) GHC.Base.String
instance (GHC.Show.Show s, Data.Typeable.Internal.Typeable s, Data.Typeable.Internal.Typeable t) => Witch.Cast.Cast (Witch.TryCastException.TryCastException s t) Data.Text.Internal.Text
instance (GHC.Show.Show s, Data.Typeable.Internal.Typeable s, Data.Typeable.Internal.Typeable t) => Witch.Cast.Cast (Witch.TryCastException.TryCastException s t) Data.Text.Internal.Lazy.Text


-- | The Witch package is a library that allows you to confidently convert
--   values between various types. This module exports everything you need
--   to perform conversions or define your own. It is designed to be
--   imported unqualified, so getting started is as easy as:
--   
--   <pre>
--   &gt;&gt;&gt; import Witch
--   </pre>
module Witch

-- | This type class is for converting values from some <tt>source</tt>
--   type into some other <tt>target</tt> type. The constraint <tt>Cast
--   source target</tt> measn that you can convert from a value of type
--   <tt>source</tt> into a value of type <tt>target</tt>.
--   
--   This type class is for conversions that cannot fail. If your
--   conversion can fail, consider implementing <tt>TryCast</tt> instead.
class Cast source target

-- | This method implements the conversion of a value between types. At
--   call sites you will usually want to use <tt>from</tt> or <tt>into</tt>
--   instead of this method.
--   
--   The default implementation of this method simply calls <a>coerce</a>,
--   which works for types that have the same runtime representation. This
--   means that for <tt>newtype</tt>s you do not need to implement this
--   method at all. For example:
--   
--   <pre>
--   &gt;&gt;&gt; newtype Name = Name String
--   
--   &gt;&gt;&gt; instance Cast Name String
--   
--   &gt;&gt;&gt; instance Cast String Name
--   </pre>
cast :: Cast source target => source -> target

-- | This method implements the conversion of a value between types. At
--   call sites you will usually want to use <tt>from</tt> or <tt>into</tt>
--   instead of this method.
--   
--   The default implementation of this method simply calls <a>coerce</a>,
--   which works for types that have the same runtime representation. This
--   means that for <tt>newtype</tt>s you do not need to implement this
--   method at all. For example:
--   
--   <pre>
--   &gt;&gt;&gt; newtype Name = Name String
--   
--   &gt;&gt;&gt; instance Cast Name String
--   
--   &gt;&gt;&gt; instance Cast String Name
--   </pre>
cast :: (Cast source target, Coercible source target) => source -> target

-- | This is the same as <a>cast</a> except that it requires a type
--   application for the <tt>source</tt> type.
--   
--   <pre>
--   -- Avoid this:
--   cast (x :: s)
--   
--   -- Prefer this:
--   from @s x
--   </pre>
from :: forall s target source. (Identity s ~ source, Cast source target) => source -> target

-- | This is the same as <a>cast</a> except that it requires a type
--   application for the <tt>target</tt> type.
--   
--   <pre>
--   -- Avoid this:
--   cast x :: t
--   
--   -- Prefer this:
--   into @t x
--   </pre>
into :: forall t source target. (Identity t ~ target, Cast source target) => source -> target

-- | This type class is for converting values from some <tt>source</tt>
--   type into some other <tt>target</tt> type. The constraint <tt>TryCast
--   source target</tt> means that you may be able to convert from a value
--   of type <tt>source</tt> into a value of type <tt>target</tt>, but that
--   conversion may fail at runtime.
--   
--   This type class is for conversions that can fail. If your conversion
--   cannot fail, consider implementing <tt>Cast</tt> instead.
class TryCast source target

-- | This method implements the conversion of a value between types. At
--   call sites you will usually want to use <tt>tryFrom</tt> or
--   <tt>tryInto</tt> instead of this method.
tryCast :: TryCast source target => source -> Either (TryCastException source target) target

-- | This is the same as <a>tryCast</a> except that it requires a type
--   application for the <tt>source</tt> type.
--   
--   <pre>
--   -- Avoid this:
--   tryCast (x :: s)
--   
--   -- Prefer this:
--   tryFrom @s x
--   </pre>
tryFrom :: forall s target source. (Identity s ~ source, TryCast source target) => source -> Either (TryCastException source target) target

-- | This is the same as <a>tryCast</a> except that it requires a type
--   application for the <tt>target</tt> type.
--   
--   <pre>
--   -- Avoid this:
--   tryCast x :: Either (TryCastException s t) t
--   
--   -- Prefer this:
--   tryInto @t x
--   </pre>
tryInto :: forall t source target. (Identity t ~ target, TryCast source target) => source -> Either (TryCastException source target) target

-- | This exception is thrown when a <tt>TryCast</tt> conversion fails. It
--   has the original <tt>source</tt> value that caused the failure and it
--   knows the <tt>target</tt> type it was trying to convert into. It also
--   has an optional <a>SomeException</a> for communicating what went wrong
--   while converting.
data TryCastException source target
TryCastException :: source -> Maybe SomeException -> TryCastException source target

-- | This is the same as <a>id</a> except that it requires a type
--   application. This can be an ergonomic way to pin down a polymorphic
--   type in a function pipeline. For example:
--   
--   <pre>
--   -- Avoid this:
--   f . (\ x -&gt; x :: Int) . g
--   
--   -- Prefer this:
--   f . as @Int . g
--   </pre>
as :: forall s source. Identity s ~ source => source -> source

-- | This function converts from some <tt>source</tt> type into some
--   <tt>target</tt> type, applies the given function, then converts back
--   into the <tt>source</tt> type. This is useful when you have two types
--   that are isomorphic but some function that only works with one of
--   them.
--   
--   <pre>
--   -- Avoid this:
--   from @t . f . from @s
--   
--   -- Prefer this:
--   over @t f
--   </pre>
over :: forall t source target. (Identity t ~ target, Cast source target, Cast target source) => (target -> target) -> source -> source

-- | This function first converts from some <tt>source</tt> type into some
--   <tt>through</tt> type, and then converts that into some
--   <tt>target</tt> type. Usually this is used when writing <a>Cast</a>
--   instances. Sometimes this can be used to work around the lack of an
--   instance that should probably exist.
--   
--   <pre>
--   -- Avoid this:
--   from @u . into @u
--   
--   -- Prefer this:
--   via @u
--   </pre>
via :: forall u source target through. (Identity u ~ through, Cast source through, Cast through target) => source -> target

-- | This function can be used to implement <a>tryCast</a> with a function
--   that returns <a>Maybe</a>. For example:
--   
--   <pre>
--   -- Avoid this:
--   tryCast s = case f s of
--     Nothing -&gt; Left $ TryCastException s Nothing
--     Just t -&gt; Right t
--   
--   -- Prefer this:
--   tryCast = maybeTryCast f
--   </pre>
maybeTryCast :: (source -> Maybe target) -> source -> Either (TryCastException source target) target

-- | This function can be used to implement <a>tryCast</a> with a function
--   that returns <a>Either</a>. For example:
--   
--   <pre>
--   -- Avoid this:
--   tryCast s = case f s of
--     Left e -&gt; Left . TryCastException s . Just $ toException e
--     Right t -&gt; Right t
--   
--   -- Prefer this:
--   tryCast = eitherTryCast f
--   </pre>
eitherTryCast :: Exception exception => (source -> Either exception target) -> source -> Either (TryCastException source target) target

-- | This is similar to <a>via</a> except that it works with <a>TryCast</a>
--   instances instead. This function is especially convenient because
--   juggling the types in the <a>TryCastException</a> can be tedious.
--   
--   <pre>
--   -- Avoid this:
--   fmap (tryFrom @u) . tryInto @u
--   
--   -- Prefer this:
--   tryVia @u
--   </pre>
tryVia :: forall u source target through. (Identity u ~ through, TryCast source through, TryCast through target) => source -> Either (TryCastException source target) target

-- | This function is like <a>tryCast</a> except that it will throw an
--   impure exception if the conversion fails.
--   
--   <pre>
--   -- Avoid this:
--   either throw id . cast
--   
--   -- Prefer this:
--   unsafeCast
--   </pre>
unsafeCast :: forall source target. (HasCallStack, TryCast source target, Show source, Typeable source, Typeable target) => source -> target

-- | This function is like <a>from</a> except that it will throw an impure
--   exception if the conversion fails.
--   
--   <pre>
--   -- Avoid this:
--   either throw id . from @s
--   
--   -- Prefer this:
--   unsafeFrom @s
--   </pre>
unsafeFrom :: forall s target source. (Identity s ~ source, HasCallStack, TryCast source target, Show source, Typeable source, Typeable target) => source -> target

-- | This function is like <a>into</a> except that it will throw an impure
--   exception if the conversion fails.
--   
--   <pre>
--   -- Avoid this:
--   either throw id . into @t
--   
--   -- Prefer this:
--   unsafeInto @t
--   </pre>
unsafeInto :: forall t source target. (Identity t ~ target, HasCallStack, TryCast source target, Show source, Typeable source, Typeable target) => source -> target

-- | This is like <a>unsafeCast</a> except that it works at compile time
--   rather than runtime.
--   
--   <pre>
--   -- Avoid this:
--   unsafeCast "some literal"
--   
--   -- Prefer this:
--   $$(liftedCast "some literal")
--   </pre>
liftedCast :: forall source target m. (TryCast source target, Lift target, Show source, Typeable source, Typeable target, Quote m) => source -> Code m target

-- | This is like <a>unsafeFrom</a> except that it works at compile time
--   rather than runtime.
--   
--   <pre>
--   -- Avoid this:
--   unsafeFrom @s "some literal"
--   
--   -- Prefer this:
--   $$(liftedFrom @s "some literal")
--   </pre>
liftedFrom :: forall s target m source. (Identity s ~ source, TryCast source target, Lift target, Show source, Typeable source, Typeable target, Quote m) => source -> Code m target

-- | This is like <a>unsafeInto</a> except that it works at compile time
--   rather than runtime.
--   
--   <pre>
--   -- Avoid this:
--   unsafeInto @t "some literal"
--   
--   -- Prefer this:
--   $$(liftedInto @t "some literal")
--   </pre>
liftedInto :: forall t source m target. (Identity t ~ target, TryCast source target, Lift target, Show source, Typeable source, Typeable target, Quote m) => source -> Code m target
