Safe Haskell | Safe |
---|
MatrixUntrusted
Description
This untrusted module supplements the small matrices module with functions for describing boards as strings and lists of strings.
Documentation
class Cell a where
Typeclass for matrix cells: provides a function for converting a cell to a character.
Instances
matrixToStr :: Cell a => Int -> Int -> Matrix a -> String
raises an exception if matrixToStr
ht wid rows
is valid
ht
wid rowsFalse
. Otherwise it converts rows
into a string
that describes it, using toChar
(from typeclass Cell
) to
convert each cell of the matrix to a character, and indexing the
rows and columns by lowercase letters (a
, b
, c
, ...).
E.g., if
instanceCell
Bool
wheretoChar
True
= '1'toChar
False
= '0'
then
matrixToStr
2 3 [[true, false, true], [false, true, true]]
produces a string that prints as
| a | b | c | --+---+---+---| a | 1 | 0 | 1 | --+---+---+---| b | 0 | 1 | 1 | --+---+---+---|
matrixToStrs :: Cell a => Int -> Int -> Matrix a -> [String]
Like matrixToStr
except divides the resulting string into lines
(not including trailing newlines).