structs-0.1.1: 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 #

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

Methods

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

struct :: Coercible (t s) (Object s) => Dict (Coercible (t s) (Object s)) #

Instances

Struct Object # 

Methods

struct :: Dict (Coercible * (Object s) (Object s)) #

Struct Label # 

Methods

struct :: Dict (Coercible * (Label s) (Object s)) #

Struct (LinkCut a) # 

Methods

struct :: Dict (Coercible * (LinkCut a s) (Object s)) #

Struct (Order a) # 

Methods

struct :: Dict (Coercible * (Order a s) (Object s)) #

data Object s #

Instances

Struct Object # 

Methods

struct :: Dict (Coercible * (Object s) (Object s)) #

Eq (Object s) # 

Methods

(==) :: Object s -> Object s -> Bool #

(/=) :: Object s -> Object s -> Bool #

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

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

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

Nil

pattern Nil :: Struct t => t s #

Truly imperative.

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

Predicate to check if a struct is Nil.

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

Slots and Fields

data Slot x y #

A Slot is a reference to another unboxed mutable object.

Instances

Precomposable k1 k2 (Slot k1 k2) # 

Methods

(#) :: Slot (Slot k1 k2) (Slot k1 k2) x y -> t y z -> t x z #

slot #

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)) #

Get the value from a Slot

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

Set the value of a Slot

data Field x a #

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

Instances

Precomposable k * (Field k) # 

Methods

(#) :: Slot (Field k) (Field k) x y -> t y z -> t x z #

field #

Arguments

:: Int

slot

-> Field s a 

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

unboxedField #

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 #

Get the value of a field in a struct

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

Set the value of a field in a struct

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

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

class Precomposable t where #

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

Minimal complete definition

(#)

Methods

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

Instances

Precomposable k1 k2 (Slot k1 k2) # 

Methods

(#) :: Slot (Slot k1 k2) (Slot k1 k2) x y -> t y z -> t x z #

Precomposable k * (Field k) # 

Methods

(#) :: Slot (Field k) (Field k) x y -> t y z -> t x z #