feldspar-language-0.6.0.2: A functional embedded language for DSP and parallelism

Safe Haskell | None

Feldspar.Core.Types

Contents

- Heterogenous lists
- Integers
- Arrays
- Monadic Types
- Mutable data
- Par Monad
- Future values
- Type representation
- Sized types

Synopsis

- data a :> b = a :> b
- newtype WordN = WordN Word32
- newtype IntN = IntN Int32
- data N8
- data N16
- data N32
- data N64
- data NNative
- data BitWidth n where
  - N8 :: BitWidth N8
  - N16 :: BitWidth N16
  - N32 :: BitWidth N32
  - N64 :: BitWidth N64
  - NNative :: BitWidth NNative
- bitWidth :: BitWidth n -> String
- data U
- data S
- data Signedness s where
  - U :: Signedness U
  - S :: Signedness S
- signedness :: Signedness s -> String
- type family GenericInt s n
- type family WidthOf a
- type family SignOf a
- fromWordN :: BitWidth n -> WordN -> GenericInt U n
- fromIntN :: BitWidth n -> IntN -> GenericInt S n
- genericLen :: BitWidth n -> [a] -> GenericInt U n
- type Length = WordN
- type Index = WordN
- data TargetArr n a = TargetArr (GenericInt U n) [a]
- class MonadType m where
  - voidTypeRep :: TypeRep (m ())
- type Mut = IO
- type MArr a = IOArray Index a
- type Par = Par
- type IV = IVar
- newtype FVal a = FVal {
  - unFVal :: a
  }
- data TypeRep a where
  - UnitType :: TypeRep ()
  - BoolType :: TypeRep Bool
  - IntType :: (BoundedInt (GenericInt s n), Size (GenericInt s n) ~ Range (GenericInt s n)) => Signedness s -> BitWidth n -> TypeRep (GenericInt s n)
  - FloatType :: TypeRep Float
  - ComplexType :: RealFloat a => TypeRep a -> TypeRep (Complex a)
  - ArrayType :: TypeRep a -> TypeRep [a]
  - TargetArrType :: BitWidth n -> TypeRep a -> TypeRep (TargetArr n a)
  - Tup2Type :: TypeRep a -> TypeRep b -> TypeRep (a, b)
  - Tup3Type :: TypeRep a -> TypeRep b -> TypeRep c -> TypeRep (a, b, c)
  - Tup4Type :: TypeRep a -> TypeRep b -> TypeRep c -> TypeRep d -> TypeRep (a, b, c, d)
  - Tup5Type :: TypeRep a -> TypeRep b -> TypeRep c -> TypeRep d -> TypeRep e -> TypeRep (a, b, c, d, e)
  - Tup6Type :: TypeRep a -> TypeRep b -> TypeRep c -> TypeRep d -> TypeRep e -> TypeRep f -> TypeRep (a, b, c, d, e, f)
  - Tup7Type :: TypeRep a -> TypeRep b -> TypeRep c -> TypeRep d -> TypeRep e -> TypeRep f -> TypeRep g -> TypeRep (a, b, c, d, e, f, g)
  - FunType :: TypeRep a -> TypeRep b -> TypeRep (a -> b)
  - MutType :: TypeRep a -> TypeRep (Mut a)
  - RefType :: TypeRep a -> TypeRep (IORef a)
  - MArrType :: TypeRep a -> TypeRep (MArr a)
  - ParType :: TypeRep a -> TypeRep (Par a)
  - IVarType :: TypeRep a -> TypeRep (IV a)
  - FValType :: TypeRep a -> TypeRep (FVal a)
- argType :: TypeRep (a -> b) -> TypeRep a
- resType :: TypeRep (a -> b) -> TypeRep b
- data TypeEq a b where
  - TypeEq :: TypeEq a a
- defaultSize :: TypeRep a -> Size a
- signEq :: Signedness s1 -> Signedness s2 -> Maybe (TypeEq s1 s2)
- widthEq :: BitWidth n1 -> BitWidth n2 -> Maybe (TypeEq n1 n2)
- typeEq :: TypeRep a -> TypeRep b -> Maybe (TypeEq a b)
- showTup :: [String] -> String
- type family TargetType n a
- class (Eq a, Show a, Typeable a, Show (Size a), Lattice (Size a)) => Type a where
  - typeRep :: TypeRep a
  - sizeOf :: a -> Size a
  - toTarget :: BitWidth n -> a -> TargetType n a
- typeRepByProxy :: Type a => Proxy a -> TypeRep a
- data AnySize = AnySize
- anySizeFun :: AnySize -> AnySize
- anySizeFun2 :: AnySize -> AnySize -> AnySize
- type family Size a
- data RangeSet a where
  - RangeSet :: BoundedInt a => Range a -> RangeSet a
  - Universal :: RangeSet a
- sizeToRange :: forall a. Type a => Size a -> RangeSet a
- tIntN :: Patch IntN IntN
- tWordN :: Patch WordN WordN
- tIndex :: Patch Index Index
- tLength :: Patch Length Length
- tArr :: Patch a a -> Patch [a] [a]

# Heterogenous lists

data a :> b

Heterogeneous list

Constructors

a :> b |

Instances

(Eq a, Eq b) => Eq (:> a b) |
(Ord a, Ord b) => Ord (:> a b) |
(Show a, Show b) => Show (:> a b) |
(Lattice a, Lattice b) => Lattice (:> a b) |

# Integers

newtype WordN

Target-dependent unsigned integers

Constructors

WordN Word32 |

Instances

Bounded WordN |
Enum WordN |
Eq WordN |
Integral WordN |
Num WordN |
Ord WordN |
Real WordN |
Show WordN |
Ix WordN |
Typeable WordN |
Arbitrary WordN |
Bits WordN |
Type WordN |
Numeric WordN |
Eq WordN |
Ord WordN |
Integral WordN |
Bits WordN |
Show (MArr a) |
Type a => Type (MArr a) |
Slice sl => Slice (:. sl (Data Length)) |
Shape sh => Shape (:. sh (Data Length)) |

newtype IntN

Target-dependent signed integers

Constructors

IntN Int32 |

Instances

Bounded IntN |
Enum IntN |
Eq IntN |
Integral IntN |
Num IntN |
Ord IntN |
Real IntN |
Show IntN |
Ix IntN |
Typeable IntN |
Arbitrary IntN |
Bits IntN |
Type IntN |
Numeric IntN |
Eq IntN |
Ord IntN |
Integral IntN |
Bits IntN |

data N8

Type representation of 8 bits

data N16

Type representation of 16 bits

data N32

Type representation of 32 bits

data N64

Type representation of 64 bits

data NNative

Type representation of the native number of bits on the target

data BitWidth n where

Witness for `N8`, `N16`, `N32`, `N64` or `NNative`

Constructors

N8 :: BitWidth N8 |
N16 :: BitWidth N16 |
N32 :: BitWidth N32 |
N64 :: BitWidth N64 |
NNative :: BitWidth NNative |

bitWidth :: BitWidth n -> String

data U

Type representation of "unsigned"

data S

Type representation of "signed"

data Signedness s where

Witness for `U` or `S`

Constructors

U :: Signedness U |
S :: Signedness S |

signedness :: Signedness s -> String

type family GenericInt s n

A generalization of unsigned and signed integers. The first parameter represents the signedness and the sectond parameter the number of bits.

type family WidthOf a

type family SignOf a

fromWordN :: BitWidth n -> WordN -> GenericInt U n

fromIntN :: BitWidth n -> IntN -> GenericInt S n

genericLen :: BitWidth n -> [a] -> GenericInt U n

type Length = WordN

type Index = WordN

# Arrays

data TargetArr n a

Array whose length is represented by an `n`-bit word

Constructors

TargetArr (GenericInt U n) [a] |

# Monadic Types

class MonadType m where

This class is used to allow constructs to be abstract in the monad

Methods

voidTypeRep :: TypeRep (m ())

Instances

MonadType Par |
MonadType Mut |

# Mutable data

type Mut = IO

Monad for manipulation of mutable data

type MArr a = IOArray Index a

Mutable arrays

# Par Monad

type Par = Par

Monad for parallel constructs

type IV = IVar

Immutable references

# Future values

newtype FVal a

Constructors

FVal |

Fields

unFVal :: a

Instances

Typeable1 FVal |
Eq a => Eq (FVal a) |
Show (FVal a) |
Type a => Type (FVal a) |

# Type representation

data TypeRep a where

Representation of supported types

Constructors

UnitType :: TypeRep () |
BoolType :: TypeRep Bool |
IntType :: (BoundedInt (GenericInt s n), Size (GenericInt s n) ~ Range (GenericInt s n)) => Signedness s -> BitWidth n -> TypeRep (GenericInt s n) |
FloatType :: TypeRep Float |
ComplexType :: RealFloat a => TypeRep a -> TypeRep (Complex a) |
ArrayType :: TypeRep a -> TypeRep [a] |
TargetArrType :: BitWidth n -> TypeRep a -> TypeRep (TargetArr n a) |
Tup2Type :: TypeRep a -> TypeRep b -> TypeRep (a, b) |
Tup3Type :: TypeRep a -> TypeRep b -> TypeRep c -> TypeRep (a, b, c) |
Tup4Type :: TypeRep a -> TypeRep b -> TypeRep c -> TypeRep d -> TypeRep (a, b, c, d) |
Tup5Type :: TypeRep a -> TypeRep b -> TypeRep c -> TypeRep d -> TypeRep e -> TypeRep (a, b, c, d, e) |
Tup6Type :: TypeRep a -> TypeRep b -> TypeRep c -> TypeRep d -> TypeRep e -> TypeRep f -> TypeRep (a, b, c, d, e, f) |
Tup7Type :: TypeRep a -> TypeRep b -> TypeRep c -> TypeRep d -> TypeRep e -> TypeRep f -> TypeRep g -> TypeRep (a, b, c, d, e, f, g) |
FunType :: TypeRep a -> TypeRep b -> TypeRep (a -> b) |
MutType :: TypeRep a -> TypeRep (Mut a) |
RefType :: TypeRep a -> TypeRep (IORef a) |
MArrType :: TypeRep a -> TypeRep (MArr a) |
ParType :: TypeRep a -> TypeRep (Par a) |
IVarType :: TypeRep a -> TypeRep (IV a) |
FValType :: TypeRep a -> TypeRep (FVal a) |

Instances

Show (TypeRep a) |

argType :: TypeRep (a -> b) -> TypeRep a

resType :: TypeRep (a -> b) -> TypeRep b

data TypeEq a b where

Type equality witness

Constructors

TypeEq :: TypeEq a a |

defaultSize :: TypeRep a -> Size a

signEq :: Signedness s1 -> Signedness s2 -> Maybe (TypeEq s1 s2)

Type equality on `Signedness`

widthEq :: BitWidth n1 -> BitWidth n2 -> Maybe (TypeEq n1 n2)

Type equality on `BitWidth`

typeEq :: TypeRep a -> TypeRep b -> Maybe (TypeEq a b)

Type equality on `TypeRep`

showTup :: [String] -> String

type family TargetType n a

class (Eq a, Show a, Typeable a, Show (Size a), Lattice (Size a)) => Type a where

The set of supported types

Methods

typeRep :: TypeRep a

Gives the type representation a value.

sizeOf :: a -> Size a

toTarget :: BitWidth n -> a -> TargetType n a

Instances

Type Bool |
Type Float |
Type Int8 |
Type Int16 |
Type Int32 |
Type Int64 |
Type Word8 |
Type Word16 |
Type Word32 |
Type Word64 |
Type () |
Type IntN |
Type WordN |
Type a => Type [a] |
(Type a, RealFloat a) => Type (Complex a) |
(Type a, Show (IORef a)) => Type (IORef a) |
Type a => Type (FVal a) |
Type a => Type (IV a) |
Type a => Type (MArr a) |
(Type a, Type b) => Type (a, b) |
(Type a, Type b, Type c) => Type (a, b, c) |
(Type a, Type b, Type c, Type d) => Type (a, b, c, d) |
(Type a, Type b, Type c, Type d, Type e) => Type (a, b, c, d, e) |
(Type a, Type b, Type c, Type d, Type e, Type f) => Type (a, b, c, d, e, f) |
(Type a, Type b, Type c, Type d, Type e, Type f, Type g) => Type (a, b, c, d, e, f, g) |

typeRepByProxy :: Type a => Proxy a -> TypeRep a

# Sized types

data AnySize

Constructors

AnySize |

Instances

Eq AnySize |
Num AnySize |
Ord AnySize |
Show AnySize |
Lattice AnySize |

anySizeFun :: AnySize -> AnySize

anySizeFun2 :: AnySize -> AnySize -> AnySize

type family Size a

data RangeSet a where

A generalization of `Range` that serves two purposes: (1) Adding an extra `Universal` constructor to support unbounded types (`Range` can only represent bounded ranges), and (2) pack a `BoundedInt` constraint with the `RangeSet` constructor. This is what allows `sizeToRange` to be defined as a total function with `Type` as the only constraint.

Constructors

RangeSet :: BoundedInt a => Range a -> RangeSet a |
Universal :: RangeSet a |

sizeToRange :: forall a. Type a => Size a -> RangeSet a

Cast a `Size` to a `RangeSet`

tIntN :: Patch IntN IntN

tWordN :: Patch WordN WordN

tIndex :: Patch Index Index

tLength :: Patch Length Length

tArr :: Patch a a -> Patch [a] [a]