From 43cf6820189d6e0ec47207ef0fdc61cfa9812e6c Mon Sep 17 00:00:00 2001 From: Justin Timmons Date: Fri, 24 Mar 2017 19:31:56 -0400 Subject: [PATCH] Added Read implementation for Matrix datatype. Made Show symmetric with it. --- Data/Matrix.hs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/Data/Matrix.hs b/Data/Matrix.hs index 64aacd3..03b45f8 100644 --- a/Data/Matrix.hs +++ b/Data/Matrix.hs @@ -144,7 +144,13 @@ prettyMatrix m = concat instance Show a => Show (Matrix a) where - show = prettyMatrix + show = show . toLists + +instance Read a => Read (Matrix a) where + readsPrec _ str = map toMatrix parsedLists + where + parsedLists = reads str + toMatrix (lists, str) = (fromLists lists, str) instance NFData a => NFData (Matrix a) where rnf = rnf . mvect