structs-0: Strict GC'd imperative object-oriented programming with cheap pointers.

Data.Struct

Contents

Description

Synopsis

# Documentation

class Struct t where Source

An instance for `Struct` `t` is a witness to the machine-level equivalence of `t` and `Object`.

Minimal complete definition

Nothing

Methods

struct :: Dict (Coercible (t s) (Object s)) Source

Instances

 Source Source Source Struct (Order a) Source

data Object s Source

Instances

 Source Eq (Object s) Source

eqStruct :: Struct t => t s -> t s -> Bool Source

alloc :: (PrimMonad m, Struct t) => Int -> m (t (PrimState m)) Source

Allocate a structure made out of `n` slots. Initialize the structure before proceeding!

# Nil

pattern Nil :: () => Struct t => t s Source

Truly imperative.

isNil :: Struct t => t s -> Bool Source

Predicate to check if a struct is `Nil`.

````>>> ````isNil (Nil :: Object (PrimState IO))
```True
`>>> ````o <- alloc 1 :: IO (Object (PrimState IO))
````>>> ````isNil o
```False
```

Constructors

 NullPointerException

# Slots and Fields

data Slot x y Source

A `Slot` is a reference to another unboxed mutable object.

Instances

 Precomposable k k (Slot k k) Source

Arguments

 :: Int slot -> Slot s t

The `Slot` at the given position in a `Struct`

get :: (PrimMonad m, Struct x, Struct y) => Slot x y -> x (PrimState m) -> m (y (PrimState m)) Source

Get the value from a `Slot`

set :: (PrimMonad m, Struct x, Struct y) => Slot x y -> x (PrimState m) -> y (PrimState m) -> m () Source

Set the value of a `Slot`

data Field x a Source

A `Field` is a reference from a struct to a normal Haskell data type.

Instances

 Precomposable k * (Field k) Source

Arguments

 :: Int slot -> Field s a

Store the reference to the Haskell data type in a normal field

Arguments

 :: Prim a => Int slot -> Int argument -> Field s a

Store the reference in the nth slot in the nth argument, treated as a MutableByteArray

getField :: (PrimMonad m, Struct x) => Field x a -> x (PrimState m) -> m a Source

Get the value of a field in a struct

setField :: (PrimMonad m, Struct x) => Field x a -> x (PrimState m) -> a -> m () Source

Set the value of a field in a struct

modifyField :: (Struct x, PrimMonad m) => Field x a -> x (PrimState m) -> (a -> a) -> m () Source

modifyField' :: (Struct x, PrimMonad m) => Field x a -> x (PrimState m) -> (a -> a) -> m () Source

class Precomposable t where Source

We can compose slots to get a nested slot or field accessor

Methods

(#) :: Slot x y -> t y z -> t x z Source

Instances

 Precomposable k * (Field k) Source Precomposable k k (Slot k k) Source