Commit | Line | Data |
---|---|---|
7f918cf1 CE |
1 | (* Copyright (C) 1999-2006 Henry Cejtin, Matthew Fluet, Suresh |
2 | * Jagannathan, and Stephen Weeks. | |
3 | * | |
4 | * MLton is released under a BSD-style license. | |
5 | * See the file MLton-LICENSE for details. | |
6 | *) | |
7 | (*-------------------------------------------------------------------*) | |
8 | (* ListQueue *) | |
9 | (*-------------------------------------------------------------------*) | |
10 | ||
11 | functor ListQueue(): BASIC_PERSISTENT_QUEUE = | |
12 | struct | |
13 | ||
14 | structure L = List | |
15 | ||
16 | datatype 'a t = T of 'a List.t | |
17 | ||
18 | fun destruct(T l) = | |
19 | case L.destruct l of | |
20 | NONE => NONE | |
21 | | SOME(x, l) => SOME(x, T l) | |
22 | ||
23 | fun empty () = T(L.empty()) | |
24 | ||
25 | fun isEmpty(T l) = L.isEmpty l | |
26 | ||
27 | fun enque(T l, x) = T(L.append(l, L.single x)) | |
28 | ||
29 | end | |
30 | ||
31 | structure ListQueue = PersistentQueue(ListQueue()) |