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
showList :: [Cola a] -> ShowS
$cshowList :: forall a. Show a => [Cola a] -> ShowS
show :: Cola a -> String
$cshow :: forall a. Show a => Cola a -> String
showsPrec :: Int -> Cola a -> ShowS
$cshowsPrec :: forall a. Show a => Int -> 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
/= :: Cola a -> Cola a -> Bool
$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
Eq)
vacia :: Cola a
vacia :: Cola a
vacia = [a] -> Cola a
forall a. [a] -> Cola a
C []
inserta :: a -> Cola a -> Cola a
inserta :: 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 :: 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 :: 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 :: Cola a -> Bool
esVacia (C [a]
xs) = [a] -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null [a]
xs
valida :: Cola a -> Bool
valida :: Cola a -> Bool
valida Cola a
_ = Bool
True