dim :: [[a]] -> (Int, Int) dim ls = let x = length ls ys = map length ls in case ys of h:t -> if all (==h) t then (x, h) else (0, 0) [] -> (0, 0) main = do print $ dim [[1, 1], [1, 1]] print $ dim [[1, 1], [2, 2, 2]]