Implementing a show for multi-line content in Haskell

I have a small matrix type in Haskell that maps most accurately across multiple lines. My current implementation of format show

formats looks like this:

matFromRows [[1,2]
            ,[3,4]]

      

This works on its own (IE to view matrix content in ghci

), but whenever the matrix is ​​displayed as part of a larger structure it generates very awkwardly formatted and hard to read content. For example, a tuple (matFromRows [[1, 2], [3, 4]], matFromRows [[5, 6], [7, 8]])

would display as

(matFromRows [[1,2]
            ,[3,4]],matFromRows [[5,6]
            ,[7,8]]

      

What's the nicest way to handle show

inline multi-line content in Haskell so that its formatting isn't destroyed when you display it as part of a larger structure?

+3


source to share





All Articles