Safe Haskell | None |
---|---|
Language | Haskell2010 |
Synopsis
- share :: (Syntax a, Syntax b) => a -> (a -> b) -> b
- shareTag :: (Syntax a, Syntax b) => String -> a -> (a -> b) -> b
- forLoop :: Syntax st => Data Length -> st -> (Data Index -> st -> st) -> st
- cond :: Syntax a => Data Bool -> a -> a -> a
- (?) :: Syntax a => Data Bool -> a -> a -> a
- switch :: (Syntax a, Syntax b, PrimType (Internal a)) => b -> [(a, b)] -> a -> b
- value :: Syntax a => Internal a -> a
- false :: Data Bool
- true :: Data Bool
- example :: Syntax a => a
- π :: (Floating a, PrimType a) => Data a
- quot :: (Integral a, PrimType a) => Data a -> Data a -> Data a
- rem :: (Integral a, PrimType a) => Data a -> Data a -> Data a
- quotRem :: (Integral a, PrimType a) => Data a -> Data a -> (Data a, Data a)
- div :: (Integral a, PrimType a) => Data a -> Data a -> Data a
- mod :: (Integral a, PrimType a) => Data a -> Data a -> Data a
- unsafeBalancedDiv :: (Integral a, PrimType a) => Data a -> Data a -> Data a
- complex :: (Num a, PrimType a, PrimType (Complex a)) => Data a -> Data a -> Data (Complex a)
- polar :: (Floating a, PrimType a, PrimType (Complex a)) => Data a -> Data a -> Data (Complex a)
- realPart :: (PrimType a, PrimType (Complex a)) => Data (Complex a) -> Data a
- imagPart :: (PrimType a, PrimType (Complex a)) => Data (Complex a) -> Data a
- magnitude :: (RealFloat a, PrimType a, PrimType (Complex a)) => Data (Complex a) -> Data a
- phase :: (RealFloat a, PrimType a, PrimType (Complex a)) => Data (Complex a) -> Data a
- conjugate :: (RealFloat a, PrimType (Complex a)) => Data (Complex a) -> Data (Complex a)
- i2n :: (Integral i, Num n, PrimType i, PrimType n) => Data i -> Data n
- i2b :: (Integral a, PrimType a) => Data a -> Data Bool
- b2i :: (Integral a, PrimType a) => Data Bool -> Data a
- round :: (RealFrac a, Num b, PrimType a, PrimType b) => Data a -> Data b
- not :: Data Bool -> Data Bool
- (&&) :: Data Bool -> Data Bool -> Data Bool
- (||) :: Data Bool -> Data Bool -> Data Bool
- (==) :: PrimType a => Data a -> Data a -> Data Bool
- (/=) :: PrimType a => Data a -> Data a -> Data Bool
- (<) :: (Ord a, PrimType a) => Data a -> Data a -> Data Bool
- (>) :: (Ord a, PrimType a) => Data a -> Data a -> Data Bool
- (<=) :: (Ord a, PrimType a) => Data a -> Data a -> Data Bool
- (>=) :: (Ord a, PrimType a) => Data a -> Data a -> Data Bool
- min :: (Ord a, PrimType a) => Data a -> Data a -> Data a
- max :: (Ord a, PrimType a) => Data a -> Data a -> Data a
- (.&.) :: (Bits a, PrimType a) => Data a -> Data a -> Data a
- (.|.) :: (Bits a, PrimType a) => Data a -> Data a -> Data a
- xor :: (Bits a, PrimType a) => Data a -> Data a -> Data a
- (⊕) :: (Bits a, PrimType a) => Data a -> Data a -> Data a
- complement :: (Bits a, PrimType a) => Data a -> Data a
- shiftL :: (Bits a, PrimType a) => Data a -> Data Int32 -> Data a
- shiftR :: (Bits a, PrimType a) => Data a -> Data Int32 -> Data a
- (.<<.) :: (Bits a, PrimType a) => Data a -> Data Int32 -> Data a
- (.>>.) :: (Bits a, PrimType a) => Data a -> Data Int32 -> Data a
- bitSize :: forall a. FiniteBits a => Data a -> Length
- allOnes :: (Bits a, Num a, PrimType a) => Data a
- oneBits :: (Bits a, Num a, PrimType a) => Data Int32 -> Data a
- lsbs :: (Bits a, Num a, PrimType a) => Data Int32 -> Data a -> Data a
- ilog2 :: (FiniteBits a, Integral a, PrimType a) => Data a -> Data a
- arrIx :: Syntax a => IArr a -> Data Index -> a
- class Indexed a where
- type IndexedElem a
- (!) :: a -> Data Index -> IndexedElem a
- class Finite a where
- class Slicable a where
- desugar :: Syntax a => a -> Data (Internal a)
- sugar :: Syntax a => Data (Internal a) -> a
- resugar :: (Syntax a, Syntax b, Internal a ~ Internal b) => a -> b
- guardVal :: Syntax a => Data Bool -> String -> a -> a
- guardValLabel :: Syntax a => AssertionLabel -> Data Bool -> String -> a -> a
- unsafePerform :: Syntax a => Comp a -> a
- class Monad m => MonadComp m where
- newRef :: (Syntax a, MonadComp m) => m (Ref a)
- newNamedRef :: (Syntax a, MonadComp m) => String -> m (Ref a)
- initRef :: (Syntax a, MonadComp m) => a -> m (Ref a)
- initNamedRef :: (Syntax a, MonadComp m) => String -> a -> m (Ref a)
- getRef :: (Syntax a, MonadComp m) => Ref a -> m a
- setRef :: (Syntax a, MonadComp m) => Ref a -> a -> m ()
- modifyRef :: (Syntax a, MonadComp m) => Ref a -> (a -> a) -> m ()
- unsafeFreezeRef :: (Syntax a, MonadComp m) => Ref a -> m a
- newArr :: (Type (Internal a), MonadComp m) => Data Length -> m (Arr a)
- newNamedArr :: (Type (Internal a), MonadComp m) => String -> Data Length -> m (Arr a)
- constArr :: (PrimType (Internal a), MonadComp m) => [Internal a] -> m (Arr a)
- constNamedArr :: (PrimType (Internal a), MonadComp m) => String -> [Internal a] -> m (Arr a)
- getArr :: (Syntax a, MonadComp m) => Arr a -> Data Index -> m a
- setArr :: forall m a. (Syntax a, MonadComp m) => Arr a -> Data Index -> a -> m ()
- copyArr :: MonadComp m => Arr a -> Arr a -> m ()
- freezeArr :: (Type (Internal a), MonadComp m) => Arr a -> m (IArr a)
- freezeSlice :: (Type (Internal a), MonadComp m) => Data Length -> Arr a -> m (IArr a)
- unsafeFreezeArr :: MonadComp m => Arr a -> m (IArr a)
- unsafeFreezeSlice :: MonadComp m => Data Length -> Arr a -> m (IArr a)
- thawArr :: (Type (Internal a), MonadComp m) => IArr a -> m (Arr a)
- unsafeThawArr :: MonadComp m => IArr a -> m (Arr a)
- constIArr :: (PrimType (Internal a), MonadComp m) => [Internal a] -> m (IArr a)
- ifE :: (Syntax a, MonadComp m) => Data Bool -> m a -> m a -> m a
- break :: MonadComp m => m ()
- assert :: MonadComp m => Data Bool -> String -> m ()
- assertLabel :: MonadComp m => AssertionLabel -> Data Bool -> String -> m ()
- shareM :: (Syntax a, MonadComp m) => a -> m a
Pure expressions
General constructs
Force evaluation of a value and share the result. Note that due to common sub-expression elimination, this function is rarely needed in practice.
:: (Syntax a, Syntax b) | |
=> String | A tag (that may be empty). May be used by a back end to generate a sensible variable name. |
-> a | Value to share |
-> (a -> b) | Body in which to share the value |
-> b |
Explicit tagged sharing
Conditional expression
:: (Syntax a, Syntax b, PrimType (Internal a)) | |
=> b | Default result |
-> [(a, b)] | Cases (match, result) |
-> a | Scrutinee |
-> b | Result |
Multi-way conditional expression
The first association (a,b)
in the list of cases for which a
is equal to
the scrutinee is selected, and the associated b
is returned as the result.
If no case matches, the default value is returned.
Literals
Primitive functions
quot :: (Integral a, PrimType a) => Data a -> Data a -> Data a Source #
Integer division truncated toward zero
rem :: (Integral a, PrimType a) => Data a -> Data a -> Data a Source #
Integer remainder satisfying
(x `quot` y)*y + (x `rem` y) == x
quotRem :: (Integral a, PrimType a) => Data a -> Data a -> (Data a, Data a) Source #
Simultaneous quot
and rem
div :: (Integral a, PrimType a) => Data a -> Data a -> Data a Source #
Integer division truncated toward negative infinity
mod :: (Integral a, PrimType a) => Data a -> Data a -> Data a Source #
Integer modulus, satisfying
(x `div` y)*y + (x `mod` y) == x
unsafeBalancedDiv :: (Integral a, PrimType a) => Data a -> Data a -> Data a Source #
Integer division assuming `unsafeBalancedDiv x y * y == x` (i.e. no remainder)
The advantage of using unsafeBalancedDiv
over quot
or div
is that the
above assumption can be used for simplifying the expression.
:: (Num a, PrimType a, PrimType (Complex a)) | |
=> Data a | Real part |
-> Data a | Imaginary part |
-> Data (Complex a) |
Construct a complex number
:: (Floating a, PrimType a, PrimType (Complex a)) | |
=> Data a | Magnitude |
-> Data a | Phase |
-> Data (Complex a) |
Construct a complex number
realPart :: (PrimType a, PrimType (Complex a)) => Data (Complex a) -> Data a Source #
Extract the real part of a complex number
imagPart :: (PrimType a, PrimType (Complex a)) => Data (Complex a) -> Data a Source #
Extract the imaginary part of a complex number
magnitude :: (RealFloat a, PrimType a, PrimType (Complex a)) => Data (Complex a) -> Data a Source #
Extract the magnitude of a complex number's polar form
phase :: (RealFloat a, PrimType a, PrimType (Complex a)) => Data (Complex a) -> Data a Source #
Extract the phase of a complex number's polar form
conjugate :: (RealFloat a, PrimType (Complex a)) => Data (Complex a) -> Data (Complex a) Source #
Complex conjugate
i2n :: (Integral i, Num n, PrimType i, PrimType n) => Data i -> Data n Source #
Integral type casting
round :: (RealFrac a, Num b, PrimType a, PrimType b) => Data a -> Data b Source #
Round a floating-point number to an integer
Bit manipulation
:: (Bits a, PrimType a) | |
=> Data a | Value to shift |
-> Data Int32 | Shift amount (negative value gives right shift) |
-> Data a |
Left shift
:: (Bits a, PrimType a) | |
=> Data a | Value to shift |
-> Data Int32 | Shift amount (negative value gives left shift) |
-> Data a |
Right shift
:: (Bits a, PrimType a) | |
=> Data a | Value to shift |
-> Data Int32 | Shift amount (negative value gives right shift) |
-> Data a |
Left shift
:: (Bits a, PrimType a) | |
=> Data a | Value to shift |
-> Data Int32 | Shift amount (negative value gives left shift) |
-> Data a |
Right shift
lsbs :: (Bits a, Num a, PrimType a) => Data Int32 -> Data a -> Data a Source #
Extract the k
lowest bits
ilog2 :: (FiniteBits a, Integral a, PrimType a) => Data a -> Data a Source #
Integer logarithm in base 2. Returns \(\lfloor log_2(x) \rfloor\). Assumes \(x>0\).
Arrays
class Indexed a where Source #
type IndexedElem a Source #
Instances
Syntax a => Indexed (IArr a) Source # | |
Defined in Feldspar.Frontend type IndexedElem (IArr a) Source # | |
Slicable a => Indexed (Nest a) Source # | |
Defined in Feldspar.Data.Array type IndexedElem (Nest a) Source # | |
Indexed (Pull2 a) Source # | Indexing the rows |
Defined in Feldspar.Data.Vector type IndexedElem (Pull2 a) Source # | |
Indexed (Pull a) Source # | |
Defined in Feldspar.Data.Vector type IndexedElem (Pull a) Source # |
Linear structures with a length. If the type is also Indexed
, the length
is the successor of the maximal allowed index.
class Slicable a where Source #
Linear structures that can be sliced
Take a slice of a structure
Syntactic conversion
resugar :: (Syntax a, Syntax b, Internal a ~ Internal b) => a -> b Source #
Cast between two values that have the same syntactic representation
Assertions
:: Syntax a | |
=> Data Bool | Condition that is expected to be true |
-> String | Error message |
-> a | Value to attach the assertion to |
-> a |
Guard a value by an assertion (with implicit label
)UserAssertion
""
:: Syntax a | |
=> AssertionLabel | Assertion label |
-> Data Bool | Condition that is expected to be true |
-> String | Error message |
-> a | Value to attach the assertion to |
-> a |
Like guardVal
but with an explicit assertion label
Unsafe operations
unsafePerform :: Syntax a => Comp a -> a Source #
Turn a Comp
computation into a pure value. For this to be safe, the
computation should be free of side effects and independent of its
environment.
Programs with computational effects
class Monad m => MonadComp m where Source #
Monads that support computational effects: mutable data structures and control flow
liftComp :: Comp a -> m a Source #
Lift a Comp
computation
iff :: Data Bool -> m () -> m () -> m () Source #
Conditional statement
for :: (Integral n, PrimType n) => IxRange (Data n) -> (Data n -> m ()) -> m () Source #
For loop
while :: m (Data Bool) -> m () -> m () Source #
While loop
References
Create an uninitialized named reference
The provided base name may be appended with a unique identifier to avoid name collisions.
Create an initialized reference
The provided base name may be appended with a unique identifier to avoid name collisions.
modifyRef :: (Syntax a, MonadComp m) => Ref a -> (a -> a) -> m () Source #
Modify the contents of reference.
unsafeFreezeRef :: (Syntax a, MonadComp m) => Ref a -> m a Source #
Freeze the contents of reference (only safe if the reference is not updated as long as the resulting value is alive).
Arrays
newArr :: (Type (Internal a), MonadComp m) => Data Length -> m (Arr a) Source #
Create an uninitialized array
Create an uninitialized named array
The provided base name may be appended with a unique identifier to avoid name collisions.
Create an array and initialize it with a constant list
:: (PrimType (Internal a), MonadComp m) | |
=> String | Base name |
-> [Internal a] | Initial contents |
-> m (Arr a) |
Create a named array and initialize it with a constant list
The provided base name may be appended with a unique identifier to avoid name collisions.
setArr :: forall m a. (Syntax a, MonadComp m) => Arr a -> Data Index -> a -> m () Source #
Set an element of an array
freezeArr :: (Type (Internal a), MonadComp m) => Arr a -> m (IArr a) Source #
Freeze a mutable array to an immutable one. This involves copying the array to a newly allocated one.
freezeSlice :: (Type (Internal a), MonadComp m) => Data Length -> Arr a -> m (IArr a) Source #
A version of freezeArr
that slices the array from 0 to the given length
unsafeFreezeArr :: MonadComp m => Arr a -> m (IArr a) Source #
Freeze a mutable array to an immutable one without making a copy. This is generally only safe if the the mutable array is not updated as long as the immutable array is alive.
unsafeFreezeSlice :: MonadComp m => Data Length -> Arr a -> m (IArr a) Source #
A version of unsafeFreezeArr
that slices the array from 0 to the given
length
thawArr :: (Type (Internal a), MonadComp m) => IArr a -> m (Arr a) Source #
Thaw an immutable array to a mutable one. This involves copying the array to a newly allocated one.
unsafeThawArr :: MonadComp m => IArr a -> m (Arr a) Source #
Thaw an immutable array to a mutable one without making a copy. This is generally only safe if the the mutable array is not updated as long as the immutable array is alive.
constIArr :: (PrimType (Internal a), MonadComp m) => [Internal a] -> m (IArr a) Source #
Create an immutable array and initialize it with a constant list
Control-flow
Conditional statement that returns an expression
Assertion (with implicit label
)UserAssertion
""
:: MonadComp m | |
=> AssertionLabel | Assertion label |
-> Data Bool | Expression that should be true |
-> String | Message in case of failure |
-> m () |
Like assert
but tagged with an explicit assertion label
Misc.
shareM :: (Syntax a, MonadComp m) => a -> m a Source #
Force evaluation of a value and share the result (monadic version of
share
)
Orphan instances
Syntactic () Source # | |
(Bounded a, Type a) => Bounded (Data a) Source # | |
(Floating a, PrimType a) => Floating (Data a) Source # | |
(Fractional a, PrimType a) => Fractional (Data a) Source # | |
(Num a, PrimType a) => Num (Data a) Source # | |