Commit | Line | Data |
---|---|---|
7f918cf1 CE |
1 | (* Copyright (C) 2002-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 | ||
9 | functor VectorArrayConvert | |
10 | (structure Vector: VECTOR | |
11 | structure VectorSlice: VECTOR_SLICE | |
12 | where type 'a slice = 'a VectorSlice.slice | |
13 | structure Array: ARRAY | |
14 | structure ArraySlice: ARRAY_SLICE | |
15 | where type 'a slice = 'a ArraySlice.slice) : | |
16 | sig | |
17 | structure Vector: VECTOR_1997 | |
18 | structure Array: ARRAY_1997 | |
19 | end = | |
20 | struct | |
21 | fun shift1 f (_, s, _) = fn (i:int, x) => f (i + s, x) | |
22 | fun shift2 f (_, s, _) = fn (i:int, x, y) => f (i + s, x, y) | |
23 | ||
24 | structure V = | |
25 | struct | |
26 | open Vector | |
27 | fun extract sl = VectorSlice.vector (VectorSlice.slice sl) | |
28 | fun mapi f sl = VectorSlice.mapi (shift1 f sl) (VectorSlice.slice sl) | |
29 | fun appi f sl = VectorSlice.appi (shift1 f sl) (VectorSlice.slice sl) | |
30 | fun foldli f b sl = VectorSlice.foldli (shift2 f sl) b (VectorSlice.slice sl) | |
31 | fun foldri f b sl = VectorSlice.foldri (shift2 f sl) b (VectorSlice.slice sl) | |
32 | end | |
33 | structure A = | |
34 | struct | |
35 | open Array | |
36 | fun appi f sl = ArraySlice.appi (shift1 f sl) (ArraySlice.slice sl) | |
37 | fun copy {src, si, len, dst, di} = | |
38 | ArraySlice.copy {src = ArraySlice.slice (src, si, len), | |
39 | dst = dst, di = di} | |
40 | fun copyVec {src, si, len, dst, di} = | |
41 | ArraySlice.copyVec {src = VectorSlice.slice (src, si, len), | |
42 | dst = dst, di = di} | |
43 | fun extract sl = ArraySlice.vector (ArraySlice.slice sl) | |
44 | fun foldli f b sl = ArraySlice.foldli (shift2 f sl) b (ArraySlice.slice sl) | |
45 | fun foldri f b sl = ArraySlice.foldri (shift2 f sl) b (ArraySlice.slice sl) | |
46 | fun modifyi f sl = ArraySlice.modifyi (shift1 f sl) (ArraySlice.slice sl) | |
47 | end | |
48 | structure Vector = V | |
49 | structure Array = A | |
50 | end |