basement-0.0.2: 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 #

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

Minimal complete definition

from

Methods

from :: a -> b #

Instances

From Int Int64 # 

Methods

from :: Int -> Int64 #

From Int Word # 

Methods

from :: Int -> Word #

From Int8 Int # 

Methods

from :: Int8 -> Int #

From Int8 Int16 # 

Methods

from :: Int8 -> Int16 #

From Int8 Int32 # 

Methods

from :: Int8 -> Int32 #

From Int8 Int64 # 

Methods

from :: Int8 -> Int64 #

From Int16 Int # 

Methods

from :: Int16 -> Int #

From Int16 Int32 # 

Methods

from :: Int16 -> Int32 #

From Int16 Int64 # 

Methods

from :: Int16 -> Int64 #

From Int32 Int # 

Methods

from :: Int32 -> Int #

From Int32 Int64 # 

Methods

from :: Int32 -> Int64 #

From Word Int # 

Methods

from :: Word -> Int #

From Word Word64 # 

Methods

from :: Word -> Word64 #

From Word8 Int # 

Methods

from :: Word8 -> Int #

From Word8 Int16 # 

Methods

from :: Word8 -> Int16 #

From Word8 Int32 # 

Methods

from :: Word8 -> Int32 #

From Word8 Int64 # 

Methods

from :: Word8 -> Int64 #

From Word8 Word # 

Methods

from :: Word8 -> Word #

From Word8 Word16 # 

Methods

from :: Word8 -> Word16 #

From Word8 Word32 # 

Methods

from :: Word8 -> Word32 #

From Word8 Word64 # 

Methods

from :: Word8 -> Word64 #

From Word8 Word128 # 

Methods

from :: Word8 -> Word128 #

From Word8 Word256 # 

Methods

from :: Word8 -> Word256 #

From Word16 Word # 

Methods

from :: Word16 -> Word #

From Word16 Word32 # 

Methods

from :: Word16 -> Word32 #

From Word16 Word64 # 

Methods

from :: Word16 -> Word64 #

From Word16 Word128 # 

Methods

from :: Word16 -> Word128 #

From Word16 Word256 # 

Methods

from :: Word16 -> Word256 #

From Word32 Word # 

Methods

from :: Word32 -> Word #

From Word32 Word64 # 

Methods

from :: Word32 -> Word64 #

From Word32 Word128 # 

Methods

from :: Word32 -> Word128 #

From Word32 Word256 # 

Methods

from :: Word32 -> Word256 #

From Word64 Word128 # 

Methods

from :: Word64 -> Word128 #

From Word64 Word256 # 

Methods

from :: Word64 -> Word256 #

IsIntegral n => From n Integer # 

Methods

from :: n -> Integer #

IsNatural n => From n Natural # 

Methods

from :: n -> Natural #

From a a # 

Methods

from :: a -> a #

From AsciiString String # 

Methods

from :: AsciiString -> String #

From AsciiString (UArray Word8) # 
From String (UArray Word8) # 

Methods

from :: String -> UArray Word8 #

From (CountOf ty) Word # 

Methods

from :: CountOf ty -> Word #

From (CountOf ty) Int # 

Methods

from :: CountOf ty -> Int #

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

Methods

from :: Zn n -> Word256 #

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

Methods

from :: Zn n -> Word128 #

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

Methods

from :: Zn n -> Word64 #

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

Methods

from :: Zn n -> Word32 #

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

Methods

from :: Zn n -> Word16 #

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

Methods

from :: Zn n -> Word8 #

From (Zn64 n) Word256 # 

Methods

from :: Zn64 n -> Word256 #

From (Zn64 n) Word128 # 

Methods

from :: Zn64 n -> Word128 #

From (Zn64 n) Word64 # 

Methods

from :: Zn64 n -> Word64 #

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

Methods

from :: Zn64 n -> Word32 #

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

Methods

from :: Zn64 n -> Word16 #

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

Methods

from :: Zn64 n -> Word8 #

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

Methods

from :: Zn n -> Zn64 n #

KnownNat n => From (Zn64 n) (Zn n) # 

Methods

from :: Zn64 n -> Zn n #

PrimType ty => From (Block ty) (UArray ty) # 

Methods

from :: Block ty -> UArray ty #

PrimType ty => From (UArray ty) (Array ty) # 

Methods

from :: UArray ty -> Array ty #

PrimType ty => From (UArray ty) (Block ty) # 

Methods

from :: UArray ty -> Block ty #

PrimType ty => From (Array ty) (Block ty) # 

Methods

from :: Array ty -> Block ty #

PrimType ty => From (Array ty) (UArray ty) # 

Methods

from :: Array ty -> UArray ty #

From (Maybe a) (Either () a) # 

Methods

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

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

Methods

from :: BlockN n ty -> Array ty #

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

Methods

from :: BlockN n ty -> UArray ty #

From (BlockN n ty) (Block ty) # 

Methods

from :: BlockN n ty -> Block ty #

From (Either a b) (These a b) # 

Methods

from :: Either a b -> These a 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.

Minimal complete definition

tryFrom

Methods

tryFrom :: a -> Maybe b #

Instances

TryFrom (UArray Word8) String # 
(NatWithinBound (CountOf ty) n, KnownNat n, PrimType ty) => TryFrom (Block ty) (BlockN n ty) # 

Methods

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

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

Methods

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

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

Methods

tryFrom :: Array 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