State I

home1 home2
 Bib
 Algorithms
 Bioinfo
 FP
 Logic
 MML
 Prog.Lang
and the
 Book

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


Coding Ockham's Razor, L. Allison, Springer

A Practical Introduction to Denotational Semantics, L. Allison, CUP

Linux
 Ubuntu
free op. sys.
OpenOffice
free office suite
The GIMP
~ free photoshop
Firefox
web browser

λ ...
:: 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 Saturday, 20-Apr-2024 05:29:04 AEST.