FSharpx.Extras


State Module

Types

Type Description

State<'T, 'State>

StateBuilder

The state monad. The algorithm is adjusted from my original work off of Brian Beckman's http://channel9.msdn.com/shows/Going+Deep/Brian-Beckman-The-Zen-of-Expressing-State-The-State-Monad/. The approach was adjusted from Matthew Podwysocki's http://codebetter.com/blogs/matthew.podwysocki/archive/2009/12/30/much-ado-about-monads-state-edition.aspx and mirrors his final result.

Functions and values

Function or value Description

x *> y

Full Usage: x *> y

Parameters:
Returns: State<'c, 'b>
Modifiers: inline

Sequence actions, discarding the value of the first argument.

x : State<'a, 'b>
y : State<'c, 'b>
Returns: State<'c, 'b>

x <* y

Full Usage: x <* y

Parameters:
Returns: State<'a, 'b>
Modifiers: inline

Sequence actions, discarding the value of the second argument.

x : State<'a, 'b>
y : State<'c, 'b>
Returns: State<'a, 'b>

f <!> m

Full Usage: f <!> m

Parameters:
    f : 'a -> 'b
    m : State<'a, 'c>

Returns: State<'b, 'c>
Modifiers: inline

Infix map

f : 'a -> 'b
m : State<'a, 'c>
Returns: State<'b, 'c>

f <*> m

Full Usage: f <*> m

Parameters:
Returns: State<'b, 'c>
Modifiers: inline

Sequential application

f : State<('a -> 'b), 'c>
m : State<'a, 'c>
Returns: State<'b, 'c>

<=<x

Full Usage: <=<x

Parameters:
    x : 'a -> State<'b, 'c>

Returns: ('d -> State<'a, 'c>) -> 'd -> State<'b, 'c>
Modifiers: inline

Right-to-left Kleisli composition

x : 'a -> State<'b, 'c>
Returns: ('d -> State<'a, 'c>) -> 'd -> State<'b, 'c>

f =<< m

Full Usage: f =<< m

Parameters:
Returns: State<'b, 'c>
Modifiers: inline

Flipped >>=

f : 'a -> State<'b, 'c>
m : State<'a, 'c>
Returns: State<'b, 'c>

(>=>) f g x

Full Usage: (>=>) f g x

Parameters:
    f : 'a -> State<'b, 'c>
    g : 'b -> State<'d, 'c>
    x : 'a

Returns: State<'d, 'c>
Modifiers: inline

Left-to-right Kleisli composition

f : 'a -> State<'b, 'c>
g : 'b -> State<'d, 'c>
x : 'a
Returns: State<'d, 'c>

m >>. f

Full Usage: m >>. f

Parameters:
Returns: State<'c, 'b>
Modifiers: inline

Sequentially compose two state actions, discarding any value produced by the first

m : State<'a, 'b>
f : State<'c, 'b>
Returns: State<'c, 'b>

m >>= f

Full Usage: m >>= f

Parameters:
Returns: State<'c, 'b>
Modifiers: inline

Sequentially compose two actions, passing any value produced by the first as an argument to the second.

m : State<'a, 'b>
f : 'a -> State<'c, 'b>
Returns: State<'c, 'b>

ap m f

Full Usage: ap m f

Parameters:
Returns: State<'c, 'b>
Modifiers: inline

Sequential application

m : State<'a, 'b>
f : State<('a -> 'c), 'b>
Returns: State<'c, 'b>

bind k m s

Full Usage: bind k m s

Parameters:
    k : 'a -> 'b -> 'c
    m : 'd -> 'a * 'b
    s : 'd

Returns: 'c

Sequentially compose two actions, passing any value produced by the first as an argument to the second.

k : 'a -> 'b -> 'c
m : 'd -> 'a * 'b
s : 'd
Returns: 'c

empty s

Full Usage: empty s

Parameters:
    s : 'a

Returns: unit * 'a

Instance of state monad without value

s : 'a
Returns: unit * 'a

eval m s

Full Usage: eval m s

Parameters:
    m : 'a -> 'b * 'c
    s : 'a

Returns: 'b

Evaluates a state computation with the given initial state and returns the final value, discarding the final state.

m : 'a -> 'b * 'c
s : 'a
Returns: 'b

exec m s

Full Usage: exec m s

Parameters:
    m : 'a -> 'b * 'c
    s : 'a

Returns: 'c

Evaluates a state computation with the given initial state and returns the final state, discarding the final value.

m : 'a -> 'b * 'c
s : 'a
Returns: 'c

foldM f s

Full Usage: foldM f s

Parameters:
    f : 'a -> 'b -> State<'a, 'c>
    s : 'a

Returns: 'b seq -> State<'a, 'c>

Fold encapsulated in the State monad

f : 'a -> 'b -> State<'a, 'c>
s : 'a
Returns: 'b seq -> State<'a, 'c>

getState s

Full Usage: getState s

Parameters:
    s : 'b

Returns: 'b * 'b

Returns state value from the monad.

s : 'b
Returns: 'b * 'b

lift2 f a b

Full Usage: lift2 f a b

Parameters:
    f : 'a -> 'b -> 'c
    a : State<'a, 'd>
    b : State<'b, 'd>

Returns: State<'c, 'd>
Modifiers: inline

Promote a function to a monad/applicative, scanning the monadic/applicative arguments from left to right.

f : 'a -> 'b -> 'c
a : State<'a, 'd>
b : State<'b, 'd>
Returns: State<'c, 'd>

map f m

Full Usage: map f m

Parameters:
    f : 'a -> 'b
    m : State<'a, 'c>

Returns: State<'b, 'c>
Modifiers: inline

Transforms a State value by using a specified mapping function.

f : 'a -> 'b
m : State<'a, 'c>
Returns: State<'b, 'c>

mapM f x

Full Usage: mapM f x

Parameters:
    f : 'a -> State<'b, 'c>
    x : 'a list

Returns: State<'b list, 'c>
Modifiers: inline

Maps each element of a list to a monadic action, evaluates these actions from left to right, and collects the results.

f : 'a -> State<'b, 'c>
x : 'a list
Returns: State<'b list, 'c>

putState s arg2

Full Usage: putState s arg2

Parameters:
    s : 'b
    arg1 : 'c

Returns: unit * 'b

Replaces state inside the monad.

s : 'b
arg1 : 'c
Returns: unit * 'b

returnM x

Full Usage: returnM x

Parameters:
    x : 'a

Returns: State<'a, 'b>
Modifiers: inline

Inject a value into the State type

x : 'a
Returns: State<'a, 'b>

sequence s

Full Usage: sequence s

Parameters:
Returns: State<'a list, 'b>
Modifiers: inline

Evaluates each monadic action in the list from left to right, and collects the results.

s : State<'a, 'b> list
Returns: State<'a list, 'b>

state

Full Usage: state

Returns: StateBuilder
Returns: StateBuilder