i'm playing a little with Haskell and i'm stuck with this error, using the snd function with a tuple (String, list).
snd ("Felix Felices",[("Escarabajos Machacados",52,[f1,f2]),("Ojo de Tigre Sucio",2,[f2])])
ERROR - Cannot find "show" function for:
*** Expression : snd ("Felix Felices",[("Escarabajos Machacados",52,[f1,f2]),("Ojo de Tigre Sucio",2,[f2])])
*** Of type : [([Char],Integer,[(Integer,Integer,Integer) -> (Integer,Integer,Integer)])]
The thing is, if i remove f1, f2 and f3 (they are functions) the code works just fine, it returns the list. Why is this happening, why can't i just put a function inside the tuple's second position?
You can put functions into tuples. But you can't display them - ghci wants to show the result and print it. How should it show (convert to string) the functions? It can't, or at least nobody felt like choosing one way of doing it (which would propably be flawed anyway - at least I can't think of any approach that doesn't have holes to huge even I can see them). Therefore, you can't evaluate something that returns functions or collections of functions in ghci.
The problem isn't really the functions f1 f2 or f3, the problem is that you are trying to print these functions, but functions don't have an instance of Show, so they cannot be printed. However if you try:
Prelude> snd ("Felix Felices",[("Escarabajos Machacados",52,["f1","f2"]),("Ojo de Tigre Sucio",2,["f2"])])
you get the result:
[("Escarabajos Machacados",52,["f1","f2"]),("Ojo de Tigre Sucio",2,["f2"])]
So the problem isn't that you cannot have a function in a tuple, the problem is that you cannot convert functions to strings so they can be printed.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With