## State I

 home  Bib Algorithms Bioinfo FP Logic MML Prog.Lang and the mmlist

FP
Lambda
Introduction
Examples
state 1
state 2
Many variations are possible in creating a function to represent an object with state, e.g.
Obj :List Cmd -> List Ans
where the commands (Cmd) are to set a state, or to query (get) the current state, and the answers (Ans) are ok, (st,State) or err.
The initial state is hard-wired here, but could be an initial parameter of Obj.

If we concentrate on the state transformations, we have

γ : Cmd
Cmds = List Cmd
σ : State
C : Cmd -> State -> State
C `γ12' σ = (C γ2)o(C γ1) σ

and indeed the above is sufficient if the output "file", or answer, is made a part of the state, together with the values of the true state variables. (For an alternative, see [state 2].)

```let Obj = lambda Cmds.  { List Cmd -> List Ans }

let rec
process = lambda state. lambda Cmds.
if null Cmds then nil else
let rec Cmd   = hd  Cmds,
tag   = fst Cmd,
param = snd Cmd
in if tag = set then { change State }
(pair ok nil)   :: (process param tl Cmds)
else if tag = get then
(pair st state) :: (process state tl Cmds)
else (pair err nil)  :: (process state tl Cmds)

in process state0 Cmds

```

window on the wide world:
 The Darwin Awards V: Next Evolution

 Linux  Ubuntu free op. sys. OpenOffice free office suite, ver 3.4+ The GIMP ~ free photoshop Firefox web browser FlashBlock like it says!

λ ...
 :: list cons nil the [ ] list null predicate hd head (1st) tl tail (rest)

 © L. Allison   http://www.allisons.org/ll/   (or as otherwise indicated), Faculty of Information Technology (Clayton), Monash University, Australia 3800 (6/'05 was School of Computer Science and Software Engineering, Fac. Info. Tech., Monash University, was Department of Computer Science, Fac. Comp. & Info. Tech., '89 was Department of Computer Science, Fac. Sci., '68-'71 was Department of Information Science, Fac. Sci.) Created with "vi (Linux + Solaris)",  charset=iso-8859-1,  fetched Tuesday, 20-Aug-2019 10:44:31 AEST.