Haskell No Instance for Show

Here is my code

type Niveles = (Int, Int, Int)
type Persona = (String, Niveles)    
type Pocion = (String, [(String, Int, [Efectos])])
type Ingredientes = [(String, Int, [Efectos])]
type Efectos = Niveles -> Niveles

aplicar3 f (a,b,c) = (f a, f b, f c)

invertir3 (a,b,c) = (c,b,a)

fst3 (a,_,_) = a
snd3 (_,b,_) = b
trd3 (_,_,c) = c

personas = [("Harry",(11, 5, 4)), ("Ron",(6,4,6)), ("Hermione",(8,12,2)), ("Draco",(7,9,6))]

f1 (ns,nc,nf) = (ns+1,nc+2,nf+3)
f2 = aplicar3 (max 7)
f3 (ns,nc,nf)
    | ns >= 8 = (ns,nc,nf+5)
    | otherwise = (ns,nc,nf-3)

misPociones :: [Pocion]
misPociones = [
    ("Felix Felices",[("Escarabajos Machacados",52,[f1,f2]),("Ojo de Tigre Sucio",2,[f3])]),
    ("Multijugos",[("Cuerno de Bicornio en Polvo",10, [invertir3, (\(a,b,c) -> (a,a,c))]),("Sanguijuela hormonal",54,[(aplicar3 (*2)), (\(a,b,c) -> (a,a,c)) ])]),
    ("Flores de Bach",[("Orquidea Salvaje",8,[f3]), ("Rosita",1,[f1])])]


efectosDePocion pocion = map trd3 (elementos pocion)

elementos :: Pocion -> Ingredientes
elementos (_, ingredientes) = ingredientes

I have a problem in the last code snippet when I try to use the elementos function:

elementos ("Felix Felices",[("Escarabajos Machacados",52,[f1,f2]),("Ojo de Tigre Sucio",2,[f3])])

I got an error message:

<interactive>:311:1:
    No instance for (Show ((Int, Int, Int) -> (Int, Int, Int)))
      arising from a use of `print'
    Possible fix:
      add an instance declaration for
      (Show ((Int, Int, Int) -> (Int, Int, Int)))
    In a stmt of an interactive GHCi command: print it

Can someone explain this to me? How can i fix this?

+4
source share
2 answers

Add the following code to your .hs file

instance Show (a -> b) where
         show a= "funcion"

Now ghci will be able to print "funcion" (function)

Good luck

+3
source

In short, the function is evaluated correctly - the problem is caused in its assessment ghci.

Ingredientes, [(String, Int, [Efectos])]. ghci , show . Efectos . ghci , , , show: No instance for (Show ((Int, Int, Int) -> (Int, Int, Int))).

, - , ghci.

+11

Source: https://habr.com/ru/post/1539494/


All Articles