{-# LANGUAGE MultiParamTypeClasses, FlexibleInstances, FunctionalDependencies, FlexibleContexts #-} {- Extension of TML, Loop providing side effects: * statement sequencing * array write access Note that array access is not the same as MArray since it doesn't provide allocation, which is part of the target framework. Note that while TML and Loop are pure functional languages, Array is not! For TML and Loop the monad is just used for code generation, i.e. it's Value interpretation can use the Identity monad. However, Array needs some kind of mutable array monad to work. -} module Array (Array(..)) where import Data import Struct {- m TML's code generation monad r Representation type a Array (reference) type t Array value type Tint Array Index type (currently fixed) -} class (Data m r, DataWord t) => Array m r a t | r -> a where {- Array declaration. Definition (allocation) is always determined by the framework of the TML implementation. This statement creates a context in which the following variables are defined: a: array reference f: first index l: last index s: index stride -} -- _bounds :: r (a t) -> m (r Tint, r Tint, r Tint) {- Array access. There is no bounds checking. The idea is to never use these operations directly, but to write combinators that generate array access and index computations that are guaranteed to be in-bounds. Note the little nuance: the return type of _get doesn't need to be a primitive value type as we support arrays of pointers, but the element type of _set is primitive, because we don't support changing pointer structure through assignment. -} get :: r (a t) -> r Tint -> m (r t) set :: r (a t) -> r Tint -> r t -> m (r ())