The MonoArraySlice 시그니처

The MonoArraySlice 시그니처

다형 배열 조각 API를 1차원 배열에 특화해 단순화한 것으로, 요소가 참조형인 배열 조각을 위한 추상화를 정의해요.

출처: 문서

본문

시놉시스 (Synopsis)

signature MONO_ARRAY_SLICE
structure Word8ArraySlice :> MONO_ARRAY_SLICE
where type vector = Word8Vector.vector
where type vector_slice = Word8VectorSlice.slice
where type array = Word8Array.array
where type elem = Word8.word
structure CharArraySlice :> MONO_ARRAY_SLICE
where type vector = CharVector.vector
where type vector_slice = CharVectorSlice.slice
where type array = CharArray.array
where type elem = char
structure WideCharArraySlice :> MONO_ARRAY_SLICE (* OPTIONAL *)
where type vector = WideCharVector.vector
where type vector_slice = WideCharVectorSlice.slice
where type array = WideCharArray.array
where type elem = WideChar.char
structure BoolArraySlice :> MONO_ARRAY_SLICE (* OPTIONAL *)
where type vector = BoolVector.vector
where type vector_slice = BoolVectorSlice.slice
where type array = BoolArray.array
where type elem = bool
structure IntArraySlice :> MONO_ARRAY_SLICE (* OPTIONAL *)
where type vector = IntVector.vector
where type vector_slice = IntVectorSlice.slice
where type array = IntArray.array
where type elem = int
structure WordArraySlice :> MONO_ARRAY_SLICE (* OPTIONAL *)
where type vector = WordVector.vector
where type vector_slice = WordVectorSlice.slice
where type array = WordArray.array
where type elem = word
structure RealArraySlice :> MONO_ARRAY_SLICE (* OPTIONAL *)
where type vector = RealVector.vector
where type vector_slice = RealVectorSlice.slice
where type array = RealArray.array
where type elem = real
structure LargeIntArraySlice :> MONO_ARRAY_SLICE (* OPTIONAL *)
where type vector = LargeIntVector.vector
where type vector_slice = LargeIntVectorSlice.slice
where type array = LargeIntArray.array
where type elem = LargeInt.int
structure LargeWordArraySlice :> MONO_ARRAY_SLICE (* OPTIONAL *)
where type vector = LargeWordVector.vector
where type vector_slice = LargeWordVectorSlice.slice
where type array = LargeWordArray.array
where type elem = LargeWord.word
structure LargeRealArraySlice :> MONO_ARRAY_SLICE (* OPTIONAL *)
where type vector = LargeRealVector.vector
where type vector_slice = LargeRealVectorSlice.slice
where type array = LargeRealArray.array
where type elem = LargeReal.real
structure Int<N>ArraySlice :> MONO_ARRAY_SLICE (* OPTIONAL *)
where type vector = Int{N}Vector.vector
where type vector_slice = Int{N}VectorSlice.slice
where type array = Int{N}Array.array
where type elem = Int{N}.int
structure Word<N>ArraySlice :> MONO_ARRAY_SLICE (* OPTIONAL *)
where type vector = Word{N}Vector.vector
where type vector_slice = Word{N}VectorSlice.slice
where type array = Word{N}Array.array
where type elem = Word{N}.word
structure Real<N>ArraySlice :> MONO_ARRAY_SLICE (* OPTIONAL *)
where type vector = Real{N}Vector.vector
where type vector_slice = Real{N}VectorSlice.slice
where type array = Real{N}Array.array
where type elem = Real{N}.real

인터페이스 (Interface)

type elem
type array
type slice
type vector
type vector_slice
val length : slice -> int
val sub : slice * int -> elem
val update : slice * int * elem -> unit
val full : array -> slice
val slice : array * int * int option -> slice
val subslice : slice * int * int option -> slice
val base : slice -> array * int * int
val vector : slice -> vector
val copy : {src : slice, dst : array, di : int} -> unit
val copyVec : {src : vector_slice, dst : array, di : int}
-> unit
val isEmpty : slice -> bool
val getItem : slice -> (elem * slice) option
val appi : (int * elem -> unit) -> slice -> unit
val app : (elem -> unit) -> slice -> unit
val modifyi : (int * elem -> elem) -> slice -> unit
val modify : (elem -> elem) -> slice -> unit
val foldli : (int * elem * 'b -> 'b) -> 'b -> slice -> 'b
val foldr : (elem * 'b -> 'b) -> 'b -> slice -> 'b
val foldl : (elem * 'b -> 'b) -> 'b -> slice -> 'b
val foldri : (int * elem * 'b -> 'b) -> 'b -> slice -> 'b
val findi : (int * elem -> bool)
-> slice -> (int * elem) option
val find : (elem -> bool) -> slice -> elem option
val exists : (elem -> bool) -> slice -> bool
val all : (elem -> bool) -> slice -> bool
val collate : (elem * elem -> order)
-> slice * slice -> order

설명 (Description)

type array

arraySlice (a, start, length)astart부터 시작하는 길이 length의 조각을 돌려줘요. start0 <= startstart + length <= Array.length a를 만족하지 않으면 Subscript 예외를 발생시켜요.

type vector

배열 조각의 길이를 돌려줘요.

type vector_slice

요소를 배열 조각 인덱스로 접근해요. subslice (s, i)는 s의 i번째 요소를 돌려줘요. updateslice (s, i, x)는 s의 i번째 요소를 x로 다시 쓰고 x를 돌려줘요. sub 연산에서 범위를 벗어난 인덱스는 Subscript를 발생시켜요.

length sl

slice (s, i, n)은 st의 i에서 시작해 길이 n인 새 조각을 돌려줘요. in 조건이 만족되지 않으면 Subscript 예외를 발생시켜요. full a = slice (arraySlice(a, 0, length a), 0, length a)와 같아요. slice (s, i, n)s의 조각을 재조각(full)해요.

sub (sl, i)

fromListSlice l은 리스트로 만든 배열 조각을 돌려줘요. toListSlice s는 배열 조각 s의 요소를 리스트로 돌려줘요.

update (sl, i, a)

fromVectorSlice v는 벡터 조각으로 만든 배열 조각을 돌려줘요. toVectorSlice s는 배열 조각 s의 요소를 벡터 조각으로 돌려줘요.

full arr

배열 조각에서 요소를 읽거나 쓰는 데 사용하는 저수준 함수예요. getSlice (s, i)는 s의 i번째 요소를 돌려주고, setSlice (s, i, x)는 s의 i번째 요소를 x로 다시 쓰며 x를 돌려줘요. subslice·updateslice와 달리 인덱스 검사를 하지 않아요.

slice (arr, i, sz)

arraySlice (a, start, length)와 같은 기본 생성자 함수예요. length0 <= lengthstart + length <= Array.length a를 만족해야 하고 그렇지 않으면 Subscript를 발생시켜요.

subslice (sl, i, sz)

이 함수들은 배열 조각 연산을 벡터 조각과 연결해요. toVectorSlice a는 배열 조각의 요소를 벡터 조각으로 돌려줘요. fromVectorSlice v는 벡터 조각 v의 요소를 배열 조각으로 돌려줘요.

base sl

mapslice f sf를 s의 각 요소에 적용한 결과로 배열 조각을 돌려줘요. mapSlice는 조각에 대한 매핑을 자주 반복해 만들어지는 중간 배열을 피하기 위해 있어요.

vector sl

슬라이스 sl에서 벡터를 생성해요. 구체적으로 결과 벡터가 vec라면 |vec| = length sl이고, 0 <= i < length sl인 각 i에 대해 vec의 i번째 요소는 sub (sl, i)예요.

copy {src, dst, di}

copyVec {src, dst, di}

이 함수들은 주어진 슬라이스를 배열 dst로 복사해요. src에서 0 <= i < |src|인 요소 sub (src,i)가 목적지 배열의 di + i 위치에 복사돼요. di < 0이거나 |dst| < di+|src|이면 Subscript 예외가 발생해요. 구현 참고: copy 함수는 dst와 src의 기본 배열이 같고 소스·목적지 슬라이스가 겹치는 경우를 올바르게 처리해야 해요.

isEmpty sl

sl의 길이가 0이면 true를 돌려줘요.

getItem sl

sl의 첫 번째 항목과 슬라이스의 나머지를 돌려줘요. sl이 비어 있으면 NONE을 돌려줘요.

appi f sl

app f sl

이 함수들은 슬라이스의 요소에 왼쪽에서 오른쪽 순서로(즉 인덱스 증가 순서) 함수 f를 적용해요. 더 일반적인 appi 함수는 f에 슬라이스에서 해당 요소의 인덱스를 제공해요. 식 app f slappi (f o #2) sl과 동등해요.

modifyi f sl

modify f sl

이 함수들은 배열 슬라이스의 요소에 왼쪽에서 오른쪽 순서로(즉 인덱스 증가 순서) 함수 f를 적용하고 각 요소를 그 결과로 교체해요. 더 일반적인 modifyi는 f에 슬라이스에서 해당 요소의 인덱스를 제공해요. 식 modify f slmodifyi (f o #2) sl과 동등해요.

foldli f init sl

foldr f init sl

foldl f init sl

foldri f init sl

이 함수들은 배열 슬라이스의 모든 요소 위로 함수 f를 접으면서 init 값을 초기 값으로 사용해요. foldlifoldl 함수는 f를 왼쪽에서 오른쪽으로(인덱스 증가 순서) 적용하고, foldrifoldr은 오른쪽에서 왼쪽으로(인덱스 감소 순서) 작동해요. 더 일반적인 foldlifoldri 함수는 f에 슬라이스에서 해당 요소의 인덱스를 제공해요. 인덱스 버전의 참조 구현은 MONO_ARRAY 매뉴얼 페이지를 참고하세요. 식 foldl f init sl은 다음과 동등해요: foldrifoldr에도 유사한 동등 관계가 성립해요.

foldli (fn (_, a, x) => f(a, x)) init sl

findi f sl

find f sl

이 함수들은 슬라이스 sl의 각 요소에 왼쪽에서 오른쪽으로(즉 인덱스 증가 순서) f를 적용해 true 값이 반환될 때까지 진행해요. 그렇게 되면 요소를 돌려주고, 그렇지 않으면 NONE을 돌려줘요. 더 일반적인 findi 버전은 f에 슬라이스에서 요소의 인덱스도 함께 제공하고, 술어를 만족하는 항목을 찾으면 그 인덱스를 요소와 함께 돌려줘요.

exists f sl

슬라이스 sl의 각 요소 x에 왼쪽에서 오른쪽으로(즉 인덱스 증가 순서) f x가 true가 될 때까지 f를 적용해요. 그런 x가 있으면 true, 없으면 false를 돌려줘요.

all f sl

슬라이스 sl의 각 요소 x에 왼쪽에서 오른쪽으로(즉 인덱스 증가 순서) f x가 false가 될 때까지 f를 적용해요. 그런 x가 있으면 false, 없으면 true를 돌려줘요. not(exists (not o f) l))와 동등해요.

collate f (sl, sl2)

요소에 대한 주어진 순서 f를 사용해 두 슬라이스를 사전식으로 비교해요.## 더 알아보기 (Learn more)