effect-monad-0.7.0.0: Embeds effect systems into Haskell using graded monads

Safe HaskellNone
LanguageHaskell98

Control.Effect.State

Synopsis

Documentation

data Set n :: [*] -> * where #

Constructors

Empty :: Set ([] *) 
Ext :: Set ((:) * e s) 

Instances

(Eq e, Eq (Set s)) => Eq (Set ((:) * e s)) 

Methods

(==) :: Set ((* ': e) s) -> Set ((* ': e) s) -> Bool #

(/=) :: Set ((* ': e) s) -> Set ((* ': e) s) -> Bool #

(Show e, Show' (Set s)) => Show (Set ((:) * e s)) 

Methods

showsPrec :: Int -> Set ((* ': e) s) -> ShowS #

show :: Set ((* ': e) s) -> String #

showList :: [Set ((* ': e) s)] -> ShowS #

Show (Set ([] *)) 

Methods

showsPrec :: Int -> Set [*] -> ShowS #

show :: Set [*] -> String #

showList :: [Set [*]] -> ShowS #

(Show' (Set s), Show e) => Show' (Set ((:) * e s)) 

Methods

show' :: Set ((* ': e) s) -> String

Show' (Set ([] *)) 

Methods

show' :: Set [*] -> String

get :: Var v -> State '[v :-> (a :! R)] a Source #

Read from a variable v of type a. Raise a read effect.

put :: Var v -> a -> State '[v :-> (a :! W)] () Source #

Write to a variable v with a value of type a. Raises a write effect

data State s a Source #

Parametric effect state monad

Constructors

State 

Fields

Instances

Effect [*] State Source # 

Associated Types

type Unit State (m :: State -> * -> *) :: k Source #

type Plus State (m :: State -> * -> *) (f :: State) (g :: State) :: k Source #

type Inv State (m :: State -> * -> *) (f :: State) (g :: State) :: Constraint Source #

Methods

return :: a -> m (Unit State m) a Source #

(>>=) :: Inv State m f g => m f a -> (a -> m g b) -> m (Plus State m f g) b Source #

(>>) :: Inv State m f g => m f a -> m g b -> m (Plus State m f g) b Source #

type Unit [*] State Source # 
type Unit [*] State = [] *
type Plus [*] State s t Source # 
type Plus [*] State s t = UnionS s t
type Inv [*] State s t Source # 
type Inv [*] State s t = (IsSet * s, IsSet * (Reads s), IsSet * (Writes s), IsSet * t, IsSet * (Reads t), IsSet * (Writes t), (~) [*] (Reads (Reads t)) (Reads t), (~) [*] (Writes (Writes s)) (Writes s), Split (Reads s) (Reads t) (Reads (UnionS s t)), Unionable (Writes s) (Writes t), IntersectR (Writes s) (Reads t), (~) [*] (Writes (UnionS s t)) (UnionS (Writes s) (Writes t)))

data k :-> v infixl 2 Source #

Constructors

(Var k) :-> v infixl 2 

Instances

(Show (Var k), Show v) => Show ((:->) k v) Source # 

Methods

showsPrec :: Int -> (k :-> v) -> ShowS #

show :: (k :-> v) -> String #

showList :: [k :-> v] -> ShowS #

Update ((:) * ((:->) u ((:!) b s)) as) as' => Update ((:) * ((:->) v ((:!) a W)) ((:) * ((:->) u ((:!) b s)) as)) as' Source # 

Methods

update :: Set ((* ': (v :-> (a :! W))) ((* ': (u :-> (b :! s))) as)) -> Set as'

Update ((:) * ((:->) v ((:!) a R)) as) as' => Update ((:) * ((:->) v ((:!) a W)) ((:) * ((:->) v ((:!) b R)) as)) as' Source # 

Methods

update :: Set ((* ': (v :-> (a :! W))) ((* ': (v :-> (b :! R))) as)) -> Set as'

Update ((:) * ((:->) u ((:!) b s)) as) as' => Update ((:) * ((:->) v ((:!) a R)) ((:) * ((:->) u ((:!) b s)) as)) ((:) * ((:->) v ((:!) a R)) as') Source # 

Methods

update :: Set ((* ': (v :-> (a :! R))) ((* ': (u :-> (b :! s))) as)) -> Set ((* ': (v :-> (a :! R))) as')

type Cmp * ((:->) v a) ((:->) u b) Source # 
type Cmp * ((:->) v a) ((:->) u b) = CmpSymbol v u

data a :! s infixl 3 Source #

Describes an effect action s on a value of type a

Constructors

a :! (Action s) infixl 3 

Instances

(Show (Action f), Show a) => Show ((:!) a f) Source # 

Methods

showsPrec :: Int -> (a :! f) -> ShowS #

show :: (a :! f) -> String #

showList :: [a :! f] -> ShowS #

Update ((:) * ((:->) u ((:!) b s)) as) as' => Update ((:) * ((:->) v ((:!) a W)) ((:) * ((:->) u ((:!) b s)) as)) as' Source # 

Methods

update :: Set ((* ': (v :-> (a :! W))) ((* ': (u :-> (b :! s))) as)) -> Set as'

Update ((:) * ((:->) v ((:!) a R)) as) as' => Update ((:) * ((:->) v ((:!) a W)) ((:) * ((:->) v ((:!) b R)) as)) as' Source # 

Methods

update :: Set ((* ': (v :-> (a :! W))) ((* ': (v :-> (b :! R))) as)) -> Set as'

Update ((:) * ((:->) u ((:!) b s)) as) as' => Update ((:) * ((:->) v ((:!) a R)) ((:) * ((:->) u ((:!) b s)) as)) ((:) * ((:->) v ((:!) a R)) as') Source # 

Methods

update :: Set ((* ': (v :-> (a :! R))) ((* ': (u :-> (b :! s))) as)) -> Set ((* ': (v :-> (a :! R))) as')

data Eff Source #

Provides an effect-parameterised version of the state monad, which gives an effect system for stateful computations with annotations that are sets of variable-type-action triples.

Distinguish reads, writes, and read-writes

Constructors

R 
W 
RW 

data Action s Source #

Provides a wrapper for effect actions

Constructors

Eff 

data Var k where Source #

Constructors

Var :: Var k 
X :: Var "x" 
Y :: Var "y" 
Z :: Var "z" 

Instances

Show (Var v) Source # 

Methods

showsPrec :: Int -> Var v -> ShowS #

show :: Var v -> String #

showList :: [Var v] -> ShowS #

Show (Var "x") Source # 

Methods

showsPrec :: Int -> Var "x" -> ShowS #

show :: Var "x" -> String #

showList :: [Var "x"] -> ShowS #

Show (Var "y") Source # 

Methods

showsPrec :: Int -> Var "y" -> ShowS #

show :: Var "y" -> String #

showList :: [Var "y"] -> ShowS #

Show (Var "z") Source # 

Methods

showsPrec :: Int -> Var "z" -> ShowS #

show :: Var "z" -> String #

showList :: [Var "z"] -> ShowS #

union :: Unionable s t => Set s -> Set t -> Set (UnionS s t) Source #

Union operation for state effects

type UnionS s t = Nub (Sort (s :++ t)) Source #

type family Reads t where ... Source #

Calculate just the reader effects

Equations

Reads '[] = '[] 
Reads ((k :-> (a :! R)) ': xs) = (k :-> (a :! R)) ': Reads xs 
Reads ((k :-> (a :! RW)) ': xs) = (k :-> (a :! R)) ': Reads xs 
Reads ((k :-> (a :! W)) ': xs) = Reads xs 

type family Writes t where ... Source #

Calculate just the writer effects

Equations

Writes '[] = '[] 
Writes ((k :-> (a :! W)) ': xs) = (k :-> (a :! W)) ': Writes xs 
Writes ((k :-> (a :! RW)) ': xs) = (k :-> (a :! W)) ': Writes xs 
Writes ((k :-> (a :! R)) ': xs) = Writes xs 

type Unionable s t = (Sortable (s :++ t), Nubable (Sort (s :++ t)) (Nub (Sort (s :++ t))), Split s t (Union s t)) Source #

class Sortable xs #

Value-level quick sort that respects the type-level ordering

Minimal complete definition

quicksort

Instances

Sortable ([] *) 

Methods

quicksort :: Set [*] -> Set (Sort * [*]) #

(Sortable (Filter * FMin p xs), Sortable (Filter * FMax p xs), FilterV FMin p xs, FilterV FMax p xs) => Sortable ((:) * p xs) 

Methods

quicksort :: Set ((* ': p) xs) -> Set (Sort * ((* ': p) xs)) #

type SetLike s = Nub (Sort s) Source #

type StateSet f = (StateSetProperties f, StateSetProperties (Reads f), StateSetProperties (Writes f)) Source #

Captures what it means to be a set of state effects

type IntersectR s t = (Sortable (s :++ t), Update (Sort (s :++ t)) t) Source #

class Update s t Source #

Update reads, that is any writes are pushed into reads, a bit like intersection

Minimal complete definition

update

Instances

Update xs ([] *) Source # 

Methods

update :: Set xs -> Set [*]

Update ((:) * ((:->) u ((:!) b s)) as) as' => Update ((:) * ((:->) v ((:!) a W)) ((:) * ((:->) u ((:!) b s)) as)) as' Source # 

Methods

update :: Set ((* ': (v :-> (a :! W))) ((* ': (u :-> (b :! s))) as)) -> Set as'

Update ((:) * ((:->) v ((:!) a R)) as) as' => Update ((:) * ((:->) v ((:!) a W)) ((:) * ((:->) v ((:!) b R)) as)) as' Source # 

Methods

update :: Set ((* ': (v :-> (a :! W))) ((* ': (v :-> (b :! R))) as)) -> Set as'

Update ((:) * ((:->) u ((:!) b s)) as) as' => Update ((:) * ((:->) v ((:!) a R)) ((:) * ((:->) u ((:!) b s)) as)) ((:) * ((:->) v ((:!) a R)) as') Source # 

Methods

update :: Set ((* ': (v :-> (a :! R))) ((* ': (u :-> (b :! s))) as)) -> Set ((* ': (v :-> (a :! R))) as')

Update ((:) * e ([] *)) ((:) * e ([] *)) Source # 

Methods

update :: Set ((* ': e) [*]) -> Set ((* ': e) [*])

type family Sort k (xs :: [k]) :: [k] where ... #

Type-level quick sort for normalising the representation of sets

Equations

Sort k ([] k) = [] k 
Sort k ((:) k x xs) = (:++) k ((:++) k (Sort k (Filter k FMin x xs)) ((:) k x ([] k))) (Sort k (Filter k FMax x xs)) 

class Split s t st #

Splitting a union a set, given the sets we want to split it into

Minimal complete definition

split

Instances

Split s t st => Split s ((:) * x t) ((:) * x st) 

Methods

split :: Set ((* ': x) st) -> (Set s, Set ((* ': x) t)) #

Split ([] *) ([] *) ([] *) 

Methods

split :: Set [*] -> (Set [*], Set [*]) #

Split s t st => Split ((:) * x s) t ((:) * x st) 

Methods

split :: Set ((* ': x) st) -> (Set ((* ': x) s), Set t) #

Split s t st => Split ((:) * x s) ((:) * x t) ((:) * x st) 

Methods

split :: Set ((* ': x) st) -> (Set ((* ': x) s), Set ((* ': x) t)) #