Import Upstream version 20180207
[hcoop/debian/mlton.git] / basis-library / libs / basis-1997 / arrays-and-vectors / mono-vector-array-array2-convert.fun
CommitLineData
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
9functor MonoVectorArrayArray2Convert
10 (structure Vector: MONO_VECTOR
11 structure VectorSlice: MONO_VECTOR_SLICE
12 structure Array: MONO_ARRAY
13 structure ArraySlice: MONO_ARRAY_SLICE
14 structure Array2: MONO_ARRAY2
15 sharing type Vector.elem = VectorSlice.elem =
16 Array.elem = ArraySlice.elem =
17 Array2.elem
18 sharing type Vector.vector = VectorSlice.vector =
19 Array.vector = ArraySlice.vector =
20 Array2.vector
21 sharing type VectorSlice.slice = ArraySlice.vector_slice
22 sharing type Array.array = ArraySlice.array) :
23 sig
24 structure Vector: MONO_VECTOR_1997
25 structure Array: MONO_ARRAY_1997
26 structure Array2: MONO_ARRAY2_1997
27 sharing type Vector.elem = Array.elem = Array2.elem
28 sharing type Vector.vector = Array.Vector.vector = Array2.Vector.vector
29 end =
30 struct
31 fun shift1 f (_, s, _) = fn (i:int, x) => f (i + s, x)
32 fun shift2 f (_, s, _) = fn (i:int, x, y) => f (i + s, x, y)
33
34 structure V =
35 struct
36 open Vector
37 fun extract sl = VectorSlice.vector (VectorSlice.slice sl)
38 fun mapi f sl = VectorSlice.mapi (shift1 f sl) (VectorSlice.slice sl)
39 fun appi f sl = VectorSlice.appi (shift1 f sl) (VectorSlice.slice sl)
40 fun foldli f b sl = VectorSlice.foldli (shift2 f sl) b (VectorSlice.slice sl)
41 fun foldri f b sl = VectorSlice.foldri (shift2 f sl) b (VectorSlice.slice sl)
42 end
43 structure A =
44 struct
45 open Array
46 structure Vector = V
47 fun appi f sl = ArraySlice.appi (shift1 f sl) (ArraySlice.slice sl)
48 fun copy {src, si, len, dst, di} =
49 ArraySlice.copy {src = ArraySlice.slice (src, si, len),
50 dst = dst, di = di}
51 fun copyVec {src, si, len, dst, di} =
52 ArraySlice.copyVec {src = VectorSlice.slice (src, si, len),
53 dst = dst, di = di}
54 fun extract sl = ArraySlice.vector (ArraySlice.slice sl)
55 fun foldli f b sl = ArraySlice.foldli (shift2 f sl) b (ArraySlice.slice sl)
56 fun foldri f b sl = ArraySlice.foldri (shift2 f sl) b (ArraySlice.slice sl)
57 fun modifyi f sl = ArraySlice.modifyi (shift1 f sl) (ArraySlice.slice sl)
58 end
59 structure A2 =
60 struct
61 open Array2
62 structure Vector = V
63 end
64 structure Array = A
65 structure Vector = V
66 structure Array2 = A2
67 end