Copyright | (c) Evgeny Poberezkin |
---|---|
License | MIT |
Maintainer | evgeny@poberezkin.com |
Stability | experimental |
Portability | non-portable |
Safe Haskell | None |
Language | Haskell2010 |
This package provides "orphan" IsList
instances for Array
s
with Integral
indices up to 5 dimensions to allow initializing
Array
s from [nested] lists using OverloadedLists
GHC extension.
It also includes more generic arrayNestedList
and toNestedList
functions to convert between nested lists and Array
s with any indices.
Examples:
>>>
["one","two","three"] :: Array Int String
array (0,2) [(0,"one"),(1,"two"),(2,"three")]
>>>
[[0,1,2], [10,11,12]] :: Array (Int, Int) Int
array ((0,0),(1,2)) [((0,0),0),((0,1),1),((0,2),2),((1,0),10),((1,1),11),((1,2),12)]
If any of the nested lists contains smaller number of elements than the first nested list in the same dimension, the array creation will fail.
>>>
[[1,2],[3]] :: Array (Int, Int) Int
... Exception: (Array.!): undefined array element
Nested lists with larger number of elements will be truncated.
Synopsis
- class IsList l
- fromList :: IsList l => [Item l] -> l
- toList :: IsList l => l -> [Item l]
- class Ix i => ArrayNestedList i e
- arrayNestedList :: ArrayNestedList i e => (i, i) -> NestedList i e -> Array i e
- toNestedList :: ArrayNestedList i e => Array i e -> NestedList i e
IsList
The IsList
class and its methods are intended to be used in
conjunction with the OverloadedLists extension.
Since: base-4.7.0.0
Instances
fromList :: IsList l => [Item l] -> l #
The fromList
function constructs the structure l
from the given
list of Item l
toList :: IsList l => l -> [Item l] #
The toList
function extracts a list of Item l
from the structure l
.
It should satisfy fromList . toList = id.
ArrayNestedList
class Ix i => ArrayNestedList i e Source #
ArrayNestedList
class defines methods to convert between
nested lists and multi-dimensional (up to 5) Array
s with any indices,
not only Integral
, using provided range of indices.
Instances
(Ix i, Ix j) => ArrayNestedList (i, j) e Source # | |
Defined in Data.Array.IsList type NestedList (i, j) e :: Type arrayNestedList :: ((i, j), (i, j)) -> NestedList (i, j) e -> Array (i, j) e Source # toNestedList :: Array (i, j) e -> NestedList (i, j) e Source # | |
(Ix i, Ix j, Ix k) => ArrayNestedList (i, j, k) e Source # | |
Defined in Data.Array.IsList type NestedList (i, j, k) e :: Type arrayNestedList :: ((i, j, k), (i, j, k)) -> NestedList (i, j, k) e -> Array (i, j, k) e Source # toNestedList :: Array (i, j, k) e -> NestedList (i, j, k) e Source # | |
(Ix i, Ix j, Ix k, Ix m) => ArrayNestedList (i, j, k, m) e Source # | |
Defined in Data.Array.IsList type NestedList (i, j, k, m) e :: Type arrayNestedList :: ((i, j, k, m), (i, j, k, m)) -> NestedList (i, j, k, m) e -> Array (i, j, k, m) e Source # toNestedList :: Array (i, j, k, m) e -> NestedList (i, j, k, m) e Source # | |
(Ix i, Ix j, Ix k, Ix m, Ix n) => ArrayNestedList (i, j, k, m, n) e Source # | |
Defined in Data.Array.IsList type NestedList (i, j, k, m, n) e :: Type arrayNestedList :: ((i, j, k, m, n), (i, j, k, m, n)) -> NestedList (i, j, k, m, n) e -> Array (i, j, k, m, n) e Source # toNestedList :: Array (i, j, k, m, n) e -> NestedList (i, j, k, m, n) e Source # |
arrayNestedList :: ArrayNestedList i e => (i, i) -> NestedList i e -> Array i e Source #
Converts nested list to multi-dimensional Array
Similarly to arrayList
function, it does not require to pass index
for each element, only the range of indices.
toNestedList :: ArrayNestedList i e => Array i e -> NestedList i e Source #
Converts multi-dimensional Array
to nested list.
Orphan instances
IsList (Array Int e) Source # | |
IsList (Array Int8 e) Source # | |
IsList (Array Int16 e) Source # | |
IsList (Array Int32 e) Source # | |
IsList (Array Int64 e) Source # | |
IsList (Array Integer e) Source # | |
IsList (Array Natural e) Source # | |
IsList (Array Word e) Source # | |
IsList (Array Word8 e) Source # | |
IsList (Array Word16 e) Source # | |
IsList (Array Word32 e) Source # | |
IsList (Array Word64 e) Source # | |
(Integral i, Integral j, Ix i, Ix j) => IsList (Array (i, j) e) Source # | |
(Integral i, Integral j, Integral k, Ix i, Ix j, Ix k) => IsList (Array (i, j, k) e) Source # | |
(Integral i, Integral j, Integral k, Integral m, Ix i, Ix j, Ix k, Ix m) => IsList (Array (i, j, k, m) e) Source # | |
(Integral i, Integral j, Integral k, Integral m, Integral n, Ix i, Ix j, Ix k, Ix m, Ix n) => IsList (Array (i, j, k, m, n) e) Source # | |