On Mon, Nov 28, 2011 at 04:20:54PM -0600, Antoine Latter wrote: > On Mon, Nov 28, 2011 at 4:12 PM, Willem Obbens <dub...@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 ++ ")"
You've made show' :: Vector -> String, but I'm guessing you actually want to make it show' :: [Point] -> String; i.e. get rid of the Vector constructors in the show' patterns. -Brent _______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe