<html>
<head>
<style><!--
.hmmessage P
{
margin:0px;
padding:0px
}
body.hmmessage
{
font-size: 10pt;
font-family:Tahoma
}
--></style>
</head>
<body class='hmmessage'><div dir='ltr'>
<style><!--
.hmmessage P
{
margin:0px;
padding:0px
}
body.hmmessage
{
font-size: 10pt;
font-family:Tahoma
}
--></style>
<div dir="ltr">Yes, thank you. Here's my simple fix:<div><br></div><div>newtype Point = Point Int<br>instance Show Point where</div><div> show (Point a) = [chr $ a + 48]</div><div><br>data Vector = Vector [Point]<br>instance Show Vector where<br> show (Vector ys) =<br> let show' [z] = show z<br> show' (x:xs) = show x ++ ", " ++ show' xs<br> show' [] = []<br> in "(" ++ show' ys ++ ")"</div><div><br></div><div>And I added this function: </div><div><br></div><div><div>createPoint :: Int -> Point</div><div>createPoint x = Point x</div><div><br></div><div>When I loaded the file containing all this into ghci and executed 'Vector $ map createPoint [1..5]' the result was '(1, 2, 3, 4, 5)' (without the quotes).</div><div>This was actually more or less a test question as I'm new to haskell-cafe, but I hope people who will read this message will learn from my mistake.</div><div><br></div><div>Thank you.</div><br><div>> From: aslatter@gmail.com<br>> Date: Mon, 28 Nov 2011 16:20:54 -0600<br>> Subject: Re: [Haskell-cafe] (no subject)<br>> To: dubl-u@hotmail.com<br>> CC: haskell-cafe@haskell.org<br>> <br>> On Mon, Nov 28, 2011 at 4:12 PM, Willem Obbens <dubl-u@hotmail.com> wrote:<br>> > Hello,<br>> > I get this error when I try to derive an instance of the Show typeclass:<br>> > Abc.hs:21:60:<br>> > Couldn't match expected type `Vector' with actual type `[Point]'<br>> > In the first argument of `show'', namely `xs'<br>> > In the second argument of `(++)', namely `show' xs'<br>> > In the second argument of `(++)', namely `", " ++ show' xs'<br>> > Failed, modules loaded: none.<br>> > Here's the faulty code:<br>> > newtype Point = Point Int<br>> > instance Show Point where<br>> > show (Point a) = [chr $ a + 48]<br>> ><br>> > data Vector = Vector [Point]<br>> > instance Show Vector where<br>> > show (Vector ys) =<br>> > let show' (Vector [z]) = show z<br>> > show' (Vector (x:xs)) = show x ++ ", " ++ show' xs<br>> > show' (Vector []) = []<br>> > in "(" ++ show' ys ++ ")"<br>> <br>> Here you're treating the value 'ys' as if its type was 'Vector', but<br>> its type is '[Point]'.<br>> <br>> Does that help?<br>> <br>> Antoine<br></div></div></div>
                                           </div></body>
</html>