[Haskell-cafe] How to define Show [MyType] ?

Dmitri O.Kondratiev dokondr at gmail.com
Fri Dec 5 18:13:31 EST 2008


On Fri, Dec 5, 2008 at 1:29 AM, Martijn van Steenbergen <
martijn at van.steenbergen.nl> wrote:

> Dmitri O.Kondratiev wrote:
>
>> --  How to define Show [MyType] ?
>>
>
> Define instance Show MyType and implement not only show (for 1 value of
> MyType) but also showList, which Show provides as well. You can do all the
> magic in there.
>
> HTH,
>
> Martijn.
>
>
Thanks everybody for your help!
I tried to implement showList, but get the same error:

{--
-- from Prelude:
type *ShowS* = String<file:///C:/usr/ghc-6.6.1/doc/html/libraries/base/Prelude.html#t%3AString>->
String<file:///C:/usr/ghc-6.6.1/doc/html/libraries/base/Prelude.html#t%3AString>
*showList* :: [a] ->
ShowS<file:///C:/usr/ghc-6.6.1/doc/html/libraries/base/Prelude.html#t%3AShowS>
--}

myShows::ShowS
myShows s = s ++ "\n"

data ShipInfo = Ship {
      name :: String,
      kind :: String,
      canons :: Int
} deriving Show

-- I get this error again:
instance (Show [ShipInfo]) where
    showList [] = myShows []
    showList (x:xs)  = myShows "x" ++ showList xs

    Illegal instance declaration for `Show [ShipInfo]'
        (The instance type must be of form (T a b c)
         where T is not a synonym, and a,b,c are distinct type variables)
    In the instance declaration for `Show [ShipInfo]'
Failed, modules loaded: none.

-- What am I doing wrong?
Thanks!
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20081206/c95e1f75/attachment-0001.htm


More information about the Haskell-Cafe mailing list