Printing list of enum type

What do I need to add to this Color enum type to print a list of them? Michael =============== data Color = Red | Blue | Green | Yellow | Orange | Brown | White | Black instance Show Color where show Red = "Red" show Blue = "Blue" show Green = "Green" show Yellow = "Yellow" show Orange = "Orange" show Brown = "Brown" show White = "White" show Black = "Black" ====================== Ok, modules loaded: Main. *Main> Red Red *Main> Black Black *Main> [Red Black White] <interactive>:1:1: Couldn't match expected type `Color -> Color -> t' against inferred type `Color' In the expression: Red Black White In the expression: [Red Black White] In the definition of `it': it = [Red Black White]

1. data Color = Red | Green | Blue deriving (Show)
2. [Red,Black,White]
2009/4/14 michael rice
What do I need to add to this Color enum type to print a list of them?
Michael
===============
data Color = Red | Blue | Green | Yellow | Orange | Brown | White | Black
instance Show Color where show Red = "Red" show Blue = "Blue" show Green = "Green" show Yellow = "Yellow" show Orange = "Orange" show Brown = "Brown" show White = "White" show Black = "Black"
======================
Ok, modules loaded: Main. *Main> Red Red *Main> Black Black *Main> [Red Black White]
<interactive>:1:1: Couldn't match expected type `Color -> Color -> t' against inferred type `Color' In the expression: Red Black White In the expression: [Red Black White] In the definition of `it': it = [Red Black White]
_______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
-- Eugene Kirpichov Web IR developer, market.yandex.ru

You don't need to add anything, you just need to use list notation
correctly. Try typing [Red, Black, White] in at the prompt instead. The
commas are part of the list syntax.
On Tue, Apr 14, 2009 at 9:15 AM, michael rice
What do I need to add to this Color enum type to print a list of them?
Michael
===============
data Color = Red | Blue | Green | Yellow | Orange | Brown | White | Black
instance Show Color where show Red = "Red" show Blue = "Blue" show Green = "Green" show Yellow = "Yellow" show Orange = "Orange" show Brown = "Brown" show White = "White" show Black = "Black"
======================
Ok, modules loaded: Main. *Main> Red Red *Main> Black Black *Main> [Red Black White]
<interactive>:1:1: Couldn't match expected type `Color -> Color -> t' against inferred type `Color' In the expression: Red Black White In the expression: [Red Black White] In the definition of `it': it = [Red Black White]
_______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe

Michael,
What do I need to add to this Color enum type to print a list of them?
You can also easily print a list of /all/ of them. Regards, John scratch$ cat color.hs data Color = Red | Blue | Green | Yellow | Orange | Brown | White | Black deriving (Show,Enum,Bounded) scratch$ ghci color.hs *Main> [minBound..maxBound] :: [Color] [Red,Blue,Green,Yellow,Orange,Brown,White,Black]
participants (4)
-
Andrew Wagner
-
Eugene Kirpichov
-
John Dorsey
-
michael rice