## 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 = {
| |||||||||||||||||||||||||||||||||||||||||||||||

module type vspace_2d = {
| |||||||||||||||||||||||||||||||||||||||||||||||

module type scalar = {
| |||||||||||||||||||||||||||||||||||||||||||||||

module mk_vspace_2d | : | (real: scalar) -> vspace_2d with real = real.t | |||||||||||||||||||||||||||||||||||||||||||||

module type vspace_3d = {
| |||||||||||||||||||||||||||||||||||||||||||||||

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
Neutral element for the addition.

- ↑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
Add vectors elementwise.

- ↑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.

- ↑val quadrance: vector -> real
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.

- ↑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.- ↑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.