Safe Haskell | Safe |
---|
Matrix
Description
This trusted module implements the small matrices that are used to represent game boards. Matrices are indexed by lowercase letters.
- type Matrix a = [[a]]
- valid :: Int -> Int -> Matrix a -> Bool
- const :: Int -> Int -> a -> Matrix a
- sub :: Int -> Int -> Matrix a -> Int -> Int -> a
- update :: Int -> Int -> Matrix a -> Int -> Int -> a -> Matrix a
- map :: (a -> b) -> Matrix a -> Matrix b
- mapM :: Monad m => (a -> m b) -> Matrix a -> m (Matrix b)
- mapPos :: (Int -> Int -> a -> b) -> Matrix a -> Matrix b
- transpose :: Int -> Int -> Matrix a -> Matrix a
Documentation
type Matrix a = [[a]]
A matrix is just a list of lists.
const :: Int -> Int -> a -> Matrix a
returns a list of const
ht wid xht
rows, each consisting
of a length-wid
list all of whose elements are x
; it raises
an exception if ht
and/or wid
are outside of the range 1
.. 26
.
map :: (a -> b) -> Matrix a -> Matrix b
transforms map
f rowsrows
by applying f
to each element
of each of its elements.
mapM :: Monad m => (a -> m b) -> Matrix a -> m (Matrix b)
Monadic version of map
: works through the rows from top to bottom,
and through each row's cells from left to right.