futhark-0.25.32: An optimising compiler for a functional, array-oriented language.

Safe Haskell | Safe-Inferred
Language | GHC2021

Futhark.Util.IntegralExp

Description

It is occasionally useful to define generic functions that can not only compute their result as an integer, but also as a symbolic expression in the form of an AST.

There are some Haskell hacks for this - it is for example not hard to define an instance of `Num` that constructs an AST. However, this falls down for some other interesting classes, like `Integral`, which requires both the problematic method `fromInteger`, and also that the type is an instance of `Enum`.

We can always just define hobbled instances that call `error` for those methods that are impractical, but this is ugly.

Hence, this module defines similes to standard Haskell numeric typeclasses that have been modified to make generic functions slightly easier to write.

Synopsis

- class Num e => IntegralExp e where
  - quot :: e -> e -> e
  - rem :: e -> e -> e
  - div :: e -> e -> e
  - mod :: e -> e -> e
  - sgn :: e -> Maybe Int
  - pow :: e -> e -> e
  - divUp :: e -> e -> e
  - nextMul :: e -> e -> e
- newtype Wrapped a = Wrapped {
  - wrappedValue :: a
  }

# Documentation

class Num e => IntegralExp e where Source #

A twist on the `Integral` type class that is more friendly to symbolic representations.

Minimal complete definition

quot, rem, div, mod, sgn, pow

Methods

quot :: e -> e -> e Source #

rem :: e -> e -> e Source #

div :: e -> e -> e Source #

mod :: e -> e -> e Source #

sgn :: e -> Maybe Int Source #

pow :: e -> e -> e Source #

divUp :: e -> e -> e Source #

Like `div`, but rounds towards positive infinity.

nextMul :: e -> e -> e Source #

#### Instances

Instances details

Integral a => IntegralExp (Wrapped a) Source # |

Instance details

Defined in Futhark.Util.IntegralExp

Methods

quot :: Wrapped a -> Wrapped a -> Wrapped a Source #

rem :: Wrapped a -> Wrapped a -> Wrapped a Source #

div :: Wrapped a -> Wrapped a -> Wrapped a Source #

mod :: Wrapped a -> Wrapped a -> Wrapped a Source #

sgn :: Wrapped a -> Maybe Int Source #

pow :: Wrapped a -> Wrapped a -> Wrapped a Source #

divUp :: Wrapped a -> Wrapped a -> Wrapped a Source #

nextMul :: Wrapped a -> Wrapped a -> Wrapped a Source #

(IntExp t, Pretty v) => IntegralExp (TPrimExp t v) Source # |

Instance details

Defined in Futhark.Analysis.PrimExp

Methods

quot :: TPrimExp t v -> TPrimExp t v -> TPrimExp t v Source #

rem :: TPrimExp t v -> TPrimExp t v -> TPrimExp t v Source #

div :: TPrimExp t v -> TPrimExp t v -> TPrimExp t v Source #

mod :: TPrimExp t v -> TPrimExp t v -> TPrimExp t v Source #

sgn :: TPrimExp t v -> Maybe Int Source #

pow :: TPrimExp t v -> TPrimExp t v -> TPrimExp t v Source #

divUp :: TPrimExp t v -> TPrimExp t v -> TPrimExp t v Source #

nextMul :: TPrimExp t v -> TPrimExp t v -> TPrimExp t v Source #

IntegralExp e => IntegralExp (Count u e) Source # |

Instance details

Defined in Futhark.IR.GPU.Sizes

Methods

quot :: Count u e -> Count u e -> Count u e Source #

rem :: Count u e -> Count u e -> Count u e Source #

div :: Count u e -> Count u e -> Count u e Source #

mod :: Count u e -> Count u e -> Count u e Source #

sgn :: Count u e -> Maybe Int Source #

pow :: Count u e -> Count u e -> Count u e Source #

divUp :: Count u e -> Count u e -> Count u e Source #

nextMul :: Count u e -> Count u e -> Count u e Source #

newtype Wrapped a Source #

This wrapper allows you to use a type that is an instance of the true class whenever the simile class is required.

Constructors

Wrapped |

Fields

- wrappedValue :: a

#### Instances

Instances details

Enum a => Enum (Wrapped a) Source # |

Instance details

Defined in Futhark.Util.IntegralExp

Methods

succ :: Wrapped a -> Wrapped a Source #

pred :: Wrapped a -> Wrapped a Source #

toEnum :: Int -> Wrapped a Source #

fromEnum :: Wrapped a -> Int Source #

enumFrom :: Wrapped a -> [Wrapped a] Source #

enumFromThen :: Wrapped a -> Wrapped a -> [Wrapped a] Source #

enumFromTo :: Wrapped a -> Wrapped a -> [Wrapped a] Source #

enumFromThenTo :: Wrapped a -> Wrapped a -> Wrapped a -> [Wrapped a] Source #

Num a => Num (Wrapped a) Source # |
Instance details Defined in Futhark.Util.IntegralExp Methods (+) :: Wrapped a -> Wrapped a -> Wrapped a Source # (-) :: Wrapped a -> Wrapped a -> Wrapped a Source # (*) :: Wrapped a -> Wrapped a -> Wrapped a Source # negate :: Wrapped a -> Wrapped a Source # abs :: Wrapped a -> Wrapped a Source # signum :: Wrapped a -> Wrapped a Source # fromInteger :: Integer -> Wrapped a Source #
Show a => Show (Wrapped a) Source # |
Instance details Defined in Futhark.Util.IntegralExp Methods showsPrec :: Int -> Wrapped a -> ShowS Source # show :: Wrapped a -> String Source # showList :: [Wrapped a] -> ShowS Source #
Integral a => IntegralExp (Wrapped a) Source # |

Instance details

Defined in Futhark.Util.IntegralExp

Methods

quot :: Wrapped a -> Wrapped a -> Wrapped a Source #

rem :: Wrapped a -> Wrapped a -> Wrapped a Source #

div :: Wrapped a -> Wrapped a -> Wrapped a Source #

mod :: Wrapped a -> Wrapped a -> Wrapped a Source #

sgn :: Wrapped a -> Maybe Int Source #

pow :: Wrapped a -> Wrapped a -> Wrapped a Source #

divUp :: Wrapped a -> Wrapped a -> Wrapped a Source #

nextMul :: Wrapped a -> Wrapped a -> Wrapped a Source #

Eq a => Eq (Wrapped a) Source # |
Instance details Defined in Futhark.Util.IntegralExp Methods (==) :: Wrapped a -> Wrapped a -> Bool Source # (/=) :: Wrapped a -> Wrapped a -> Bool Source #
Ord a => Ord (Wrapped a) Source # |

Instance details

Defined in Futhark.Util.IntegralExp

Methods

compare :: Wrapped a -> Wrapped a -> Ordering Source #

(<) :: Wrapped a -> Wrapped a -> Bool Source #

(<=) :: Wrapped a -> Wrapped a -> Bool Source #

(>) :: Wrapped a -> Wrapped a -> Bool Source #

(>=) :: Wrapped a -> Wrapped a -> Bool Source #

max :: Wrapped a -> Wrapped a -> Wrapped a Source #

min :: Wrapped a -> Wrapped a -> Wrapped a Source #