File:  [Research Unix] / researchv10no / cmd / sml / doc / examples / missionaries / buffers.sml
Revision 1.1.1.1 (vendor branch): download - view: text, annotated - select for diffs
Tue Apr 24 17:21:35 2018 UTC (8 years, 1 month ago) by root
Branches: belllabs, MAIN
CVS tags: researchv10, HEAD
researchv10 Norman

(* depth-first state buffer -- implements a stack *)

structure DF : BUFFER =
struct
  type 'a buffer = 'a list
  exception EMPTY
  val empty = []
  fun get [] = raise EMPTY
    | get(x::l) = (x,l)
  fun put(x,l) = x::l
end


(* breadth-first state buffer -- implements an applicative queue *)

structure BF : BUFFER =
struct
  type 'a buffer = 'a list * 'a list
  exception EMPTY
  val empty = ([],[])
  fun get([],[]) = raise EMPTY
    | get(a::r,l) = (a,(r,l))
    | get([],l) = get(rev l,[])
  fun put(x,(m,l)) = (m,x::l)
end

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.