[Haskell-cafe] Defining show for a function type.
sabel at ki.informatik.uni-frankfurt.de
Mon Jul 10 12:06:10 EDT 2006
you can make every function being an instance of class Show,
this works for me:
instance Show (a -> b) where
show _ = "FUNCTION"
data Element = Int Int | Float Float | Func (Machine -> Machine)
Johan Grönqvist wrote:
> I am a haskell-beginner and I wish to write a Forth-like interpreter.
> (Only for practice, no usefulness.)
> I would like use a list (as stack) that can contain several kinds of
> 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? I just want to define something like
> show (Func _) = "Function, cannot show"
> and I am not interested in actually displaying any information about
> the function, but I am interested in getting information about
> elements of other kinds.
> So far I have just guessed, but failed to produce anything that does
> not give an error stating that my function is not of the form (T a b
> c) where T is not an alias and a b c are simple type variables (or so).
> Any help appreciated!
> Haskell-Cafe mailing list
> Haskell-Cafe at haskell.org
More information about the Haskell-Cafe