[Haskell-cafe] Re: Defining show for a function type.
max.vasin at gmail.com
Tue Jul 11 12:46:56 EDT 2006
>>>>> "Johan" == Johan Grönqvist <johan.gronqvist at gmail.com> writes:
Johan> I am a haskell-beginner and I wish to write a Forth-like
Johan> interpreter. (Only for practice, no usefulness.)
Johan> I would like use a list (as stack) that can contain several
Johan> kinds of values.
Johan> data Element = Int Int | Float Float | Func : Machine ->
Johan> Machine | ...
Johan> Now I would like to have this type be an instance of the class
Johan> Show, so that I can see what the stack contains in ghci.
Johan> "deriving Show" is impossible as Func is not instance of
Johan> Show. Can I make it instance of Show? I just want to define
Johan> something like
Johan> show (Func _) = "Function, cannot show"
err, why not just write
instance Show Element where
show (Func _) = "Function, cannot show"
data Foo = Bar | Foo (Int -> Int -> Int)
instance Show Foo where
show Bar = "Bar"
show (Foo _) = "Func!"
main = do putStrLn $ show Bar
putStrLn $ show $ Foo (+)
NP: Nothing playing right now
More information about the Haskell-Cafe