Returning a datatype.
For instance, let’s say that I had made a datatype:
data Something = Something Int [Char]
And, then I did some manipulation with the following function (the exact function of which is irrelevant):
manipulativeFunc::Something->[Something]
I keep getting these strange error messages that
Top level:
No instance for (Show (Int -> IO ()))
arising from use of 'print' at Top level
Probable fix: add an instance declaration for (Show (Int -> IO ()))
In a 'do' expression: print it
Note that I don’t have any uses of print anywhere in my program, nor do I have any uses of IO. The data declaration and the manipulativeFunc are all I have on it.
What could I be doing wrong?
EDIT: From commenters, I get the message that I may need to declare a Show instance for this task. So, what if I had
data Something = Something Int Int
Then how would I write a Show instance function for it?
In order to use the function
print, the compiler needs to be able to convert a value into aString, which is ensured by theShowclass. You try to display a function, and there is noShowinstance defined for it.In order to be able to display your
Something, usemanipulativeFunccan’t be displayed that way, but its result if you call it with an argument.