[Haskell-beginners] showing user defined data types
Dan Lior
sitiposit at gmail.com
Fri Apr 5 22:15:26 CEST 2013
Hello,
I defined a type Pixel :
data Pixel = Black | White deriving (Eq, Show)
and would like to "show" it as
show :: Pixel -> String
show Black = "#"
show White = "."
Apparently, ghc finds this ambiguous. That seems strange to me since Pixel is my own custom type and I don't imagine that ghc has another definition for showing it. Isn't this what "overloading" is supposed to enable?
I can get around the problem by :
import Prelude hiding(show)
but that seems to drastic since it hides all the various overloaded incarnations of "show". I only need it to hide one of them (the one for Pixel).
I'm obviously misunderstanding something.
Is there a simple way to define my own show function for my own user defined data type?
Thanks in advance.
dan
More information about the Beginners
mailing list