diff --git a/Matrix.hs b/Matrix.hs index dc66cd4..b4e7b88 100644 --- a/Matrix.hs +++ b/Matrix.hs @@ -1,4 +1,6 @@ module Matrix where + +import Control.Applicative import Data.List (intercalate) newtype Mat a = Mat [[a]] @@ -26,8 +28,9 @@ group n xs = take n xs : group n (drop n xs) -- | Create a matrix of indeces of a matrix indeces :: Mat a -> Mat Pos -indeces (Mat m) = Mat [[(x,y) | y <- [0..length (m !! x)-1]] | - x <- [0..length m-1]] +indeces (Mat m) = Mat (group y pos) where + (x, y) = (length m, length (m !! 0)) + pos = liftA2 (,) [0..x-1] [0..y-1] -- | Create a constant matrix constant :: a -> Int -> Int -> Mat a