Hi,
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)
deriving Show
David
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
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? 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!
Johan
_______________________________________________
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe
_______________________________________________
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe