-- 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.2 -- | This module provides the From 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 From String Name -- instance From 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 -- from (123 :: Int) :: 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 ---- -- The default implementation of from simply calls coerce, -- which works for types that have the same runtime representation. from :: From a b => a -> b -- | This method converts a value from one type into another. This is -- intended to be used with the TypeApplications language -- extension. For example, here are a few ways to convert from an -- Int into an Integer: -- --
-- from @Int @Integer 123 -- from @_ @Integer (123 :: Int) -- from @Int @_ 123 :: Integer -- from @Int 123 :: Integer -- from (123 :: Int) :: 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 ---- -- The default implementation of from simply calls coerce, -- which works for types that have the same runtime representation. from :: (From a b, Coercible a b) => a -> b -- | 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 b a. From a b => a -> b -- | This function converts a value from one type into another by going -- through some third type. This is the same as calling 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 b a c. (From a b, From b c) => a -> c instance Witch.From a a instance Witch.From a (x -> a) instance Witch.From a [a] instance Witch.From a (GHC.Maybe.Maybe a) instance Witch.From a (Data.Either.Either a x) instance Witch.From a (Data.Either.Either x a) instance Witch.From Data.Void.Void x instance Witch.From (a, x) a instance Witch.From (x, a) a instance Witch.From (a, b) (b, a) instance Witch.From (GHC.Base.NonEmpty a) [a] instance Witch.From GHC.Word.Word8 GHC.Word.Word16 instance Witch.From GHC.Word.Word16 GHC.Word.Word32 instance Witch.From GHC.Word.Word32 GHC.Word.Word64 instance Witch.From GHC.Types.Word GHC.Natural.Natural instance Witch.From GHC.Natural.Natural GHC.Integer.Type.Integer instance Witch.From GHC.Int.Int8 GHC.Int.Int16 instance Witch.From GHC.Int.Int16 GHC.Int.Int32 instance Witch.From GHC.Int.Int32 GHC.Int.Int64 instance Witch.From GHC.Types.Int GHC.Integer.Type.Integer instance Witch.From GHC.Integer.Type.Integer GHC.Real.Rational instance Witch.From GHC.Types.Float GHC.Types.Double instance Witch.From GHC.Types.Bool GHC.Types.Int instance Witch.From GHC.Types.Char GHC.Types.Int instance Witch.From [GHC.Word.Word8] Data.ByteString.Internal.ByteString instance Witch.From Data.ByteString.Internal.ByteString [GHC.Word.Word8] instance Witch.From Data.ByteString.Internal.ByteString Data.ByteString.Lazy.Internal.ByteString instance Witch.From Data.ByteString.Lazy.Internal.ByteString Data.ByteString.Internal.ByteString instance Witch.From GHC.Base.String Data.Text.Internal.Text instance Witch.From Data.Text.Internal.Text GHC.Base.String instance Witch.From Data.Text.Internal.Text Data.Text.Internal.Lazy.Text instance Witch.From Data.Text.Internal.Lazy.Text Data.Text.Internal.Text instance Witch.From [a] (Data.Sequence.Internal.Seq a) instance Witch.From (Data.Sequence.Internal.Seq a) [a] instance GHC.Classes.Ord a => Witch.From [a] (Data.Set.Internal.Set a) instance Witch.From (Data.Set.Internal.Set a) [a] instance GHC.Classes.Ord k => Witch.From [(k, v)] (Data.Map.Internal.Map k v) instance Witch.From (Data.Map.Internal.Map k v) [(k, v)]