func-data-presn/Queue2.txt

56 lines
882 B
Plaintext

--Load Queue2.hs - lazy rebuilding queue
:l Queue2.hs
--Start ghc-vis
:vis
let x = empty
:view x
--Insert a value - view new queue; we already triggered the reverse
let y = insert 1 x
:view y
--Remove the value - forces the evaluation in y, but we discard the new tree
let (z,_) = remove y
print z
:update
--Add another element to y; now there's one in the right list
let a = insert 2 y
:view a
--Add one more, and we trigger the swap again
let b = insert 3 a
:view b
--We can add 3 more and still not swap
let c = insert 6 $ insert 5 $ insert 4 b
:view c
--One more, and now we trigger the swap
let d = insert 7 c
:view d
--Let's remove one by one and see how evaluation progresses
let (e,f) = remove d
print e
:view f
let (g,h) = remove f
print g
:view h
let (i,j) = remove h
print i
:view j
let (k,l) = remove j
print k
:view l
let (m,n) = remove l
print m
:view n