module I1M.Cola
(Cola,
vacia,
inserta,
primero,
resto,
esVacia,
valida
) where
newtype Cola a = C [a]
deriving (Int -> Cola a -> ShowS
[Cola a] -> ShowS
Cola a -> String
(Int -> Cola a -> ShowS)
-> (Cola a -> String) -> ([Cola a] -> ShowS) -> Show (Cola a)
forall a. Show a => Int -> Cola a -> ShowS
forall a. Show a => [Cola a] -> ShowS
forall a. Show a => Cola a -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: forall a. Show a => Int -> Cola a -> ShowS
showsPrec :: Int -> Cola a -> ShowS
$cshow :: forall a. Show a => Cola a -> String
show :: Cola a -> String
$cshowList :: forall a. Show a => [Cola a] -> ShowS
showList :: [Cola a] -> ShowS
Show, Cola a -> Cola a -> Bool
(Cola a -> Cola a -> Bool)
-> (Cola a -> Cola a -> Bool) -> Eq (Cola a)
forall a. Eq a => Cola a -> Cola a -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: forall a. Eq a => Cola a -> Cola a -> Bool
== :: Cola a -> Cola a -> Bool
$c/= :: forall a. Eq a => Cola a -> Cola a -> Bool
/= :: Cola a -> Cola a -> Bool
Eq)
vacia :: Cola a
vacia :: forall a. Cola a
vacia = [a] -> Cola a
forall a. [a] -> Cola a
C []
inserta :: a -> Cola a -> Cola a
inserta :: forall a. a -> Cola a -> Cola a
inserta a
x (C [a]
c) = [a] -> Cola a
forall a. [a] -> Cola a
C ([a]
c [a] -> [a] -> [a]
forall a. [a] -> [a] -> [a]
++ [a
x])
primero :: Cola a -> a
primero :: forall a. Cola a -> a
primero (C (a
x:[a]
_)) = a
x
primero (C []) = String -> a
forall a. HasCallStack => String -> a
error String
"primero: cola vacia"
resto :: Cola a -> Cola a
resto :: forall a. Cola a -> Cola a
resto (C (a
_:[a]
xs)) = [a] -> Cola a
forall a. [a] -> Cola a
C [a]
xs
resto (C []) = String -> Cola a
forall a. HasCallStack => String -> a
error String
"resto: cola vacia"
esVacia :: Cola a -> Bool
esVacia :: forall a. Cola a -> Bool
esVacia (C [a]
xs) = [a] -> Bool
forall a. [a] -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null [a]
xs
valida :: Cola a -> Bool
valida :: forall a. Cola a -> Bool
valida Cola a
_ = Bool
True