Scrapbook-0.4.0: code examples
Copyright© Frank Jung 202020212022
LicenseGPL-3
Safe HaskellSafe-Inferred
LanguageHaskell2010

MyState

Description

A simple State monad implementation to explore it's characteristics.

Based on many articles, but principally from: The State Monad: A Tutorial for the Confused?

Synopsis

Documentation

newtype MyState s a Source #

Mock of MyState data type. (Not yet a Monad, Functor or Applicative.)

Constructors

MyState 

Fields

Instances

Instances details
Applicative (MyState s) Source # 
Instance details

Defined in MyState

Methods

pure :: a -> MyState s a #

(<*>) :: MyState s (a -> b) -> MyState s a -> MyState s b #

liftA2 :: (a -> b -> c) -> MyState s a -> MyState s b -> MyState s c #

(*>) :: MyState s a -> MyState s b -> MyState s b #

(<*) :: MyState s a -> MyState s b -> MyState s a #

Functor (MyState s) Source # 
Instance details

Defined in MyState

Methods

fmap :: (a -> b) -> MyState s a -> MyState s b #

(<$) :: a -> MyState s b -> MyState s a #

Monad (MyState s) Source # 
Instance details

Defined in MyState

Methods

(>>=) :: MyState s a -> (a -> MyState s b) -> MyState s b #

(>>) :: MyState s a -> MyState s b -> MyState s b #

return :: a -> MyState s a #

get :: MyState s s Source #

Returns current state.

put :: s -> MyState s () Source #

Replace current state with the given value. Returns unit.

modify :: (s -> s) -> MyState s () Source #

Update current state using the given function.

evalState :: MyState s a -> s -> a Source #

Returns results of state function.

execState :: MyState s a -> s -> s Source #

Returns final state.