module Ring ( Ring, Elt, newRing, current, deleteCurrent, rotate, size) where ---------------------------------------- -- Interface ---------------------------------------- newRing :: [Elt] -> Ring current :: Ring -> Elt deleteCurrent :: Ring -> Ring -- after deleting, new current is the -- element following the deleted elt rotate :: Ring -> Int -> Ring size :: Ring -> Int ---------------------------------------- -- Implementation ---------------------------------------- ---------------------- -- type implementation ---------------------- type Elt = Int type Ring = [Elt] -------------------------- -- Function implementation -------------------------- newRing elts = elts current (first:_) = first deleteCurrent (_:rest) = rest rotate elts amount = newFront++newRear where modAmount = amount `mod` ringSize ringSize = length elts newFront = drop modAmount elts newRear = take modAmount elts size elts = length elts