readで([ [String] ] -> [ [Int] ])の変換

StringIntに変換するやり方を教えてもらって、分かったのでメモしとく。

{-
--間違った書き方
test_1 :: [[String] -> [[Int]]
test_1 = map (\x -> map (\y -> read y :: Int)) [["123", "12"], ["234", "324"]]
-}

test0, test4 :: [[Int]]
test1, test2, test3 :: [[String]] -> [[Int]]
test0, test1P, test2P, test3P, test4P :: IO ()

test0 = map (\x -> map (\y -> read y :: Int) x) [["123", "12"], ["234", "324"]]
test0P = print test0

test1, test2, test3 :: [[String]] -> [[Int]]
test1P, test2P, test3P, test4P :: IO ()

test1 = map (map (\x -> read x :: Int))
test1P = print (test1 [["123", "12"], ["234", "324"]])

test2 = map (map (\x -> read x ))
test2P = print (test2 [["123", "12"], ["234", "324"]])

test3 = map $ map read
test3P = print $ test3 [["123", "12"], ["234", "324"]]

test4 = (map $ map read) [["123", "12"], ["234", "324"]]
test4P = print test4

冗長に書くとtest0のようになる。面白い書き方がtest4の書き方で、ちゃんと使えそうなのがtest1の書き方か。