I have this code:
module Coleccion where
data Pila a= Pil [a] deriving (Show,Eq,Ord)
data Cola a= Col [a] deriving (Show,Eq,Ord)
class Coleccion n where
esVacia::n->Bool
insertar::n->a->n
primero::n->a
eliminar:: n->n
size::n->Int;
instance Coleccion (Pila a) where
esVacia (Pil [])= True
esVacia (Pil _ )= False
primero (Pil x) = last x
eliminar (Pil x)= (Pil (init x))
size (Pil []) = 0
size (Pil pila) = length pila;
And when I compile it with GHCI I have:
• Couldn't match expected type ‘a1’ with actual type ‘a’
‘a’ is a rigid type variable bound by
the instance declaration at Coleccion.hs:18:12-29
‘a1’ is a rigid type variable bound by
the type signature for:
primero :: forall a1. Pila a -> a1
at Coleccion.hs:21:5-11
• In the expression: last x
In an equation for ‘primero’: primero (Pil x) = last x
In the instance declaration for ‘Coleccion (Pila a)’
• Relevant bindings include
x :: [a] (bound at Coleccion.hs:21:18)
primero :: Pila a -> a1 (bound at Coleccion.hs:21:5)
The functions that I have a problem with them are functions that have a type distinct from n or predefined types (Bool, Integer...) like, for example, primero. For example, esVacia, size & eliminar are working OK. I don't know what is wrong in declarations or in instance code. Thank you.