Johan Grönqvist wrote: > I would like use a list (as stack) that can contain several kinds of values. > > data Element = Int Int | Float Float | Func : Machine -> Machine | ... > > Now I would like to have this type be an instance of the class Show, so > that I can see what the stack contains in ghci. > > "deriving Show" is impossible as Func is not instance of Show. Can I > make it instance of Show?
Of course you can:
instance Show Element where
showsPrec p (Int i) = showsPrec p i
showsPrec p (Float f) = showsPrec p f
showsPrec _ (Func _) = ("<<function>>" ++)
...
Udo.
--
Alcohol is the anesthesia by which we endure the operation of life.
-- George Bernard Shaw
signature.asc
Description: Digital signature
_______________________________________________ Haskell-Cafe mailing list [email protected] http://www.haskell.org/mailman/listinfo/haskell-cafe
