From 7b97c9c65dbbfe7d5105070aed38622985ab0f96 Mon Sep 17 00:00:00 2001 From: Rnhmjoj Date: Sun, 8 Mar 2015 01:34:41 +0100 Subject: [PATCH] Use applicative style --- Matrix.hs | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) 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