VSL - The data.array_ref Structure
# Copyright 2011 Petter Urkedal
#
# This file is part of the Viz Standard Library <http://www.vizlang.org/>.
#
# The Viz Standard Library (VSL) is free software: you can redistribute it
# and/or modify it under the terms of the GNU Lesser General Public License as
# published by the Free Software Foundation, either version 3 of the License,
# or (at your option) any later version.
#
# The VSL is distributed in the hope that it will be useful, but WITHOUT ANY
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
# FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for
# more details.
#
# You should have received a copy of the GNU Lesser General Public License
# along with the VSL. If not, see <http://www.gnu.org/licenses/>.
open prelude.ubiquitous
open effect
#?ffoc {#
type r α
#?ffoc #}
val length : r α → int
val init : int → (int → α) → r α
val init_fold : int → (β → α × β) → β → r α × β
val uniform : int → α → ψ /~ r α
val get : int → r α → effect ψ α
val slice : int → int → r α → effect ψ (r α)
val set : int → α → r α → effect ψ unit
val copy : r α → effect ψ (r α)
val fill : int → int → α → r α → effect ψ (r α)
val blit : int → int → r α → int → r α → effect ψ (r α)
val map : (α → β) → r α → effect ψ (r β)
val mapi : (int → α → β) → r α → effect ψ (r β)
val fold : (α → β → β) → r α → β → effect ψ β
val foldr : (α → β → β) → r α → β → effect ψ β
val iter : (α → effect ψ unit) → r α → effect ψ unit
val iterr : (α → effect ψ unit) → r α → effect ψ unit
val afold : (α → β → effect ψ β) → r α → β → effect ψ β
val afoldr : (α → β → effect ψ β) → r α → β → effect ψ β
val cat : r α → r α → effect ψ (r α)
val cat_list : list (r α) → effect ψ (r α)
val sort : (α → α → order) → r α → effect ψ unit
val of_list : list α → effect ψ (r α)
val as_list : r α → effect ψ (list α)
val of_array : array.t α → effect ψ (r α)
val as_array : r α → effect ψ (array.t α)
val freeze : r α → effect ψ (array.t α)
#?ffoc include compat.ocaml_array.array_act
let uniform n x be init n (i ↦ x)
let fold f a
let n be length a
let! loop i accu
if i = n be accu
let x do get i a
do loop (i + 1) (f x accu)
be loop 0
let foldr f a
let! loop i accu
if i < 0 be accu
let x do get i a
do loop (i - 1) (f x accu)
be loop (length a)
let iter k a be fold (x +> m +> m >> k x) a (return ()) >>= ident
let iterr k a be foldr (x +> m +> m >> k x) a (return ()) >>= ident
let afold k a accu be fold (x +> m +> m >>= k x) a (return accu) >>= ident
let afoldr k a accu be foldr (x +> m +> m >>= k x) a (return accu) >>= ident