Skip to content

Commit 99c42ed

Browse files
committed
adding fromListIO convenience function
1 parent df9b51c commit 99c42ed

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

Foreign/Matlab/Array.hsc

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ module Foreign.Matlab.Array (
3131
-- | array list access
3232
mxArrayGetList, mxArraySetList,
3333
mxArrayGetAll, mxArraySetAll,
34+
fromListIO,
3435

3536
-- * Struct access
3637
-- |Structs in Matlab are always arrays, and so can be accessed using most array accessors.
@@ -126,6 +127,13 @@ foreign import ccall unsafe mxDestroyArray :: MXArrayPtr -> IO ()
126127
freeMXArray :: MXArray a -> MIO ()
127128
freeMXArray a = withMXArray a mxDestroyArray
128129

130+
-- |Create and populate an MXArray in one go.
131+
fromListIO :: MXArrayComponent a => [a] -> MIO (MXArray a)
132+
fromListIO xs = do
133+
arr <- createMXArray [length xs]
134+
mxArraySetAll arr xs
135+
pure arr
136+
129137
-- |The class of standardly typeable array elements
130138
class MXArrayComponent a where
131139
-- |Determine whether the given array is of the correct type

0 commit comments

Comments
 (0)