-- 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.0.0.4 -- | This module provides the Cast type class for converting values -- between various types. This aims to be a common interface for the -- various xToY or yFromX functions you might write -- instead. It is inspired by the std::convert::From trait that -- the Rust programming language provides. -- -- Many Haskell libraries already provide similar functionality. Here's -- how this module compares to them: -- --
-- newtype Name = Name String -- instance Cast String Name -- instance Cast Name String ---- -- And then you could convert back and forth between Names and -- Strings: -- --
-- let someString = "Taylor" -- let someName = Name someString -- into @Name someString -- convert from string to name -- into @String someName -- convert from name to string ---- -- This type class does not have any laws, but it does have some -- expectations: -- --
-- from @Int @Integer 123 -- from @_ @Integer (123 :: Int) -- from @Int @_ 123 :: Integer -- from @Int 123 :: Integer ---- -- Often the context around an expression will make the explicit type -- signatures unnecessary. If you find yourself using a partial type -- signature, consider using into instead. For example: -- --
-- let someInt = 123 :: Int -- from @_ @Integer someInt -- avoid this -- into @Integer someInt -- prefer this --from :: forall s target source. (Ambiguous s ~ source, Cast source target) => source -> target -- | This function converts a value from one type into another. This is the -- same as from except that the type variables are in the opposite -- order. into :: forall t source target. (Ambiguous t ~ target, Cast source target) => source -> target -- | This function converts a value from one type into another by going -- through some third type. This is the same as calling cast (or -- from or into) twice, but can sometimes be more -- convenient. -- -- Note that the type in the middle of the conversion is the first type -- variable of this function. In other words, via @b @a @c first -- converts from a to b, and then from b to -- c. Often both a and c will be inferred from -- context, which means you can just write via @b. via :: forall through source target. (Cast source through, Cast through target) => source -> target instance Witch.Cast a a instance Witch.Cast a (x -> a) instance Witch.Cast a [a] instance Witch.Cast a (GHC.Maybe.Maybe a) instance Witch.Cast a (Data.Either.Either a x) instance Witch.Cast a (Data.Either.Either x a) instance Witch.Cast Data.Void.Void x instance Witch.Cast (a, x) a instance Witch.Cast (x, a) a instance Witch.Cast (a, b) (b, a) instance Witch.Cast (GHC.Base.NonEmpty a) [a] instance Witch.Cast GHC.Word.Word8 GHC.Word.Word16 instance Witch.Cast GHC.Word.Word16 GHC.Word.Word32 instance Witch.Cast GHC.Word.Word32 GHC.Word.Word64 instance Witch.Cast GHC.Types.Word GHC.Natural.Natural instance Witch.Cast GHC.Natural.Natural GHC.Integer.Type.Integer instance Witch.Cast GHC.Int.Int8 GHC.Int.Int16 instance Witch.Cast GHC.Int.Int16 GHC.Int.Int32 instance Witch.Cast GHC.Int.Int32 GHC.Int.Int64 instance Witch.Cast GHC.Types.Int GHC.Integer.Type.Integer instance Witch.Cast GHC.Integer.Type.Integer GHC.Real.Rational instance Witch.Cast GHC.Types.Float GHC.Types.Double instance Witch.Cast GHC.Types.Bool GHC.Types.Int instance Witch.Cast GHC.Types.Char GHC.Types.Int instance Witch.Cast [GHC.Word.Word8] Data.ByteString.Internal.ByteString instance Witch.Cast Data.ByteString.Internal.ByteString [GHC.Word.Word8] instance Witch.Cast Data.ByteString.Internal.ByteString Data.ByteString.Lazy.Internal.ByteString instance Witch.Cast Data.ByteString.Lazy.Internal.ByteString Data.ByteString.Internal.ByteString instance Witch.Cast GHC.Base.String Data.Text.Internal.Text instance Witch.Cast Data.Text.Internal.Text GHC.Base.String instance Witch.Cast Data.Text.Internal.Text Data.Text.Internal.Lazy.Text instance Witch.Cast Data.Text.Internal.Lazy.Text Data.Text.Internal.Text instance Witch.Cast [a] (Data.Sequence.Internal.Seq a) instance Witch.Cast (Data.Sequence.Internal.Seq a) [a] instance GHC.Classes.Ord a => Witch.Cast [a] (Data.Set.Internal.Set a) instance Witch.Cast (Data.Set.Internal.Set a) [a] instance GHC.Classes.Ord k => Witch.Cast [(k, v)] (Data.Map.Internal.Map k v) instance Witch.Cast (Data.Map.Internal.Map k v) [(k, v)]