Module NDState

This module provides an implementation of non-deterministic state monad where the non-determinism distributes over state.

Author: Björn Peemöller

Version: September 2015

Summary of exported operations:

bindResult :: Result a -> (a -> Result b) -> Result b   
Monadic bind operation.
runState :: (a -> Result (b,a)) -> a -> Result (b,a)   
Run a monadic computation.
(>+=) :: (a -> Result (b,a)) -> (b -> a -> Result (c,a)) -> a -> Result (c,a)   
Monadic bind for state monad.
(>+) :: (a -> Result (b,a)) -> (a -> Result (c,a)) -> a -> Result (c,a)   
Monadic sequence for state monad.
(>!) :: (a -> Result ((),a)) -> (a -> Result (b,a)) -> a -> Result (b,a)   
Strict monadic sequence for state monad.
returnS :: a -> b -> Result (a,b)   
Monadic return for state monad.
choiceS :: (a -> Result (b,a)) -> (a -> Result (b,a)) -> a -> Result (b,a)   
Non-Deterministic choice for state monad.
getS :: a -> Result (a,a)   
Retrieve the state from the state monad.
getsS :: (a -> b) -> a -> Result (b,a)   
Retrieve the state from the state monad using an accessor function.
putS :: a -> a -> Result ((),a)   
Set the state from the state monad.
modifyS :: (a -> a) -> a -> Result ((),a)   
Modify the state from the state monad using a function.
sequenceS :: [a -> Result (b,a)] -> a -> Result ([b],a)   
Sequence a list of monadic computations and collect the results.
sequenceS_ :: [a -> Result (b,a)] -> a -> Result ((),a)   
Sequence a list of monadic computations and discard the results.
mapS :: (a -> b -> Result (c,b)) -> [a] -> b -> Result ([c],b)   
Perform a monadic computations for each element in a list and collect the results.
mapS_ :: (a -> b -> Result (c,b)) -> [a] -> b -> Result ((),b)   
Perform a monadic computations for each element in a list and discard the results.
(<$>) :: (a -> b) -> (c -> Result (a,c)) -> c -> Result (b,c)   
Apply a pure function to the result of a monadic action.
(<*>) :: (a -> Result (b -> c,a)) -> (a -> Result (b,a)) -> a -> Result (c,a)   
Apply a function originating from the first monadic computation to the result of the second monadic action.
(<|>) :: (a -> Result (b,a)) -> (a -> Result (b,a)) -> a -> Result (b,a)   
Infix version of non-deterministic choice.
anyS :: (a -> b -> Result (Bool,b)) -> [a] -> b -> Result (Bool,b)   
Monadic version of any.
allS :: (a -> b -> Result (Bool,b)) -> [a] -> b -> Result (Bool,b)   
Monadic version of all.

Exported datatypes:


Result

Non-Deterministic result

Constructors:

  • Return :: a -> Result a : single result
  • Choice :: (Result a) -> (Result a) -> Result a : non-deterministic choice

State

Non-Deterministic state monad.

Type synonym: State a b = a -> Result (b,a)


Exported operations:

bindResult :: Result a -> (a -> Result b) -> Result b   

Monadic bind operation.

runState :: (a -> Result (b,a)) -> a -> Result (b,a)   

Run a monadic computation.

(>+=) :: (a -> Result (b,a)) -> (b -> a -> Result (c,a)) -> a -> Result (c,a)   

Monadic bind for state monad.

Further infos:
  • defined as left-associative infix operator with precedence 1

(>+) :: (a -> Result (b,a)) -> (a -> Result (c,a)) -> a -> Result (c,a)   

Monadic sequence for state monad.

Further infos:
  • defined as left-associative infix operator with precedence 1

(>!) :: (a -> Result ((),a)) -> (a -> Result (b,a)) -> a -> Result (b,a)   

Strict monadic sequence for state monad.

Further infos:
  • defined as left-associative infix operator with precedence 1

returnS :: a -> b -> Result (a,b)   

Monadic return for state monad.

Further infos:
  • solution complete, i.e., able to compute all solutions

choiceS :: (a -> Result (b,a)) -> (a -> Result (b,a)) -> a -> Result (b,a)   

Non-Deterministic choice for state monad.

getS :: a -> Result (a,a)   

Retrieve the state from the state monad.

getsS :: (a -> b) -> a -> Result (b,a)   

Retrieve the state from the state monad using an accessor function.

putS :: a -> a -> Result ((),a)   

Set the state from the state monad.

Further infos:
  • solution complete, i.e., able to compute all solutions

modifyS :: (a -> a) -> a -> Result ((),a)   

Modify the state from the state monad using a function.

sequenceS :: [a -> Result (b,a)] -> a -> Result ([b],a)   

Sequence a list of monadic computations and collect the results.

sequenceS_ :: [a -> Result (b,a)] -> a -> Result ((),a)   

Sequence a list of monadic computations and discard the results.

mapS :: (a -> b -> Result (c,b)) -> [a] -> b -> Result ([c],b)   

Perform a monadic computations for each element in a list and collect the results.

mapS_ :: (a -> b -> Result (c,b)) -> [a] -> b -> Result ((),b)   

Perform a monadic computations for each element in a list and discard the results.

(<$>) :: (a -> b) -> (c -> Result (a,c)) -> c -> Result (b,c)   

Apply a pure function to the result of a monadic action.

Further infos:
  • defined as left-associative infix operator with precedence 4

(<*>) :: (a -> Result (b -> c,a)) -> (a -> Result (b,a)) -> a -> Result (c,a)   

Apply a function originating from the first monadic computation to the result of the second monadic action.

Further infos:
  • defined as left-associative infix operator with precedence 4

(<|>) :: (a -> Result (b,a)) -> (a -> Result (b,a)) -> a -> Result (b,a)   

Infix version of non-deterministic choice.

Further infos:
  • defined as left-associative infix operator with precedence 3

anyS :: (a -> b -> Result (Bool,b)) -> [a] -> b -> Result (Bool,b)   

Monadic version of any.

allS :: (a -> b -> Result (Bool,b)) -> [a] -> b -> Result (Bool,b)   

Monadic version of all.