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

Safe Haskell | Safe-Inferred
Language | GHC2021

Language.Futhark.Interpreter.Values

Contents

- Shapes
- Values
- Conversion

Description

The value representation used in the interpreter.

Kept simple and free of unnecessary operational details (in particular, no references to the interpreter monad).

Synopsis

- data Shape d
  - = ShapeDim d (Shape d)
  - | ShapeLeaf
  - | ShapeRecord (Map Name (Shape d))
  - | ShapeSum (Map Name [Shape d])
- type ValueShape = Shape Int64
- typeShape :: TypeBase d u -> Shape d
- structTypeShape :: StructType -> Shape (Maybe Int64)
- data Value m
  - = ValuePrim !PrimValue
  - | ValueArray ValueShape !(Array Int (Value m))
  - | ValueRecord (Map Name (Value m))
  - | ValueFun (Value m -> m (Value m))
  - | ValueSum ValueShape Name [Value m]
  - | ValueAcc ValueShape (Value m -> Value m -> m (Value m)) !(Array Int (Value m))
  - | ValueAD Depth ADVariable
- valueShape :: Value m -> ValueShape
- arrayValueShape :: Value m -> ValueShape
- prettyValue :: Value m -> Doc a
- valueText :: Value m -> Text
- valueAccum :: (a -> Value m -> (a, Value m)) -> a -> Value m -> (a, Value m)
- valueAccumLM :: Monad f => (a -> Value m -> f (a, Value m)) -> a -> Value m -> f (a, Value m)
- fromTuple :: Value m -> Maybe [Value m]
- arrayLength :: Integral int => Array Int (Value m) -> int
- isEmptyArray :: Value m -> Bool
- prettyEmptyArray :: TypeBase () () -> Value m -> Text
- toArray :: ValueShape -> [Value m] -> Value m
- toArray' :: ValueShape -> [Value m] -> Value m
- toTuple :: [Value m] -> Value m
- fromDataValue :: Value -> Value m

# Shapes

data Shape d Source #

A shape is a tree to accomodate the case of records. It is parameterised over the representation of dimensions.

Constructors

ShapeDim d (Shape d) |
ShapeLeaf |
ShapeRecord (Map Name (Shape d)) |
ShapeSum (Map Name [Shape d]) |

#### Instances

Instances details

Foldable Shape Source # |

Instance details

Defined in Language.Futhark.Interpreter.Values

Methods

fold :: Monoid m => Shape m -> m Source #

foldMap :: Monoid m => (a -> m) -> Shape a -> m Source #

foldMap' :: Monoid m => (a -> m) -> Shape a -> m Source #

foldr :: (a -> b -> b) -> b -> Shape a -> b Source #

foldr' :: (a -> b -> b) -> b -> Shape a -> b Source #

foldl :: (b -> a -> b) -> b -> Shape a -> b Source #

foldl' :: (b -> a -> b) -> b -> Shape a -> b Source #

foldr1 :: (a -> a -> a) -> Shape a -> a Source #

foldl1 :: (a -> a -> a) -> Shape a -> a Source #

toList :: Shape a -> [a] Source #

null :: Shape a -> Bool Source #

length :: Shape a -> Int Source #

elem :: Eq a => a -> Shape a -> Bool Source #

maximum :: Ord a => Shape a -> a Source #

minimum :: Ord a => Shape a -> a Source #

sum :: Num a => Shape a -> a Source #

product :: Num a => Shape a -> a Source #

Traversable Shape Source # |
Instance details Defined in Language.Futhark.Interpreter.Values Methods traverse :: Applicative f => (a -> f b) -> Shape a -> f (Shape b) Source # sequenceA :: Applicative f => Shape (f a) -> f (Shape a) Source # mapM :: Monad m => (a -> m b) -> Shape a -> m (Shape b) Source # sequence :: Monad m => Shape (m a) -> m (Shape a) Source #
Functor Shape Source # |
Instance details Defined in Language.Futhark.Interpreter.Values Methods fmap :: (a -> b) -> Shape a -> Shape b Source # (<$) :: a -> Shape b -> Shape a Source #
Show d => Show (Shape d) Source # |
Instance details Defined in Language.Futhark.Interpreter.Values Methods showsPrec :: Int -> Shape d -> ShowS Source # show :: Shape d -> String Source # showList :: [Shape d] -> ShowS Source #
Eq d => Eq (Shape d) Source # |
Instance details Defined in Language.Futhark.Interpreter.Values Methods (==) :: Shape d -> Shape d -> Bool Source # (/=) :: Shape d -> Shape d -> Bool Source #
Pretty d => Pretty (Shape d) Source # |
Instance details Defined in Language.Futhark.Interpreter.Values Methods pretty :: Shape d -> Doc ann Source # prettyList :: [Shape d] -> Doc ann Source #

type ValueShape = Shape Int64 Source #

The shape of an array.

typeShape :: TypeBase d u -> Shape d Source #

structTypeShape :: StructType -> Shape (Maybe Int64) Source #

# Values

data Value m Source #

A fully evaluated Futhark value.

Constructors

ValuePrim !PrimValue |
ValueArray ValueShape !(Array Int (Value m)) |
ValueRecord (Map Name (Value m)) |
ValueFun (Value m -> m (Value m)) |
ValueSum ValueShape Name [Value m] |
ValueAcc ValueShape (Value m -> Value m -> m (Value m)) !(Array Int (Value m)) |
ValueAD Depth ADVariable |

#### Instances

Instances details

Show (Value m) Source # |
Instance details Defined in Language.Futhark.Interpreter.Values Methods showsPrec :: Int -> Value m -> ShowS Source # show :: Value m -> String Source # showList :: [Value m] -> ShowS Source #
Eq (Value m) Source # |
Instance details Defined in Language.Futhark.Interpreter.Values Methods (==) :: Value m -> Value m -> Bool Source # (/=) :: Value m -> Value m -> Bool Source #

valueShape :: Value m -> ValueShape Source #

arrayValueShape :: Value m -> ValueShape Source #

Retrieve the part of the value shape that corresponds to outer array dimensions. This is used for reporting shapes in those cases where the full shape is not important, namely in indexing errors.

prettyValue :: Value m -> Doc a Source #

Prettyprint value.

valueText :: Value m -> Text Source #

The value in the textual format.

valueAccum :: (a -> Value m -> (a, Value m)) -> a -> Value m -> (a, Value m) Source #

valueAccumLM :: Monad f => (a -> Value m -> f (a, Value m)) -> a -> Value m -> f (a, Value m) Source #

fromTuple :: Value m -> Maybe [Value m] Source #

arrayLength :: Integral int => Array Int (Value m) -> int Source #

isEmptyArray :: Value m -> Bool Source #

Does the value correspond to an empty array?

prettyEmptyArray :: TypeBase () () -> Value m -> Text Source #

String representation of an empty array with the provided element type. This is pretty ad-hoc - don't expect good results unless the element type is a primitive.

toArray :: ValueShape -> [Value m] -> Value m Source #

toArray' :: ValueShape -> [Value m] -> Value m Source #

toTuple :: [Value m] -> Value m Source #

# Conversion

fromDataValue :: Value -> Value m Source #

Convert a Futhark value in the externally observable data format to an interpreter value.