[Haskell-cafe] (no subject)
Antoine Latter
aslatter at gmail.com
Mon Nov 28 23:20:54 CET 2011
On Mon, Nov 28, 2011 at 4:12 PM, Willem Obbens <dubl-u at hotmail.com> wrote:
> Hello,
> I get this error when I try to derive an instance of the Show typeclass:
> Abc.hs:21:60:
> Couldn't match expected type `Vector' with actual type `[Point]'
> In the first argument of `show'', namely `xs'
> In the second argument of `(++)', namely `show' xs'
> In the second argument of `(++)', namely `", " ++ show' xs'
> Failed, modules loaded: none.
> Here's the faulty code:
> newtype Point = Point Int
> instance Show Point where
> show (Point a) = [chr $ a + 48]
>
> data Vector = Vector [Point]
> instance Show Vector where
> show (Vector ys) =
> let show' (Vector [z]) = show z
> show' (Vector (x:xs)) = show x ++ ", " ++ show' xs
> show' (Vector []) = []
> in "(" ++ show' ys ++ ")"
Here you're treating the value 'ys' as if its type was 'Vector', but
its type is '[Point]'.
Does that help?
Antoine
More information about the Haskell-Cafe
mailing list