module I1M.Pila
(Pila,
vacia,
apila,
cima,
desapila,
esVacia
) where
data Pila a = Vacia
| P a (Pila a)
deriving Pila a -> Pila a -> Bool
(Pila a -> Pila a -> Bool)
-> (Pila a -> Pila a -> Bool) -> Eq (Pila a)
forall a. Eq a => Pila a -> Pila a -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: forall a. Eq a => Pila a -> Pila a -> Bool
== :: Pila a -> Pila a -> Bool
$c/= :: forall a. Eq a => Pila a -> Pila a -> Bool
/= :: Pila a -> Pila a -> Bool
Eq
instance (Show a) => Show (Pila a) where
showsPrec :: Int -> Pila a -> ShowS
showsPrec Int
_ Pila a
Vacia String
cad = Char -> ShowS
showChar Char
'-' String
cad
showsPrec Int
_ (P a
x Pila a
s) String
cad = a -> ShowS
forall a. Show a => a -> ShowS
shows a
x (Char -> ShowS
showChar Char
'|' (Pila a -> ShowS
forall a. Show a => a -> ShowS
shows Pila a
s String
cad))
vacia :: Pila a
vacia :: forall a. Pila a
vacia = Pila a
forall a. Pila a
Vacia
apila :: a -> Pila a -> Pila a
apila :: forall a. a -> Pila a -> Pila a
apila = a -> Pila a -> Pila a
forall a. a -> Pila a -> Pila a
P
cima :: Pila a -> a
cima :: forall a. Pila a -> a
cima Pila a
Vacia = String -> a
forall a. HasCallStack => String -> a
error String
"la pila vacia no tiene cima"
cima (P a
x Pila a
_) = a
x
desapila :: Pila a -> Pila a
desapila :: forall a. Pila a -> Pila a
desapila Pila a
Vacia = String -> Pila a
forall a. HasCallStack => String -> a
error String
"no se puede desapila la pila vacia"
desapila (P a
_ Pila a
p) = Pila a
p
esVacia :: Pila a -> Bool
esVacia :: forall a. Pila a -> Bool
esVacia Pila a
Vacia = Bool
True
esVacia Pila a
_ = Bool
False