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

Copyright(C) 2015 Edward Kmett
LicenseBSD-style (see the file LICENSE)
MaintainerEdward Kmett <ekmett@gmail.com>
Stabilityexperimental
Portabilitynon-portable
Safe HaskellUnsafe
LanguageHaskell2010

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. The argument to struct is ignored and is only present to help type inference.

Methods

struct :: proxy t -> Dict (Coercible (t s) (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

Slots and Fields

data Slot x y Source

A Slot is a reference to another unboxed mutable object.

Instances

slot :: Int -> Slot s t Source

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

field :: Int -> Field s a Source

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

unboxedField :: Prim a => Int -> Int -> Field s a Source

Store the reference in the nth slot of 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

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