I am trying to define instance Show[MyType] so <br>show (x:xs :: MyType) would return a single string where substrings corresponding to list elements will be separated by &quot;\n&quot;.<br>This would allow pretty printing of MyType list in several lines instead of one, as default Show does for lists.<br>
<br>For example:<br><br>data ShipInfo = Ship {<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; name :: String,<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; kind :: String,<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; canons :: Int<br>} deriving Show<br><br>s1 = Ship {name =&quot;HMS Fly&quot;, kind = &quot;sloop&quot;, canons=16} <br>
s2 = Ship {name =&quot;HMS Surprise&quot;, kind = &quot;frigate&quot;, canons=42} <br><br>-- Yet when I try to define:<br>instance (Show ShipInfo) =&gt; Show [ShipInfo] where<br>&nbsp;&nbsp;&nbsp; show (x:xs) = &quot;&lt;&quot; ++ show x ++ &quot;&gt;&quot; ++ show xs<br>
<br>-- I get this error:<br>&nbsp;&nbsp;&nbsp; Illegal instance declaration for `Show [ShipInfo]&#39;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; (The instance type must be of form (T a b c)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; where T is not a synonym, and a,b,c are distinct type variables)<br>
&nbsp;&nbsp;&nbsp; In the instance declaration for `Show [ShipInfo]&#39;<br>Failed, modules loaded: none.<br><br>-- On the other hand this definition:<br>instance (Show a) =&gt; Show [a] where<br>
&nbsp;&nbsp;&nbsp; show (x:xs) = &quot;&lt;&quot; ++ show x ++ &quot;&gt;&quot; ++ show xs<br>
<br>-- Gives a different error:<br>
&nbsp;&nbsp;&nbsp; Duplicate instance declarations:<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; instance (Show a) =&gt; Show [a]<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; -- Defined at C:/wks/haskell-wks/ShowMatrix.hs:37:0<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; instance (Show a) =&gt; Show [a] -- Defined in GHC.Show<br>
Failed, modules loaded: none.<br>
<br>-- Note the last error implicitly tells us that defining Show [a] is possible in principle!<br>-- In fact it already defined in GHC.Show !!!<br><br>--&nbsp; How to define Show [MyType] ?<br>
<br>Thanks!<br>Dmitri<br>