Haskell: Mostrar derivación para tipo personalizado


Tengo esta definición de tipo:

data Operace = Op (Int->Int->Int) String (Int->Int->Int) deriving Show

Quiero imprimir este tipo en el shell interactivo (GHCi). Todo lo que se debe imprimir es el campo String.

He intentado esto:

instance Show Operace where
    show (Op op str inv) = show str

Pero todavía sigo recibiendo

No instance for (Show (Int -> Int -> Int))
  arising from the 'deriving' clause of a data type declaration
Possible fix:
  add an instance declaration for (Show (Int -> Int -> Int))
  or use a standalone 'deriving instance' declaration,
       so you can specify the instance context yourself
When deriving the instance for (Show Operace)

No quiero agregar Show para (Int->Int->Int), todo lo que quiero imprimir es la cadena.

Gracias por la ayuda!

EDITAR:

Para referencia futura, la versión fija es:

data Operace = Op (Int->Int->Int) String (Int->Int->Int)

instance Show Operace where
    show (Op op str inv) = str
Author: Jan Tojnar, 2011-05-21

2 answers

La declaración de instancia que hizo es el camino correcto a seguir. Parece que olvidó eliminar esa cláusula deriving defectuosa de la declaración data original.

data Operace = Op (Int->Int->Int) String (Int->Int->Int)

instance Show Operace where
   show (Op op str inv) = show str
 21
Author: hugomg,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2011-05-21 13:43:44

Puedes derivar Show, solo importa Text.Show.Functions primero.

 20
Author: Thomas M. DuBuisson,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2011-05-21 14:22:30