-- 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.3.2.2 module Witch.From -- | This type class is for converting values from some source -- type into some other target type. The constraint -- From source target means that you can convert from a -- value of type source into a value of type target. -- -- This type class is for conversions that always succeed. If your -- conversion sometimes fails, consider implementing TryFrom -- instead. class From source target -- | This method implements the conversion of a value between types. At -- call sites you may prefer to use into instead. -- --
-- -- Avoid this: -- from (x :: s) -- -- -- Prefer this: -- from @s x ---- -- The default implementation of this method simply calls coerce, -- which works for types that have the same runtime representation. This -- means that for newtypes you do not need to implement this -- method at all. For example: -- --
-- >>> newtype Name = Name String -- -- >>> instance From Name String -- -- >>> instance From String Name --from :: From source target => source -> target -- | This method implements the conversion of a value between types. At -- call sites you may prefer to use into instead. -- --
-- -- Avoid this: -- from (x :: s) -- -- -- Prefer this: -- from @s x ---- -- The default implementation of this method simply calls coerce, -- which works for types that have the same runtime representation. This -- means that for newtypes you do not need to implement this -- method at all. For example: -- --
-- >>> newtype Name = Name String -- -- >>> instance From Name String -- -- >>> instance From String Name --from :: (From source target, Coercible source target) => source -> target module Witch.TryFromException -- | This exception is thrown when a TryFrom conversion fails. It -- has the original source value that caused the failure and it -- knows the target type it was trying to convert into. It also -- has an optional SomeException for communicating what went wrong -- while converting. data TryFromException source target TryFromException :: source -> Maybe SomeException -> TryFromException source target instance (GHC.Show.Show source, Data.Typeable.Internal.Typeable source, Data.Typeable.Internal.Typeable target) => GHC.Show.Show (Witch.TryFromException.TryFromException source target) instance (GHC.Show.Show source, Data.Typeable.Internal.Typeable source, Data.Typeable.Internal.Typeable target) => GHC.Exception.Type.Exception (Witch.TryFromException.TryFromException source target) module Witch.TryFrom -- | This type class is for converting values from some source -- type into some other target type. The constraint -- TryFrom source target means that you may be able to -- convert from a value of type source into a value of type -- target, but that conversion may fail at runtime. -- -- This type class is for conversions that can sometimes fail. If your -- conversion always succeeds, consider implementing From -- instead. class TryFrom source target -- | This method implements the conversion of a value between types. At -- call sites you may want to use tryInto instead. -- --
-- -- Avoid this: -- tryFrom (x :: s) -- -- -- Prefer this: -- tryFrom @s ---- -- Consider using maybeTryFrom or eitherTryFrom to -- implement this method. tryFrom :: TryFrom source target => source -> Either (TryFromException source target) target module Witch.Utility -- | This is the same as id. This can be an ergonomic way to pin -- down a polymorphic type in a function pipeline. For example: -- --
-- -- Avoid this: -- f . (\ x -> x :: Int) . g -- -- -- Prefer this: -- f . as @Int . g --as :: forall source. source -> source -- | This is the same as from except that the type variables are in -- the opposite order. -- --
-- -- Avoid this: -- from x :: t -- -- -- Prefer this: -- into @t x --into :: forall target source. From source target => source -> target -- | This function converts from some source type into some -- target type, applies the given function, then converts back -- into the source type. This is useful when you have two types -- that are isomorphic but some function that only works with one of -- them. -- --
-- -- Avoid this: -- from @t . f . into @t -- -- -- Prefer this: -- over @t f --over :: forall target source. (From source target, From target source) => (target -> target) -> source -> source -- | This function first converts from some source type into some -- through type, and then converts that into some -- target type. Usually this is used when writing From -- instances. Sometimes this can be used to work around the lack of an -- instance that should probably exist. -- --
-- -- Avoid this: -- from @u . into @u -- -- -- Prefer this: -- via @u --via :: forall through source target. (From source through, From through target) => source -> target -- | This is the same as tryFrom except that the type variables are -- in the opposite order. -- --
-- -- Avoid this: -- tryFrom x :: Either (TryFromException s t) t -- -- -- Prefer this: -- tryInto @t x --tryInto :: forall target source. TryFrom source target => source -> Either (TryFromException source target) target -- | This is similar to via except that it works with TryFrom -- instances instead. This function is especially convenient because -- juggling the types in the TryFromException can be tedious. -- --
-- -- Avoid this: -- case tryInto @u x of -- Left (TryFromException _ e) -> Left $ TryFromException x e -- Right y -> case tryFrom @u y of -- Left (TryFromException _ e) -> Left $ TryFromException x e -- Right z -> Right z -- -- -- Prefer this: -- tryVia @u --tryVia :: forall through source target. (TryFrom source through, TryFrom through target) => source -> Either (TryFromException source target) target -- | This function can be used to implement tryFrom with a function -- that returns Maybe. For example: -- --
-- -- Avoid this: -- tryFrom s = case f s of -- Nothing -> Left $ TryFromException s Nothing -- Just t -> Right t -- -- -- Prefer this: -- tryFrom = maybeTryFrom f --maybeTryFrom :: (source -> Maybe target) -> source -> Either (TryFromException source target) target -- | This function can be used to implement tryFrom with a function -- that returns Either. For example: -- --
-- -- Avoid this: -- tryFrom s = case f s of -- Left e -> Left . TryFromException s . Just $ toException e -- Right t -> Right t -- -- -- Prefer this: -- tryFrom = eitherTryFrom f --eitherTryFrom :: Exception exception => (source -> Either exception target) -> source -> Either (TryFromException source target) target -- | This function is like tryFrom except that it will throw an -- impure exception if the conversion fails. -- --
-- -- Avoid this: -- either throw id . tryFrom @s -- -- -- Prefer this: -- unsafeFrom @s --unsafeFrom :: forall source target. (HasCallStack, TryFrom source target, Show source, Typeable source, Typeable target) => source -> target -- | This function is like tryInto except that it will throw an -- impure exception if the conversion fails. -- --
-- -- Avoid this: -- either throw id . tryInto @t -- -- -- Prefer this: -- unsafeInto @t --unsafeInto :: forall target source. (HasCallStack, TryFrom source target, Show source, Typeable source, Typeable target) => source -> target module Witch.Lift -- | This is like unsafeFrom except that it works at compile time -- rather than runtime. -- --
-- -- Avoid this: -- unsafeFrom @s "some literal" -- -- -- Prefer this: -- $$(liftedFrom @s "some literal") --liftedFrom :: forall source target. (TryFrom source target, Lift target, Show source, Typeable source, Typeable target) => source -> Q (TExp target) -- | This is like unsafeInto except that it works at compile time -- rather than runtime. -- --
-- -- Avoid this: -- unsafeInto @t "some literal" -- -- -- Prefer this: -- $$(liftedInto @t "some literal") --liftedInto :: forall target source. (TryFrom source target, Lift target, Show source, Typeable source, Typeable target) => source -> Q (TExp target) module Witch.Instances fromNonNegativeIntegral :: (Integral s, Num t) => s -> Either ArithException t -- | The maximum integral value that can be unambiguously represented as a -- Float. Equal to 16,777,215. maxFloat :: Num a => a -- | The maximum integral value that can be unambiguously represented as a -- Double. Equal to 9,007,199,254,740,991. maxDouble :: Num a => a instance Witch.From.From a a instance Witch.From.From GHC.Int.Int8 GHC.Int.Int16 instance Witch.From.From GHC.Int.Int8 GHC.Int.Int32 instance Witch.From.From GHC.Int.Int8 GHC.Int.Int64 instance Witch.From.From GHC.Int.Int8 GHC.Types.Int instance Witch.From.From GHC.Int.Int8 GHC.Integer.Type.Integer instance Witch.TryFrom.TryFrom GHC.Int.Int8 GHC.Word.Word8 instance Witch.TryFrom.TryFrom GHC.Int.Int8 GHC.Word.Word16 instance Witch.TryFrom.TryFrom GHC.Int.Int8 GHC.Word.Word32 instance Witch.TryFrom.TryFrom GHC.Int.Int8 GHC.Word.Word64 instance Witch.TryFrom.TryFrom GHC.Int.Int8 GHC.Types.Word instance Witch.TryFrom.TryFrom GHC.Int.Int8 GHC.Natural.Natural instance Witch.From.From GHC.Int.Int8 GHC.Types.Float instance Witch.From.From GHC.Int.Int8 GHC.Types.Double instance Witch.TryFrom.TryFrom GHC.Int.Int16 GHC.Int.Int8 instance Witch.From.From GHC.Int.Int16 GHC.Int.Int32 instance Witch.From.From GHC.Int.Int16 GHC.Int.Int64 instance Witch.From.From GHC.Int.Int16 GHC.Types.Int instance Witch.From.From GHC.Int.Int16 GHC.Integer.Type.Integer instance Witch.TryFrom.TryFrom GHC.Int.Int16 GHC.Word.Word8 instance Witch.TryFrom.TryFrom GHC.Int.Int16 GHC.Word.Word16 instance Witch.TryFrom.TryFrom GHC.Int.Int16 GHC.Word.Word32 instance Witch.TryFrom.TryFrom GHC.Int.Int16 GHC.Word.Word64 instance Witch.TryFrom.TryFrom GHC.Int.Int16 GHC.Types.Word instance Witch.TryFrom.TryFrom GHC.Int.Int16 GHC.Natural.Natural instance Witch.From.From GHC.Int.Int16 GHC.Types.Float instance Witch.From.From GHC.Int.Int16 GHC.Types.Double instance Witch.TryFrom.TryFrom GHC.Int.Int32 GHC.Int.Int8 instance Witch.TryFrom.TryFrom GHC.Int.Int32 GHC.Int.Int16 instance Witch.From.From GHC.Int.Int32 GHC.Int.Int64 instance Witch.TryFrom.TryFrom GHC.Int.Int32 GHC.Types.Int instance Witch.From.From GHC.Int.Int32 GHC.Integer.Type.Integer instance Witch.TryFrom.TryFrom GHC.Int.Int32 GHC.Word.Word8 instance Witch.TryFrom.TryFrom GHC.Int.Int32 GHC.Word.Word16 instance Witch.TryFrom.TryFrom GHC.Int.Int32 GHC.Word.Word32 instance Witch.TryFrom.TryFrom GHC.Int.Int32 GHC.Word.Word64 instance Witch.TryFrom.TryFrom GHC.Int.Int32 GHC.Types.Word instance Witch.TryFrom.TryFrom GHC.Int.Int32 GHC.Natural.Natural instance Witch.TryFrom.TryFrom GHC.Int.Int32 GHC.Types.Float instance Witch.From.From GHC.Int.Int32 GHC.Types.Double instance Witch.TryFrom.TryFrom GHC.Int.Int64 GHC.Int.Int8 instance Witch.TryFrom.TryFrom GHC.Int.Int64 GHC.Int.Int16 instance Witch.TryFrom.TryFrom GHC.Int.Int64 GHC.Int.Int32 instance Witch.TryFrom.TryFrom GHC.Int.Int64 GHC.Types.Int instance Witch.From.From GHC.Int.Int64 GHC.Integer.Type.Integer instance Witch.TryFrom.TryFrom GHC.Int.Int64 GHC.Word.Word8 instance Witch.TryFrom.TryFrom GHC.Int.Int64 GHC.Word.Word16 instance Witch.TryFrom.TryFrom GHC.Int.Int64 GHC.Word.Word32 instance Witch.TryFrom.TryFrom GHC.Int.Int64 GHC.Word.Word64 instance Witch.TryFrom.TryFrom GHC.Int.Int64 GHC.Types.Word instance Witch.TryFrom.TryFrom GHC.Int.Int64 GHC.Natural.Natural instance Witch.TryFrom.TryFrom GHC.Int.Int64 GHC.Types.Float instance Witch.TryFrom.TryFrom GHC.Int.Int64 GHC.Types.Double instance Witch.TryFrom.TryFrom GHC.Types.Int GHC.Int.Int8 instance Witch.TryFrom.TryFrom GHC.Types.Int GHC.Int.Int16 instance Witch.TryFrom.TryFrom GHC.Types.Int GHC.Int.Int32 instance Witch.From.From GHC.Types.Int GHC.Int.Int64 instance Witch.From.From GHC.Types.Int GHC.Integer.Type.Integer instance Witch.TryFrom.TryFrom GHC.Types.Int GHC.Word.Word8 instance Witch.TryFrom.TryFrom GHC.Types.Int GHC.Word.Word16 instance Witch.TryFrom.TryFrom GHC.Types.Int GHC.Word.Word32 instance Witch.TryFrom.TryFrom GHC.Types.Int GHC.Word.Word64 instance Witch.TryFrom.TryFrom GHC.Types.Int GHC.Types.Word instance Witch.TryFrom.TryFrom GHC.Types.Int GHC.Natural.Natural instance Witch.TryFrom.TryFrom GHC.Types.Int GHC.Types.Float instance Witch.TryFrom.TryFrom GHC.Types.Int GHC.Types.Double instance Witch.TryFrom.TryFrom GHC.Integer.Type.Integer GHC.Int.Int8 instance Witch.TryFrom.TryFrom GHC.Integer.Type.Integer GHC.Int.Int16 instance Witch.TryFrom.TryFrom GHC.Integer.Type.Integer GHC.Int.Int32 instance Witch.TryFrom.TryFrom GHC.Integer.Type.Integer GHC.Int.Int64 instance Witch.TryFrom.TryFrom GHC.Integer.Type.Integer GHC.Types.Int instance Witch.TryFrom.TryFrom GHC.Integer.Type.Integer GHC.Word.Word8 instance Witch.TryFrom.TryFrom GHC.Integer.Type.Integer GHC.Word.Word16 instance Witch.TryFrom.TryFrom GHC.Integer.Type.Integer GHC.Word.Word32 instance Witch.TryFrom.TryFrom GHC.Integer.Type.Integer GHC.Word.Word64 instance Witch.TryFrom.TryFrom GHC.Integer.Type.Integer GHC.Types.Word instance Witch.TryFrom.TryFrom GHC.Integer.Type.Integer GHC.Natural.Natural instance Witch.TryFrom.TryFrom GHC.Integer.Type.Integer GHC.Types.Float instance Witch.TryFrom.TryFrom GHC.Integer.Type.Integer GHC.Types.Double instance Witch.From.From GHC.Word.Word8 GHC.Word.Word16 instance Witch.From.From GHC.Word.Word8 GHC.Word.Word32 instance Witch.From.From GHC.Word.Word8 GHC.Word.Word64 instance Witch.From.From GHC.Word.Word8 GHC.Types.Word instance Witch.From.From GHC.Word.Word8 GHC.Natural.Natural instance Witch.TryFrom.TryFrom GHC.Word.Word8 GHC.Int.Int8 instance Witch.From.From GHC.Word.Word8 GHC.Int.Int16 instance Witch.From.From GHC.Word.Word8 GHC.Int.Int32 instance Witch.From.From GHC.Word.Word8 GHC.Int.Int64 instance Witch.From.From GHC.Word.Word8 GHC.Types.Int instance Witch.From.From GHC.Word.Word8 GHC.Integer.Type.Integer instance Witch.From.From GHC.Word.Word8 GHC.Types.Float instance Witch.From.From GHC.Word.Word8 GHC.Types.Double instance Witch.TryFrom.TryFrom GHC.Word.Word16 GHC.Word.Word8 instance Witch.From.From GHC.Word.Word16 GHC.Word.Word32 instance Witch.From.From GHC.Word.Word16 GHC.Word.Word64 instance Witch.From.From GHC.Word.Word16 GHC.Types.Word instance Witch.From.From GHC.Word.Word16 GHC.Natural.Natural instance Witch.TryFrom.TryFrom GHC.Word.Word16 GHC.Int.Int8 instance Witch.TryFrom.TryFrom GHC.Word.Word16 GHC.Int.Int16 instance Witch.From.From GHC.Word.Word16 GHC.Int.Int32 instance Witch.From.From GHC.Word.Word16 GHC.Int.Int64 instance Witch.From.From GHC.Word.Word16 GHC.Types.Int instance Witch.From.From GHC.Word.Word16 GHC.Integer.Type.Integer instance Witch.From.From GHC.Word.Word16 GHC.Types.Float instance Witch.From.From GHC.Word.Word16 GHC.Types.Double instance Witch.TryFrom.TryFrom GHC.Word.Word32 GHC.Word.Word8 instance Witch.TryFrom.TryFrom GHC.Word.Word32 GHC.Word.Word16 instance Witch.From.From GHC.Word.Word32 GHC.Word.Word64 instance Witch.TryFrom.TryFrom GHC.Word.Word32 GHC.Types.Word instance Witch.From.From GHC.Word.Word32 GHC.Natural.Natural instance Witch.TryFrom.TryFrom GHC.Word.Word32 GHC.Int.Int8 instance Witch.TryFrom.TryFrom GHC.Word.Word32 GHC.Int.Int16 instance Witch.TryFrom.TryFrom GHC.Word.Word32 GHC.Int.Int32 instance Witch.From.From GHC.Word.Word32 GHC.Int.Int64 instance Witch.TryFrom.TryFrom GHC.Word.Word32 GHC.Types.Int instance Witch.From.From GHC.Word.Word32 GHC.Integer.Type.Integer instance Witch.TryFrom.TryFrom GHC.Word.Word32 GHC.Types.Float instance Witch.From.From GHC.Word.Word32 GHC.Types.Double instance Witch.TryFrom.TryFrom GHC.Word.Word64 GHC.Word.Word8 instance Witch.TryFrom.TryFrom GHC.Word.Word64 GHC.Word.Word16 instance Witch.TryFrom.TryFrom GHC.Word.Word64 GHC.Word.Word32 instance Witch.TryFrom.TryFrom GHC.Word.Word64 GHC.Types.Word instance Witch.From.From GHC.Word.Word64 GHC.Natural.Natural instance Witch.TryFrom.TryFrom GHC.Word.Word64 GHC.Int.Int8 instance Witch.TryFrom.TryFrom GHC.Word.Word64 GHC.Int.Int16 instance Witch.TryFrom.TryFrom GHC.Word.Word64 GHC.Int.Int32 instance Witch.TryFrom.TryFrom GHC.Word.Word64 GHC.Int.Int64 instance Witch.TryFrom.TryFrom GHC.Word.Word64 GHC.Types.Int instance Witch.From.From GHC.Word.Word64 GHC.Integer.Type.Integer instance Witch.TryFrom.TryFrom GHC.Word.Word64 GHC.Types.Float instance Witch.TryFrom.TryFrom GHC.Word.Word64 GHC.Types.Double instance Witch.TryFrom.TryFrom GHC.Types.Word GHC.Word.Word8 instance Witch.TryFrom.TryFrom GHC.Types.Word GHC.Word.Word16 instance Witch.TryFrom.TryFrom GHC.Types.Word GHC.Word.Word32 instance Witch.From.From GHC.Types.Word GHC.Word.Word64 instance Witch.From.From GHC.Types.Word GHC.Natural.Natural instance Witch.TryFrom.TryFrom GHC.Types.Word GHC.Int.Int8 instance Witch.TryFrom.TryFrom GHC.Types.Word GHC.Int.Int16 instance Witch.TryFrom.TryFrom GHC.Types.Word GHC.Int.Int32 instance Witch.TryFrom.TryFrom GHC.Types.Word GHC.Int.Int64 instance Witch.TryFrom.TryFrom GHC.Types.Word GHC.Types.Int instance Witch.From.From GHC.Types.Word GHC.Integer.Type.Integer instance Witch.TryFrom.TryFrom GHC.Types.Word GHC.Types.Float instance Witch.TryFrom.TryFrom GHC.Types.Word GHC.Types.Double instance Witch.TryFrom.TryFrom GHC.Natural.Natural GHC.Word.Word8 instance Witch.TryFrom.TryFrom GHC.Natural.Natural GHC.Word.Word16 instance Witch.TryFrom.TryFrom GHC.Natural.Natural GHC.Word.Word32 instance Witch.TryFrom.TryFrom GHC.Natural.Natural GHC.Word.Word64 instance Witch.TryFrom.TryFrom GHC.Natural.Natural GHC.Types.Word instance Witch.TryFrom.TryFrom GHC.Natural.Natural GHC.Int.Int8 instance Witch.TryFrom.TryFrom GHC.Natural.Natural GHC.Int.Int16 instance Witch.TryFrom.TryFrom GHC.Natural.Natural GHC.Int.Int32 instance Witch.TryFrom.TryFrom GHC.Natural.Natural GHC.Int.Int64 instance Witch.TryFrom.TryFrom GHC.Natural.Natural GHC.Types.Int instance Witch.From.From GHC.Natural.Natural GHC.Integer.Type.Integer instance Witch.TryFrom.TryFrom GHC.Natural.Natural GHC.Types.Float instance Witch.TryFrom.TryFrom GHC.Natural.Natural GHC.Types.Double instance Witch.TryFrom.TryFrom GHC.Types.Float GHC.Int.Int8 instance Witch.TryFrom.TryFrom GHC.Types.Float GHC.Int.Int16 instance Witch.TryFrom.TryFrom GHC.Types.Float GHC.Int.Int32 instance Witch.TryFrom.TryFrom GHC.Types.Float GHC.Int.Int64 instance Witch.TryFrom.TryFrom GHC.Types.Float GHC.Types.Int instance Witch.TryFrom.TryFrom GHC.Types.Float GHC.Integer.Type.Integer instance Witch.TryFrom.TryFrom GHC.Types.Float GHC.Word.Word8 instance Witch.TryFrom.TryFrom GHC.Types.Float GHC.Word.Word16 instance Witch.TryFrom.TryFrom GHC.Types.Float GHC.Word.Word32 instance Witch.TryFrom.TryFrom GHC.Types.Float GHC.Word.Word64 instance Witch.TryFrom.TryFrom GHC.Types.Float GHC.Types.Word instance Witch.TryFrom.TryFrom GHC.Types.Float GHC.Natural.Natural instance Witch.TryFrom.TryFrom GHC.Types.Float GHC.Real.Rational instance Witch.From.From GHC.Types.Float GHC.Types.Double instance Witch.TryFrom.TryFrom GHC.Types.Double GHC.Int.Int8 instance Witch.TryFrom.TryFrom GHC.Types.Double GHC.Int.Int16 instance Witch.TryFrom.TryFrom GHC.Types.Double GHC.Int.Int32 instance Witch.TryFrom.TryFrom GHC.Types.Double GHC.Int.Int64 instance Witch.TryFrom.TryFrom GHC.Types.Double GHC.Types.Int instance Witch.TryFrom.TryFrom GHC.Types.Double GHC.Integer.Type.Integer instance Witch.TryFrom.TryFrom GHC.Types.Double GHC.Word.Word8 instance Witch.TryFrom.TryFrom GHC.Types.Double GHC.Word.Word16 instance Witch.TryFrom.TryFrom GHC.Types.Double GHC.Word.Word32 instance Witch.TryFrom.TryFrom GHC.Types.Double GHC.Word.Word64 instance Witch.TryFrom.TryFrom GHC.Types.Double GHC.Types.Word instance Witch.TryFrom.TryFrom GHC.Types.Double GHC.Natural.Natural instance Witch.TryFrom.TryFrom GHC.Types.Double GHC.Real.Rational instance Witch.From.From GHC.Types.Double GHC.Types.Float instance GHC.Real.Integral a => Witch.From.From a (GHC.Real.Ratio a) instance (GHC.Classes.Eq a, GHC.Num.Num a) => Witch.TryFrom.TryFrom (GHC.Real.Ratio a) a instance Witch.From.From GHC.Real.Rational GHC.Types.Float instance Witch.From.From GHC.Real.Rational GHC.Types.Double instance Witch.From.From GHC.Integer.Type.Integer (Data.Fixed.Fixed a) instance Witch.From.From (Data.Fixed.Fixed a) GHC.Integer.Type.Integer instance GHC.Num.Num a => Witch.From.From a (Data.Complex.Complex a) instance (GHC.Classes.Eq a, GHC.Num.Num a) => Witch.TryFrom.TryFrom (Data.Complex.Complex a) a instance Witch.TryFrom.TryFrom [a] (GHC.Base.NonEmpty a) instance Witch.From.From (GHC.Base.NonEmpty a) [a] instance GHC.Classes.Ord a => Witch.From.From [a] (Data.Set.Internal.Set a) instance Witch.From.From (Data.Set.Internal.Set a) [a] instance Witch.From.From [GHC.Types.Int] Data.IntSet.Internal.IntSet instance Witch.From.From Data.IntSet.Internal.IntSet [GHC.Types.Int] instance GHC.Classes.Ord k => Witch.From.From [(k, v)] (Data.Map.Internal.Map k v) instance Witch.From.From (Data.Map.Internal.Map k v) [(k, v)] instance Witch.From.From [(GHC.Types.Int, v)] (Data.IntMap.Internal.IntMap v) instance Witch.From.From (Data.IntMap.Internal.IntMap v) [(GHC.Types.Int, v)] instance Witch.From.From [a] (Data.Sequence.Internal.Seq a) instance Witch.From.From (Data.Sequence.Internal.Seq a) [a] instance Witch.From.From [GHC.Word.Word8] Data.ByteString.Internal.ByteString instance Witch.From.From Data.ByteString.Internal.ByteString [GHC.Word.Word8] instance Witch.From.From Data.ByteString.Internal.ByteString Data.ByteString.Lazy.Internal.ByteString instance Witch.From.From Data.ByteString.Internal.ByteString Data.ByteString.Short.Internal.ShortByteString instance Witch.TryFrom.TryFrom Data.ByteString.Internal.ByteString Data.Text.Internal.Text instance Witch.From.From [GHC.Word.Word8] Data.ByteString.Lazy.Internal.ByteString instance Witch.From.From Data.ByteString.Lazy.Internal.ByteString [GHC.Word.Word8] instance Witch.From.From Data.ByteString.Lazy.Internal.ByteString Data.ByteString.Internal.ByteString instance Witch.TryFrom.TryFrom Data.ByteString.Lazy.Internal.ByteString Data.Text.Internal.Lazy.Text instance Witch.From.From [GHC.Word.Word8] Data.ByteString.Short.Internal.ShortByteString instance Witch.From.From Data.ByteString.Short.Internal.ShortByteString [GHC.Word.Word8] instance Witch.From.From Data.ByteString.Short.Internal.ShortByteString Data.ByteString.Internal.ByteString instance Witch.From.From GHC.Base.String Data.Text.Internal.Text instance Witch.From.From Data.Text.Internal.Text GHC.Base.String instance Witch.From.From Data.Text.Internal.Text Data.Text.Internal.Lazy.Text instance Witch.From.From Data.Text.Internal.Text Data.ByteString.Internal.ByteString instance Witch.From.From GHC.Base.String Data.Text.Internal.Lazy.Text instance Witch.From.From Data.Text.Internal.Lazy.Text GHC.Base.String instance Witch.From.From Data.Text.Internal.Lazy.Text Data.Text.Internal.Text instance Witch.From.From Data.Text.Internal.Lazy.Text Data.ByteString.Lazy.Internal.ByteString instance Witch.From.From (Witch.TryFromException.TryFromException s u) (Witch.TryFromException.TryFromException s t) instance Witch.From.From GHC.Integer.Type.Integer Data.Time.Calendar.Days.Day instance Witch.From.From Data.Time.Calendar.Days.Day GHC.Integer.Type.Integer instance Witch.From.From Data.Time.Calendar.Days.Day Data.Time.Calendar.Week.DayOfWeek instance Witch.From.From GHC.Real.Rational Data.Time.Clock.Internal.UniversalTime.UniversalTime instance Witch.From.From Data.Time.Clock.Internal.UniversalTime.UniversalTime GHC.Real.Rational instance Witch.From.From Data.Fixed.Pico Data.Time.Clock.Internal.DiffTime.DiffTime instance Witch.From.From Data.Time.Clock.Internal.DiffTime.DiffTime Data.Fixed.Pico instance Witch.From.From Data.Fixed.Pico Data.Time.Clock.Internal.NominalDiffTime.NominalDiffTime instance Witch.From.From Data.Time.Clock.Internal.NominalDiffTime.NominalDiffTime Data.Fixed.Pico instance Witch.From.From Data.Time.Clock.Internal.SystemTime.SystemTime Data.Time.Clock.Internal.POSIXTime.POSIXTime instance Witch.From.From Data.Time.Clock.Internal.UTCTime.UTCTime Data.Time.Clock.Internal.POSIXTime.POSIXTime instance Witch.From.From Data.Time.Clock.Internal.POSIXTime.POSIXTime Data.Time.Clock.Internal.UTCTime.UTCTime instance Witch.From.From Data.Time.Clock.Internal.UTCTime.UTCTime Data.Time.Clock.Internal.SystemTime.SystemTime instance Witch.From.From Data.Time.Clock.Internal.SystemTime.SystemTime Data.Time.Clock.Internal.AbsoluteTime.AbsoluteTime instance Witch.From.From Data.Time.Clock.Internal.SystemTime.SystemTime Data.Time.Clock.Internal.UTCTime.UTCTime instance Witch.From.From Data.Time.Clock.Internal.DiffTime.DiffTime Data.Time.LocalTime.Internal.TimeOfDay.TimeOfDay instance Witch.From.From GHC.Real.Rational Data.Time.LocalTime.Internal.TimeOfDay.TimeOfDay instance Witch.From.From Data.Time.LocalTime.Internal.TimeOfDay.TimeOfDay Data.Time.Clock.Internal.DiffTime.DiffTime instance Witch.From.From Data.Time.LocalTime.Internal.TimeOfDay.TimeOfDay GHC.Real.Rational instance Witch.From.From Data.Time.Calendar.CalendarDiffDays.CalendarDiffDays Data.Time.LocalTime.Internal.CalendarDiffTime.CalendarDiffTime instance Witch.From.From Data.Time.Clock.Internal.NominalDiffTime.NominalDiffTime Data.Time.LocalTime.Internal.CalendarDiffTime.CalendarDiffTime instance Witch.From.From Data.Time.LocalTime.Internal.ZonedTime.ZonedTime Data.Time.Clock.Internal.UTCTime.UTCTime -- | 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: -- --
-- >>> import Witch ---- -- In typical usage, the functions that you will use most often are -- into for conversions that always succeed and tryInto for -- conversions that sometimes fail. module Witch -- | This type class is for converting values from some source -- type into some other target type. The constraint -- From source target means that you can convert from a -- value of type source into a value of type target. -- -- This type class is for conversions that always succeed. If your -- conversion sometimes fails, consider implementing TryFrom -- instead. class From source target -- | This method implements the conversion of a value between types. At -- call sites you may prefer to use into instead. -- --
-- -- Avoid this: -- from (x :: s) -- -- -- Prefer this: -- from @s x ---- -- The default implementation of this method simply calls coerce, -- which works for types that have the same runtime representation. This -- means that for newtypes you do not need to implement this -- method at all. For example: -- --
-- >>> newtype Name = Name String -- -- >>> instance From Name String -- -- >>> instance From String Name --from :: From source target => source -> target -- | This method implements the conversion of a value between types. At -- call sites you may prefer to use into instead. -- --
-- -- Avoid this: -- from (x :: s) -- -- -- Prefer this: -- from @s x ---- -- The default implementation of this method simply calls coerce, -- which works for types that have the same runtime representation. This -- means that for newtypes you do not need to implement this -- method at all. For example: -- --
-- >>> newtype Name = Name String -- -- >>> instance From Name String -- -- >>> instance From String Name --from :: (From source target, Coercible source target) => source -> target -- | This is the same as from except that the type variables are in -- the opposite order. -- --
-- -- Avoid this: -- from x :: t -- -- -- Prefer this: -- into @t x --into :: forall target source. From source target => source -> target -- | This type class is for converting values from some source -- type into some other target type. The constraint -- TryFrom source target means that you may be able to -- convert from a value of type source into a value of type -- target, but that conversion may fail at runtime. -- -- This type class is for conversions that can sometimes fail. If your -- conversion always succeeds, consider implementing From -- instead. class TryFrom source target -- | This method implements the conversion of a value between types. At -- call sites you may want to use tryInto instead. -- --
-- -- Avoid this: -- tryFrom (x :: s) -- -- -- Prefer this: -- tryFrom @s ---- -- Consider using maybeTryFrom or eitherTryFrom to -- implement this method. tryFrom :: TryFrom source target => source -> Either (TryFromException source target) target -- | This is the same as tryFrom except that the type variables are -- in the opposite order. -- --
-- -- Avoid this: -- tryFrom x :: Either (TryFromException s t) t -- -- -- Prefer this: -- tryInto @t x --tryInto :: forall target source. TryFrom source target => source -> Either (TryFromException source target) target -- | This exception is thrown when a TryFrom conversion fails. It -- has the original source value that caused the failure and it -- knows the target type it was trying to convert into. It also -- has an optional SomeException for communicating what went wrong -- while converting. data TryFromException source target TryFromException :: source -> Maybe SomeException -> TryFromException source target -- | This is the same as id. This can be an ergonomic way to pin -- down a polymorphic type in a function pipeline. For example: -- --
-- -- Avoid this: -- f . (\ x -> x :: Int) . g -- -- -- Prefer this: -- f . as @Int . g --as :: forall source. source -> source -- | This function converts from some source type into some -- target type, applies the given function, then converts back -- into the source type. This is useful when you have two types -- that are isomorphic but some function that only works with one of -- them. -- --
-- -- Avoid this: -- from @t . f . into @t -- -- -- Prefer this: -- over @t f --over :: forall target source. (From source target, From target source) => (target -> target) -> source -> source -- | This function first converts from some source type into some -- through type, and then converts that into some -- target type. Usually this is used when writing From -- instances. Sometimes this can be used to work around the lack of an -- instance that should probably exist. -- --
-- -- Avoid this: -- from @u . into @u -- -- -- Prefer this: -- via @u --via :: forall through source target. (From source through, From through target) => source -> target -- | This is similar to via except that it works with TryFrom -- instances instead. This function is especially convenient because -- juggling the types in the TryFromException can be tedious. -- --
-- -- Avoid this: -- case tryInto @u x of -- Left (TryFromException _ e) -> Left $ TryFromException x e -- Right y -> case tryFrom @u y of -- Left (TryFromException _ e) -> Left $ TryFromException x e -- Right z -> Right z -- -- -- Prefer this: -- tryVia @u --tryVia :: forall through source target. (TryFrom source through, TryFrom through target) => source -> Either (TryFromException source target) target -- | This function can be used to implement tryFrom with a function -- that returns Maybe. For example: -- --
-- -- Avoid this: -- tryFrom s = case f s of -- Nothing -> Left $ TryFromException s Nothing -- Just t -> Right t -- -- -- Prefer this: -- tryFrom = maybeTryFrom f --maybeTryFrom :: (source -> Maybe target) -> source -> Either (TryFromException source target) target -- | This function can be used to implement tryFrom with a function -- that returns Either. For example: -- --
-- -- Avoid this: -- tryFrom s = case f s of -- Left e -> Left . TryFromException s . Just $ toException e -- Right t -> Right t -- -- -- Prefer this: -- tryFrom = eitherTryFrom f --eitherTryFrom :: Exception exception => (source -> Either exception target) -> source -> Either (TryFromException source target) target -- | This function is like tryFrom except that it will throw an -- impure exception if the conversion fails. -- --
-- -- Avoid this: -- either throw id . tryFrom @s -- -- -- Prefer this: -- unsafeFrom @s --unsafeFrom :: forall source target. (HasCallStack, TryFrom source target, Show source, Typeable source, Typeable target) => source -> target -- | This function is like tryInto except that it will throw an -- impure exception if the conversion fails. -- --
-- -- Avoid this: -- either throw id . tryInto @t -- -- -- Prefer this: -- unsafeInto @t --unsafeInto :: forall target source. (HasCallStack, TryFrom source target, Show source, Typeable source, Typeable target) => source -> target -- | This is like unsafeFrom except that it works at compile time -- rather than runtime. -- --
-- -- Avoid this: -- unsafeFrom @s "some literal" -- -- -- Prefer this: -- $$(liftedFrom @s "some literal") --liftedFrom :: forall source target. (TryFrom source target, Lift target, Show source, Typeable source, Typeable target) => source -> Q (TExp target) -- | This is like unsafeInto except that it works at compile time -- rather than runtime. -- --
-- -- Avoid this: -- unsafeInto @t "some literal" -- -- -- Prefer this: -- $$(liftedInto @t "some literal") --liftedInto :: forall target source. (TryFrom source target, Lift target, Show source, Typeable source, Typeable target) => source -> Q (TExp target)