## Abstract

A module type for standard Euclidean vectors.

Vectors of arbitrary dimension can be constructed with `mk_vspace` by passing in a `vector` and a `real` module, although for most uses the `mk_vspace_2d` and `mk_vspace_3d` modules are simpler and sufficient.

## Synopsis

module type vspace = {
 type real type vector val zero : vector val one : real val map : (real -> real) -> vector -> vector val map2 : (real -> real -> real) -> vector -> vector -> vector val + : vector -> vector -> vector val - : vector -> vector -> vector val * : vector -> vector -> vector val / : vector -> vector -> vector val dot : vector -> vector -> real val quadrance : vector -> real val scale : real -> vector -> vector val norm : vector -> real val normalise : vector -> vector
}
module type vspace_2d = {
 type real include vspace with real = real with vector = {x: real, y: real}
}
module type scalar = {
 type t val + : t -> t -> t val - : t -> t -> t val * : t -> t -> t val / : t -> t -> t val i32 : i32 -> t val sqrt : t -> t
}
module mk_vspace_2d: (real: scalar) -> vspace_2d with real = real.t
module type vspace_3d = {
 type real include vspace with real = real with vector = {x: real, y: real, z: real} val cross : vector -> vector -> vector val rot_x : (radians: real) -> vector -> vector val rot_y : (radians: real) -> vector -> vector val rot_z : (radians: real) -> vector -> vector
}
module mk_vspace_3d: (real: real) -> vspace_3d with real = real.t
module mk_vspace: (V: vector) -> (real: real) -> vspace with real = real.t with vector = V.vector real.t

## Description

module type vspace
type real
type vector

A vector type. Semantically a sequence of `real`s.

val zero: vector

val one: real

Neutral element for the multiplication by a scalar.

val map: (real -> real) -> vector -> vector

Apply an operation to each element of the vector.

val map2: (real -> real -> real) -> vector -> vector -> vector

Apply a binary operation to corresponding components of two vectors.

val +: vector -> vector -> vector

val -: vector -> vector -> vector

Subtract vectors elementwise.

val *: vector -> vector -> vector

Multiply vectors elementwise.

val /: vector -> vector -> vector

Divide vectors elementwise.

val dot: vector -> vector -> real

Inner product.

Squared norm.

val scale: real -> vector -> vector
val norm: vector -> real
val normalise: vector -> vector

Transform to unit vectortor.

module type vspace_2d

A two-dimensional vector space is just a vector space, but we give the vectors a convenient record type.

type real
include vspace with real = real with vector = {x: real, y: real}
module type scalar

The operations that must be supported by the scalars contained in a vector. The builtin modules `f32` and `f64` satisfy this interface.

type t
val +: t -> t -> t
val -: t -> t -> t
val *: t -> t -> t
val /: t -> t -> t
val i32: i32 -> t
val sqrt: t -> t
module mk_vspace_2d

Construct a 2D vector space.

module type vspace_3d

A three-dimensional vector space is just a vector space, but we give the vectors a convenient record type. Also, cross product is defined.

type real
include vspace with real = real with vector = {x: real, y: real, z: real}
val cross: vector -> vector -> vector

Cross product.

val rot_x: (radians: real) -> vector -> vector

Rotate vector around the x axis. This leaves the x axis unchanged.

val rot_y: (radians: real) -> vector -> vector

Rotate vector around the y axis. This leaves the y axis unchanged.

val rot_z: (radians: real) -> vector -> vector

Rotate vector around the z axis. This leaves the z axis unchanged.

module mk_vspace_3d

Construct a 3D vector space.

module mk_vspace

Construct an arbitrary-dimensional vector space. The dimensionality is given by the vector representation that is provided.