module DifferenceLists (DL, show, fromList, toList, append, empty, cons) where
-- Differenzlisten in Haskell

newtype DL a = DL {unDL :: [a] -> [a]}

instance Show a => Show (DL a)  where 
 show dl = "Differenzliste"

fromList :: [a] -> DL a
fromList xs = DL (xs ++)

toList :: DL a -> [a]
toList (DL xs) = xs []

append :: DL a -> DL a -> DL a
append (DL xs) (DL ys) = DL (xs . ys)

empty :: DL a 
empty = DL id

cons :: a -> DL a -> DL a
cons x (DL xs) = DL ((x:). xs)
infixr `cons` 