futhark
Safe HaskellNone
LanguageGHC2021

Language.Futhark.Interpreter.Values

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

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
Functor Shape Source # 
Instance details

Defined in Language.Futhark.Interpreter.Values

Methods

fmap :: (a -> b) -> Shape a -> Shape b #

(<$) :: a -> Shape b -> Shape a #

Foldable Shape Source # 
Instance details

Defined in Language.Futhark.Interpreter.Values

Methods

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

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

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

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

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

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

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

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

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

toList :: Shape a -> [a] #

null :: Shape a -> Bool #

length :: Shape a -> Int #

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

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

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

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

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

Traversable Shape Source # 
Instance details

Defined in Language.Futhark.Interpreter.Values

Methods

traverse :: Applicative f => (a -> f b) -> Shape a -> f (Shape b) #

sequenceA :: Applicative f => Shape (f a) -> f (Shape a) #

mapM :: Monad m => (a -> m b) -> Shape a -> m (Shape b) #

sequence :: Monad m => Shape (m a) -> m (Shape a) #

Show d => Show (Shape d) Source # 
Instance details

Defined in Language.Futhark.Interpreter.Values

Methods

showsPrec :: Int -> Shape d -> ShowS #

show :: Shape d -> String #

showList :: [Shape d] -> ShowS #

Eq d => Eq (Shape d) Source # 
Instance details

Defined in Language.Futhark.Interpreter.Values

Methods

(==) :: Shape d -> Shape d -> Bool #

(/=) :: Shape d -> Shape d -> Bool #

Pretty d => Pretty (Shape d) Source # 
Instance details

Defined in Language.Futhark.Interpreter.Values

Methods

pretty :: Shape d -> Doc ann #

prettyList :: [Shape d] -> Doc ann #

type ValueShape = Shape Int64 Source #

The shape of an array.

Values

data Value (m :: Type -> Type) Source #

A Futhark value as produced and used by the interpreter. Some of these represent semantically meaningful Futhark values, while others represent internal operational things that should never be returned by an interpreter entry point, but can be observed in its intermediate stage (e.g. when using breakpoints to access the environment).

Constructors

ValuePrim !PrimValue

A primitive value.

ValueArray ValueShape !(Array Int (Value m))

An array, with explicit shape. The shape is the full shape of the value, including element shape.

ValueRecord (Map Name (Value m))

A record, which also subsumes tuples.

ValueFun (Value m -> m (Value m))

A function value.

ValueSum ValueShape Name [Value m]

A sum value.

ValueAcc ValueShape (Value m -> Value m -> m (Value m)) !(Array Int (Value m))

Internal value: an accumulator. Represented by the shape, the update function, and the array.

ValueAD Depth ADVariable

Internal value: A primitive value with added information used in automatic differentiation

ValueLazyFFI ValueShape ValueRef [Int64]

A lazy reference to a value on a Futhark Server. These can be returned by the interpreter, although the only sane way to use them for anything is to retrieve them.

We store the full shape locally, along with the indexes applied so far.

Instances

Instances details
Show (Value m) Source # 
Instance details

Defined in Language.Futhark.Interpreter.Values

Methods

showsPrec :: Int -> Value m -> ShowS #

show :: Value m -> String #

showList :: [Value m] -> ShowS #

Eq (Value m) Source # 
Instance details

Defined in Language.Futhark.Interpreter.Values

Methods

(==) :: Value m -> Value m -> Bool #

(/=) :: Value m -> Value m -> Bool #

valueShape :: forall (m :: Type -> Type). Value m -> ValueShape Source #

The shape of a value.

arrayValueShape :: forall (m :: Type -> Type). 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 :: forall (m :: Type -> Type) a. Value m -> Doc a Source #

Prettyprint value.

valueText :: forall (m :: Type -> Type). Value m -> Text Source #

The value in the textual format.

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

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

fromTuple :: forall (m :: Type -> Type). Value m -> Maybe [Value m] Source #

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

isEmptyArray :: forall (m :: Type -> Type). Value m -> Bool Source #

Does the value correspond to an empty array?

prettyEmptyArray :: forall (m :: Type -> Type). TypeBase () NoMode -> 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 :: forall (m :: Type -> Type). ValueShape -> [Value m] -> Value m Source #

toArray' :: forall (m :: Type -> Type). ValueShape -> [Value m] -> Value m Source #

toTuple :: forall (m :: Type -> Type). [Value m] -> Value m Source #

Conversion

fromDataValue :: forall (m :: Type -> Type). Value -> Value m Source #

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

asByteString :: forall (m :: Type -> Type). Value m -> Maybe ByteString Source #

If the value represents an array of type []u8, then return those bytes.