[Haskell-cafe] Printing list of enum type

michael rice nowgate at yahoo.com
Tue Apr 14 09:15:46 EDT 2009

What do I need to add to this Color enum type to print a list of them?



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
*Main> Black
*Main> [Red Black White]

    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]

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20090414/3d726dc9/attachment.htm

More information about the Haskell-Cafe mailing list