{Record
empty
new
is_empty
push
pop
pop_all
append
concat
}
Where
Let (concat queues)
(LIST.reduce queues empty append)
Where
Define (pop_all queue)
Match (pop queue)
| `nothing []
| `just.{item queue} (item :: (pop_all queue))
;
Let (push_all queue items)
(LIST.reduce items queue push)
Define (append queue queue')
Match (pop queue')
| `nothing queue
| `just.{item queue'} (append (push queue item) queue')
;
Where
Let (push queue item)
{Record incoming:(item :: queue.incoming) outgoing:queue.outgoing}
Define (pop queue)
Match queue.outgoing
| `cons.{item outgoing}
Let queue
{Record incoming:queue.incoming outgoing}
In
`just.{item queue}
| `nil
Match queue.incoming
| `nil `nothing
| _ (pop (new (LIST.reverse queue.incoming)))
;
;
Where
Let (new init)
{Record incoming:[] outgoing:init}
Let empty {Record incoming:[] outgoing:[]}
Let (is_empty queue)
Match queue.incoming
| `nil Match queue.outgoing | `nil True | `cons._ False ;
| `cons._ False
;
Where
Let LIST Package "list"