Copyright | [2009..2018] Manuel M T Chakravarty Gabriele Keller Trevor L. McDonell |
---|---|

License | BSD3 |

Maintainer | Trevor L. McDonell <tmcdonell@cse.unsw.edu.au> |

Stability | experimental |

Portability | non-portable (GHC extensions) |

Safe Haskell | None |

Language | Haskell2010 |

Operations which may be unsafe. Use with care.

*Since: 1.2.0.0*

## Unsafe operations

undef :: Elt t => Exp t Source #

`undef`

can be used anywhere a constant is expected, and indicates that the
consumer of the value can receive an unspecified bit pattern.

This is useful because a store of an undefined value can be assumed to not
have any effect; we can assume that the value is overwritten with bits that
happen to match what was already there. However, a store *to* an undefined
location could clobber arbitrary memory, therefore, its use in such a context
would introduce undefined *behaviour*.

There are (at least) two cases where you may want to use this:

- The
`permute`

function requires an array of default values, into which the new values are combined. However, if you are sure the default values are not used, and will (eventually) be completely overwritten, then`fill`

ing an array with this value will give you a new uninitialised array. - In the definition of sum data types. See for example Data.Array.Accelerate.Data.Maybe and Data.Array.Accelerate.Data.Either.

*Since: 1.2.0.0*

coerce :: (Elt a, Elt b) => Exp a -> Exp b Source #

The function `coerce`

allows you to convert a value between any two types
whose underlying representations have the same bit size at each component.

For example:

coerce (x :: Exp Double) :: Exp Word64 coerce (x :: Exp (Int64,Float)) :: Exp (Complex Float, Word32)

Furthermore, as we typically declare newtype wrappers similarly to:

type instance EltRepr (Sum a) = ((), EltRepr a)

This can be used instead of the newtype constructor, to go from the newtype's
abstract type to the concrete type by dropping the extra `()`

from the
representation, and vice-versa.

You will get a runtime error if it fails to find a coercion between the two representations.

*Since: 1.2.0.0*