basement-0.0.11: Foundation scrap box of array & string

LicenseBSD-style
MaintainerHaskell Foundation
Safe HaskellNone
LanguageHaskell2010

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

Documentation

class From a b where Source #

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 Source #

Instances
From Int Int64 Source # 
Instance details

Defined in Basement.From

Methods

from :: Int -> Int64 Source #

From Int8 Int Source # 
Instance details

Defined in Basement.From

Methods

from :: Int8 -> Int Source #

From Int8 Int16 Source # 
Instance details

Defined in Basement.From

Methods

from :: Int8 -> Int16 Source #

From Int8 Int32 Source # 
Instance details

Defined in Basement.From

Methods

from :: Int8 -> Int32 Source #

From Int8 Int64 Source # 
Instance details

Defined in Basement.From

Methods

from :: Int8 -> Int64 Source #

From Int16 Int Source # 
Instance details

Defined in Basement.From

Methods

from :: Int16 -> Int Source #

From Int16 Int32 Source # 
Instance details

Defined in Basement.From

Methods

from :: Int16 -> Int32 Source #

From Int16 Int64 Source # 
Instance details

Defined in Basement.From

Methods

from :: Int16 -> Int64 Source #

From Int32 Int Source # 
Instance details

Defined in Basement.From

Methods

from :: Int32 -> Int Source #

From Int32 Int64 Source # 
Instance details

Defined in Basement.From

Methods

from :: Int32 -> Int64 Source #

From Word Word64 Source # 
Instance details

Defined in Basement.From

Methods

from :: Word -> Word64 Source #

From Word8 Int Source # 
Instance details

Defined in Basement.From

Methods

from :: Word8 -> Int Source #

From Word8 Int16 Source # 
Instance details

Defined in Basement.From

Methods

from :: Word8 -> Int16 Source #

From Word8 Int32 Source # 
Instance details

Defined in Basement.From

Methods

from :: Word8 -> Int32 Source #

From Word8 Int64 Source # 
Instance details

Defined in Basement.From

Methods

from :: Word8 -> Int64 Source #

From Word8 Word Source # 
Instance details

Defined in Basement.From

Methods

from :: Word8 -> Word Source #

From Word8 Word16 Source # 
Instance details

Defined in Basement.From

Methods

from :: Word8 -> Word16 Source #

From Word8 Word32 Source # 
Instance details

Defined in Basement.From

Methods

from :: Word8 -> Word32 Source #

From Word8 Word64 Source # 
Instance details

Defined in Basement.From

Methods

from :: Word8 -> Word64 Source #

From Word8 Word128 Source # 
Instance details

Defined in Basement.From

Methods

from :: Word8 -> Word128 Source #

From Word8 Word256 Source # 
Instance details

Defined in Basement.From

Methods

from :: Word8 -> Word256 Source #

From Word16 Int Source # 
Instance details

Defined in Basement.From

Methods

from :: Word16 -> Int Source #

From Word16 Int32 Source # 
Instance details

Defined in Basement.From

Methods

from :: Word16 -> Int32 Source #

From Word16 Int64 Source # 
Instance details

Defined in Basement.From

Methods

from :: Word16 -> Int64 Source #

From Word16 Word Source # 
Instance details

Defined in Basement.From

Methods

from :: Word16 -> Word Source #

From Word16 Word32 Source # 
Instance details

Defined in Basement.From

Methods

from :: Word16 -> Word32 Source #

From Word16 Word64 Source # 
Instance details

Defined in Basement.From

Methods

from :: Word16 -> Word64 Source #

From Word16 Word128 Source # 
Instance details

Defined in Basement.From

Methods

from :: Word16 -> Word128 Source #

From Word16 Word256 Source # 
Instance details

Defined in Basement.From

Methods

from :: Word16 -> Word256 Source #

From Word32 Int Source # 
Instance details

Defined in Basement.From

Methods

from :: Word32 -> Int Source #

From Word32 Int64 Source # 
Instance details

Defined in Basement.From

Methods

from :: Word32 -> Int64 Source #

From Word32 Word Source # 
Instance details

Defined in Basement.From

Methods

from :: Word32 -> Word Source #

From Word32 Word64 Source # 
Instance details

Defined in Basement.From

Methods

from :: Word32 -> Word64 Source #

From Word32 Word128 Source # 
Instance details

Defined in Basement.From

Methods

from :: Word32 -> Word128 Source #

From Word32 Word256 Source # 
Instance details

Defined in Basement.From

Methods

from :: Word32 -> Word256 Source #

From Word64 Word128 Source # 
Instance details

Defined in Basement.From

Methods

from :: Word64 -> Word128 Source #

From Word64 Word256 Source # 
Instance details

Defined in Basement.From

Methods

from :: Word64 -> Word256 Source #

IsIntegral n => From n Integer Source # 
Instance details

Defined in Basement.From

Methods

from :: n -> Integer Source #

IsNatural n => From n Natural Source # 
Instance details

Defined in Basement.From

Methods

from :: n -> Natural Source #

From a a Source # 
Instance details

Defined in Basement.From

Methods

from :: a -> a Source #

From Word128 Word256 Source # 
Instance details

Defined in Basement.From

Methods

from :: Word128 -> Word256 Source #

From AsciiString String Source # 
Instance details

Defined in Basement.From

From Word (CountOf ty) Source # 
Instance details

Defined in Basement.From

Methods

from :: Word -> CountOf ty Source #

From Word (Offset ty) Source # 
Instance details

Defined in Basement.From

Methods

from :: Word -> Offset ty Source #

From AsciiString (UArray Word8) Source # 
Instance details

Defined in Basement.From

From String (UArray Word8) Source # 
Instance details

Defined in Basement.From

(KnownNat n, NatWithinBound Word256 n) => From (Zn n) Word256 Source # 
Instance details

Defined in Basement.From

Methods

from :: Zn n -> Word256 Source #

(KnownNat n, NatWithinBound Word128 n) => From (Zn n) Word128 Source # 
Instance details

Defined in Basement.From

Methods

from :: Zn n -> Word128 Source #

(KnownNat n, NatWithinBound Word64 n) => From (Zn n) Word64 Source # 
Instance details

Defined in Basement.From

Methods

from :: Zn n -> Word64 Source #

(KnownNat n, NatWithinBound Word32 n) => From (Zn n) Word32 Source # 
Instance details

Defined in Basement.From

Methods

from :: Zn n -> Word32 Source #

(KnownNat n, NatWithinBound Word16 n) => From (Zn n) Word16 Source # 
Instance details

Defined in Basement.From

Methods

from :: Zn n -> Word16 Source #

(KnownNat n, NatWithinBound Word8 n) => From (Zn n) Word8 Source # 
Instance details

Defined in Basement.From

Methods

from :: Zn n -> Word8 Source #

From (Zn64 n) Word256 Source # 
Instance details

Defined in Basement.From

Methods

from :: Zn64 n -> Word256 Source #

From (Zn64 n) Word128 Source # 
Instance details

Defined in Basement.From

Methods

from :: Zn64 n -> Word128 Source #

From (Zn64 n) Word64 Source # 
Instance details

Defined in Basement.From

Methods

from :: Zn64 n -> Word64 Source #

(KnownNat n, NatWithinBound Word32 n) => From (Zn64 n) Word32 Source # 
Instance details

Defined in Basement.From

Methods

from :: Zn64 n -> Word32 Source #

(KnownNat n, NatWithinBound Word16 n) => From (Zn64 n) Word16 Source # 
Instance details

Defined in Basement.From

Methods

from :: Zn64 n -> Word16 Source #

(KnownNat n, NatWithinBound Word8 n) => From (Zn64 n) Word8 Source # 
Instance details

Defined in Basement.From

Methods

from :: Zn64 n -> Word8 Source #

From (CountOf ty) Word Source # 
Instance details

Defined in Basement.From

Methods

from :: CountOf ty -> Word Source #

From (CountOf ty) Int Source # 
Instance details

Defined in Basement.From

Methods

from :: CountOf ty -> Int Source #

(KnownNat n, NatWithinBound Word64 n) => From (Zn n) (Zn64 n) Source # 
Instance details

Defined in Basement.From

Methods

from :: Zn n -> Zn64 n Source #

KnownNat n => From (Zn64 n) (Zn n) Source # 
Instance details

Defined in Basement.From

Methods

from :: Zn64 n -> Zn n Source #

PrimType ty => From (Block ty) (UArray ty) Source # 
Instance details

Defined in Basement.From

Methods

from :: Block ty -> UArray ty Source #

PrimType ty => From (UArray ty) (Array ty) Source # 
Instance details

Defined in Basement.From

Methods

from :: UArray ty -> Array ty Source #

PrimType ty => From (UArray ty) (Block ty) Source # 
Instance details

Defined in Basement.From

Methods

from :: UArray ty -> Block ty Source #

PrimType ty => From (Array ty) (Block ty) Source # 
Instance details

Defined in Basement.From

Methods

from :: Array ty -> Block ty Source #

PrimType ty => From (Array ty) (UArray ty) Source # 
Instance details

Defined in Basement.From

Methods

from :: Array ty -> UArray ty Source #

From (Maybe a) (Either () a) Source # 
Instance details

Defined in Basement.From

Methods

from :: Maybe a -> Either () a Source #

(NatWithinBound Int n, PrimType ty) => From (BlockN n ty) (Array ty) Source # 
Instance details

Defined in Basement.From

Methods

from :: BlockN n ty -> Array ty Source #

(NatWithinBound Int n, PrimType ty) => From (BlockN n ty) (UArray ty) Source # 
Instance details

Defined in Basement.From

Methods

from :: BlockN n ty -> UArray ty Source #

From (BlockN n ty) (Block ty) Source # 
Instance details

Defined in Basement.From

Methods

from :: BlockN n ty -> Block ty Source #

From (Either a b) (These a b) Source # 
Instance details

Defined in Basement.From

Methods

from :: Either a b -> These a b Source #

(PrimType a, PrimType b, KnownNat n, KnownNat m, (PrimSize b * m) ~ (PrimSize a * n)) => From (BlockN n a) (BlockN m b) Source # 
Instance details

Defined in Basement.From

Methods

from :: BlockN n a -> BlockN m b Source #

type Into b a = From a b Source #

class TryFrom a b where Source #

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

Methods

tryFrom :: a -> Maybe b Source #

Instances
TryFrom Int (CountOf ty) Source # 
Instance details

Defined in Basement.From

Methods

tryFrom :: Int -> Maybe (CountOf ty) Source #

TryFrom Int (Offset ty) Source # 
Instance details

Defined in Basement.From

Methods

tryFrom :: Int -> Maybe (Offset ty) Source #

TryFrom (UArray Word8) String Source # 
Instance details

Defined in Basement.From

(NatWithinBound (CountOf ty) n, KnownNat n, PrimType ty) => TryFrom (Block ty) (BlockN n ty) Source # 
Instance details

Defined in Basement.From

Methods

tryFrom :: Block ty -> Maybe (BlockN n ty) Source #

(NatWithinBound (CountOf ty) n, KnownNat n, PrimType ty) => TryFrom (UArray ty) (BlockN n ty) Source # 
Instance details

Defined in Basement.From

Methods

tryFrom :: UArray ty -> Maybe (BlockN n ty) Source #

(NatWithinBound (CountOf ty) n, KnownNat n, PrimType ty) => TryFrom (Array ty) (BlockN n ty) Source # 
Instance details

Defined in Basement.From

Methods

tryFrom :: Array ty -> Maybe (BlockN n ty) Source #

type TryInto b a = TryFrom a b Source #

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

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 Source #

same as tryFrom but reversed