futhark-0.19.4: An optimising compiler for a functional, array-oriented language.
Safe HaskellSafe-Inferred
LanguageHaskell2010

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

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

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 #

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

Like div, but rounds towards positive infinity.

Instances

Instances details
Integral a => IntegralExp (Wrapped a) Source # 
Instance details

Defined in Futhark.Util.IntegralExp

(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 #

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

IntegralExp e => IntegralExp (Count u e) Source # 
Instance details

Defined in Futhark.IR.Kernels.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 #

divUp :: 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

Instances

Instances details
Eq a => Eq (Wrapped a) Source # 
Instance details

Defined in Futhark.Util.IntegralExp

Methods

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

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

Num a => Num (Wrapped a) Source # 
Instance details

Defined in Futhark.Util.IntegralExp

Methods

(+) :: Wrapped a -> Wrapped a -> Wrapped a #

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

(*) :: Wrapped a -> Wrapped a -> Wrapped a #

negate :: Wrapped a -> Wrapped a #

abs :: Wrapped a -> Wrapped a #

signum :: Wrapped a -> Wrapped a #

fromInteger :: Integer -> Wrapped a #

Ord a => Ord (Wrapped a) Source # 
Instance details

Defined in Futhark.Util.IntegralExp

Methods

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

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

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

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

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

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

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

Show a => Show (Wrapped a) Source # 
Instance details

Defined in Futhark.Util.IntegralExp

Methods

showsPrec :: Int -> Wrapped a -> ShowS #

show :: Wrapped a -> String #

showList :: [Wrapped a] -> ShowS #

Integral a => IntegralExp (Wrapped a) Source # 
Instance details

Defined in Futhark.Util.IntegralExp