Notes on Types in Accelerate - ku-fpg/mandelbrot-examples GitHub Wiki

Type of abs

In general, the type of a worker/wrapper style abs would be something like

abs :: a -> Exp a

Here, because of the way Accelerate uses an associated type family in its Lift class, we need the slightly more specialized type

abs :: (Lift Exp a, a ~ Plain a) => a -> Exp a

The Lift constraint is required since only certain types can be lifted into Accelerate (which makes conceptual sense because GPUs are not designed to directly manipulate arbitrary Haskell data types).

In the second constraint, Plain is the type family associated with the Lift class. What it does is eliminate all Exps from the given type. The example given here in the Accelerate documentation is that equalities such as this hold:

Plain (Exp Int, Int) ~ (Int,Int) ~ Plain (Int, Exp Int)

Since we should only ever be applying abs to values with types that have no Exps in them, it should be okay to require a ~ Plain a.