You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Data.Matrix.prettyMatrix produces a String that looks nice on its own, but it doesn't have some properties that a good Show instance should have.
Firstly, when embedded inside other Strings obtained from Show, the results can be very strange. In my code, I have some datatypes that contain matrices, and I am logging the results to a file after using a general pretty-printer (http://hackage.haskell.org/package/pretty-show-1.10/docs/Text-Show-Pretty.html). When the pretty printer encounters matrices, it gets completely confused because they do not look like normal Haskell expressions.
Secondly, derived instances of Show have the following property, according to the documentation: "The result of show is a syntactically correct Haskell expression containing only constants, given the fixity declarations in force at the point where the type is declared. It contains only the constructor names defined in the data type, parentheses, and spaces. When labelled constructor fields are used, braces, commas, field names, and equal signs are also used." Several datatypes try to mimic this property in their Show instances. For example, show applied to a Map gives something like fromList [(1,2), (3,4)].
I propose that the Show instance for a matrix should use toLists, so that, for example, show-ing the 2x2 identity matrix gives either
-- This is in the same spirit as Data.Map, and gives an expression
-- that can be copied and pasted into ghci to give a matrix
fromLists [[1,0],[0,1]]
or just
-- This is in the spirit of Data.Vector. It gives an expression that cannot
-- precisely be copied into ghci, but it does follow Haskell syntax and is
-- shorter/simpler than the above
[[1,0],[0,1]]
The text was updated successfully, but these errors were encountered:
Data.Matrix.prettyMatrix
produces a String that looks nice on its own, but it doesn't have some properties that a good Show instance should have.Firstly, when embedded inside other
String
s obtained fromShow
, the results can be very strange. In my code, I have some datatypes that contain matrices, and I am logging the results to a file after using a general pretty-printer (http://hackage.haskell.org/package/pretty-show-1.10/docs/Text-Show-Pretty.html). When the pretty printer encounters matrices, it gets completely confused because they do not look like normal Haskell expressions.Secondly, derived instances of
Show
have the following property, according to the documentation: "The result ofshow
is a syntactically correct Haskell expression containing only constants, given the fixity declarations in force at the point where the type is declared. It contains only the constructor names defined in the data type, parentheses, and spaces. When labelled constructor fields are used, braces, commas, field names, and equal signs are also used." Several datatypes try to mimic this property in their Show instances. For example,show
applied to aMap
gives something likefromList [(1,2), (3,4)]
.I propose that the
Show
instance for a matrix should usetoLists
, so that, for example,show
-ing the 2x2 identity matrix gives eitheror just
The text was updated successfully, but these errors were encountered: