Module

Matrix

#Matrix

newtype Matrix a

A two-dimensional Matrix. Its Show instance is meant as a tool for debugging/pretty-printing.

Instances

#height

height :: forall a. Matrix a -> Int

Returns the height of a matrix.

#width

width :: forall a. Matrix a -> Int

Returns the width of a matrix.

#repeat

repeat :: forall a. Int -> Int -> a -> Matrix a

Repeats the same value and creates a width × height Matrix.

> repeat 2 3 "X"
"X", "X"
"X", "X"
"X", "X"

#fromArray

fromArray :: forall a. Array (Array a) -> Maybe (Matrix a)

Constructs a Matrix from an Array of Arrays. Returns Nothing if the dimensions don't line up.

> fromMaybe empty (fromArray [[1,2,3], [4,5,6]])
1, 2, 3
4, 5, 6

> fromArray [[1,2,3], [4,5]]
Nothing

#get

get :: forall a. Int -> Int -> Matrix a -> Maybe a

Returns the value at column, row or Nothing if the index was out of bounds.

#getRow

getRow :: forall a. Int -> Matrix a -> Maybe (Array a)

Get the row at the given index.

#getColumn

getColumn :: forall a. Int -> Matrix a -> Maybe (Array a)

Get the column at the given index.

#rows

rows :: forall a. Matrix a -> Array (Array a)

Get all the rows in the matrix

#columns

columns :: forall a. Matrix a -> Array (Array a)

Get all the columns in the matrix

#prettyPrintMatrix

prettyPrintMatrix :: forall a. (a -> String) -> Matrix a -> String

Pretty prints a matrix using the given formatting function on every element

#empty

empty :: forall a. Matrix a

The empty Matrix.

#isEmpty

isEmpty :: forall a. Matrix a -> Boolean

Checks whether a Matrix is empty

#set

set :: forall a. Int -> Int -> a -> Matrix a -> Maybe (Matrix a)

Sets the value at column, row or returns Nothing if the index was out of bounds.

#modify

modify :: forall a. Int -> Int -> (a -> a) -> Matrix a -> Maybe (Matrix a)

Applies the given function to the element at column, row or returns Nothing if the index was out of bounds.

#toIndexedArray

toIndexedArray :: forall a. Matrix a -> Array { value :: a, x :: Int, y :: Int }

Convert a Matrix to an indexed Array

#indexedMap

indexedMap :: forall a b. (Int -> Int -> a -> b) -> Matrix a -> Matrix b

Apply a function to every element in the given Matrix taking its indices into account

#zipWith

zipWith :: forall a b c. (a -> b -> c) -> Matrix a -> Matrix b -> Maybe (Matrix c)

Combines two Matrices with the same dimensions by combining elements at the same index with the given function. Returns Nothing on a dimension mismatch.

Modules