1
使用show
打印由列表列表給出的矩陣行時遇到了一些麻煩。在Haskell中使用顯示列表列表
我有這樣的:
data Matrix = Mat Int [[Bit]]
deriving Eq
當參數Int
是平方矩陣的順序和Bit
是一個Int(0或1)。我需要我的代碼才能夠做到以下幾點,以Matrix
爲Show
一個實例:
Main> Mat 3 [[0,0,1],[1,0,1],[1,1,1]
[0,0,1]
[1,0,1]
[0,0,1]
到目前爲止,我只有:
instance Show Matrix where
show (Mat i (x:xs)) = (show x) ++ "\n"
但這顯然只是返回第一個列表。你能幫我解決這個問題嗎? 在此先感謝。