Basement.From

basement-0.0.12: Foundation scrap box of array & string

License | BSD-style
Maintainer | Haskell Foundation
Safe Haskell | Safe-Inferred
Language | Haskell2010

Basement.From

Description

Flexible Type convertion

From is multi parameter type class that allow converting from a to b.

Only type that are valid to convert to another type should be From instance; otherwise TryFrom should be used.

Into (resp TryInto) allows the contrary instances to be able to specify the destination type before the source. This is practical with TypeApplication

Synopsis

- class From a b where
  - from :: a -> b
- type Into b a = From a b
- class TryFrom a b where
  - tryFrom :: a -> Maybe b
- type TryInto b a = TryFrom a b
- into :: Into b a => a -> b
- tryInto :: TryInto b a => a -> Maybe b

# Documentation

class From a b where #

Class of things that can be converted from a to b.

In a valid instance, the source should be always representable by the destination, otherwise the instance should be using `TryFrom`

Methods

from :: a -> b #

#### Instances

Instances details

From Int16 Int32 # |
Instance details Defined in Basement.From Methods from :: Int16 -> Int32 #
From Int16 Int64 # |
Instance details Defined in Basement.From Methods from :: Int16 -> Int64 #
From Int16 Int # |
Instance details Defined in Basement.From Methods from :: Int16 -> Int #
From Int32 Int64 # |
Instance details Defined in Basement.From Methods from :: Int32 -> Int64 #
From Int32 Int # |
Instance details Defined in Basement.From Methods from :: Int32 -> Int #
From Int8 Int16 # |
Instance details Defined in Basement.From Methods from :: Int8 -> Int16 #
From Int8 Int32 # |
Instance details Defined in Basement.From Methods from :: Int8 -> Int32 #
From Int8 Int64 # |
Instance details Defined in Basement.From Methods from :: Int8 -> Int64 #
From Int8 Int # |
Instance details Defined in Basement.From Methods from :: Int8 -> Int #
From Word16 Int32 # |
Instance details Defined in Basement.From Methods from :: Word16 -> Int32 #
From Word16 Int64 # |
Instance details Defined in Basement.From Methods from :: Word16 -> Int64 #
From Word16 Word32 # |
Instance details Defined in Basement.From Methods from :: Word16 -> Word32 #
From Word16 Word64 # |
Instance details Defined in Basement.From Methods from :: Word16 -> Word64 #
From Word16 Word128 # |
Instance details Defined in Basement.From Methods from :: Word16 -> Word128 #
From Word16 Word256 # |
Instance details Defined in Basement.From Methods from :: Word16 -> Word256 #
From Word16 Int # |
Instance details Defined in Basement.From Methods from :: Word16 -> Int #
From Word16 Word # |
Instance details Defined in Basement.From Methods from :: Word16 -> Word #
From Word32 Int64 # |
Instance details Defined in Basement.From Methods from :: Word32 -> Int64 #
From Word32 Word64 # |
Instance details Defined in Basement.From Methods from :: Word32 -> Word64 #
From Word32 Word128 # |
Instance details Defined in Basement.From Methods from :: Word32 -> Word128 #
From Word32 Word256 # |
Instance details Defined in Basement.From Methods from :: Word32 -> Word256 #
From Word32 Int # |
Instance details Defined in Basement.From Methods from :: Word32 -> Int #
From Word32 Word # |
Instance details Defined in Basement.From Methods from :: Word32 -> Word #
From Word64 Word128 # |
Instance details Defined in Basement.From Methods from :: Word64 -> Word128 #
From Word64 Word256 # |
Instance details Defined in Basement.From Methods from :: Word64 -> Word256 #
From Word8 Int16 # |
Instance details Defined in Basement.From Methods from :: Word8 -> Int16 #
From Word8 Int32 # |
Instance details Defined in Basement.From Methods from :: Word8 -> Int32 #
From Word8 Int64 # |
Instance details Defined in Basement.From Methods from :: Word8 -> Int64 #
From Word8 Word16 # |
Instance details Defined in Basement.From Methods from :: Word8 -> Word16 #
From Word8 Word32 # |
Instance details Defined in Basement.From Methods from :: Word8 -> Word32 #
From Word8 Word64 # |
Instance details Defined in Basement.From Methods from :: Word8 -> Word64 #
From Word8 Word128 # |
Instance details Defined in Basement.From Methods from :: Word8 -> Word128 #
From Word8 Word256 # |
Instance details Defined in Basement.From Methods from :: Word8 -> Word256 #
From Word8 Int # |
Instance details Defined in Basement.From Methods from :: Word8 -> Int #
From Word8 Word # |
Instance details Defined in Basement.From Methods from :: Word8 -> Word #
From AsciiString String # |
Instance details Defined in Basement.From Methods from :: AsciiString -> String #
From Word128 Word256 # |
Instance details Defined in Basement.From Methods from :: Word128 -> Word256 #
From Int Int64 # |
Instance details Defined in Basement.From Methods from :: Int -> Int64 #
From Word Word64 # |
Instance details Defined in Basement.From Methods from :: Word -> Word64 #
From a a # |
Instance details Defined in Basement.From Methods from :: a -> a #
IsIntegral n => From n Integer # |
Instance details Defined in Basement.From Methods from :: n -> Integer #
IsNatural n => From n Natural # |
Instance details Defined in Basement.From Methods from :: n -> Natural #
From AsciiString (UArray Word8) # |
Instance details Defined in Basement.From Methods from :: AsciiString -> UArray Word8 #
From String (UArray Word8) # |
Instance details Defined in Basement.From Methods from :: String -> UArray Word8 #
From Word (CountOf ty) # |
Instance details Defined in Basement.From Methods from :: Word -> CountOf ty #
From Word (Offset ty) # |
Instance details Defined in Basement.From Methods from :: Word -> Offset ty #
(KnownNat n, NatWithinBound Word16 n) => From (Zn n) Word16 # |
Instance details Defined in Basement.From Methods from :: Zn n -> Word16 #
(KnownNat n, NatWithinBound Word32 n) => From (Zn n) Word32 # |
Instance details Defined in Basement.From Methods from :: Zn n -> Word32 #
(KnownNat n, NatWithinBound Word64 n) => From (Zn n) Word64 # |
Instance details Defined in Basement.From Methods from :: Zn n -> Word64 #
(KnownNat n, NatWithinBound Word8 n) => From (Zn n) Word8 # |
Instance details Defined in Basement.From Methods from :: Zn n -> Word8 #
(KnownNat n, NatWithinBound Word128 n) => From (Zn n) Word128 # |
Instance details Defined in Basement.From Methods from :: Zn n -> Word128 #
(KnownNat n, NatWithinBound Word256 n) => From (Zn n) Word256 # |
Instance details Defined in Basement.From Methods from :: Zn n -> Word256 #
(KnownNat n, NatWithinBound Word16 n) => From (Zn64 n) Word16 # |
Instance details Defined in Basement.From Methods from :: Zn64 n -> Word16 #
(KnownNat n, NatWithinBound Word32 n) => From (Zn64 n) Word32 # |
Instance details Defined in Basement.From Methods from :: Zn64 n -> Word32 #
From (Zn64 n) Word64 # |
Instance details Defined in Basement.From Methods from :: Zn64 n -> Word64 #
(KnownNat n, NatWithinBound Word8 n) => From (Zn64 n) Word8 # |
Instance details Defined in Basement.From Methods from :: Zn64 n -> Word8 #
From (Zn64 n) Word128 # |
Instance details Defined in Basement.From Methods from :: Zn64 n -> Word128 #
From (Zn64 n) Word256 # |
Instance details Defined in Basement.From Methods from :: Zn64 n -> Word256 #
From (CountOf ty) Int # |
Instance details Defined in Basement.From Methods from :: CountOf ty -> Int #
From (CountOf ty) Word # |
Instance details Defined in Basement.From Methods from :: CountOf ty -> Word #
PrimType ty => From (Block ty) (UArray ty) # |
Instance details Defined in Basement.From Methods from :: Block ty -> UArray ty #
(KnownNat n, NatWithinBound Word64 n) => From (Zn n) (Zn64 n) # |
Instance details Defined in Basement.From Methods from :: Zn n -> Zn64 n #
KnownNat n => From (Zn64 n) (Zn n) # |
Instance details Defined in Basement.From Methods from :: Zn64 n -> Zn n #
PrimType ty => From (Array ty) (Block ty) # |
Instance details Defined in Basement.From Methods from :: Array ty -> Block ty #
PrimType ty => From (Array ty) (UArray ty) # |
Instance details Defined in Basement.From Methods from :: Array ty -> UArray ty #
PrimType ty => From (UArray ty) (Block ty) # |
Instance details Defined in Basement.From Methods from :: UArray ty -> Block ty #
PrimType ty => From (UArray ty) (Array ty) # |
Instance details Defined in Basement.From Methods from :: UArray ty -> Array ty #
From (Maybe a) (Either () a) # |
Instance details Defined in Basement.From Methods from :: Maybe a -> Either () a #
From (BlockN n ty) (Block ty) # |
Instance details Defined in Basement.From Methods from :: BlockN n ty -> Block ty #
(NatWithinBound Int n, PrimType ty) => From (BlockN n ty) (Array ty) # |
Instance details Defined in Basement.From Methods from :: BlockN n ty -> Array ty #
(NatWithinBound Int n, PrimType ty) => From (BlockN n ty) (UArray ty) # |
Instance details Defined in Basement.From Methods from :: BlockN n ty -> UArray ty #
From (Either a b) (These a b) # |
Instance details Defined in Basement.From Methods from :: Either a b -> These a b #
(PrimType a, PrimType b, KnownNat n, KnownNat m, (PrimSize b * m) ~ (PrimSize a * n)) => From (BlockN n a) (BlockN m b) # |
Instance details Defined in Basement.From Methods from :: BlockN n a -> BlockN m b #

type Into b a = From a b #

class TryFrom a b where #

Class of things that can mostly be converted from a to b, but with possible error cases.

Methods

tryFrom :: a -> Maybe b #

#### Instances

Instances details

TryFrom Int (CountOf ty) # |
Instance details Defined in Basement.From Methods tryFrom :: Int -> Maybe (CountOf ty) #
TryFrom Int (Offset ty) # |
Instance details Defined in Basement.From Methods tryFrom :: Int -> Maybe (Offset ty) #
TryFrom (UArray Word8) String # |
Instance details Defined in Basement.From Methods tryFrom :: UArray Word8 -> Maybe String #
(NatWithinBound (CountOf ty) n, KnownNat n, PrimType ty) => TryFrom (Block ty) (BlockN n ty) # |
Instance details Defined in Basement.From Methods tryFrom :: Block ty -> Maybe (BlockN n ty) #
(NatWithinBound (CountOf ty) n, KnownNat n, PrimType ty) => TryFrom (Array ty) (BlockN n ty) # |
Instance details Defined in Basement.From Methods tryFrom :: Array ty -> Maybe (BlockN n ty) #
(NatWithinBound (CountOf ty) n, KnownNat n, PrimType ty) => TryFrom (UArray ty) (BlockN n ty) # |
Instance details Defined in Basement.From Methods tryFrom :: UArray ty -> Maybe (BlockN n ty) #

type TryInto b a = TryFrom a b #

into :: Into b a => a -> b #

Same as from but reverse the type variable so that the destination type can be specified first

e.g. converting:

from `_` Word (10 :: Int)

into @Word (10 :: Int)

tryInto :: TryInto b a => a -> Maybe b #

same as tryFrom but reversed