module DList where import Data.Function ((.), id) import Data.Monoid (Monoid (mempty)) import Data.Semigroup (Semigroup ((<>))) newtype DList a = DList ([a] -> [a]) toList :: DList a -> [a] toList :: forall a. DList a -> [a] toList (DList [a] -> [a] f) = [a] -> [a] f [] singleton :: a -> DList a singleton :: forall a. a -> DList a singleton a x = forall a. ([a] -> [a]) -> DList a DList (a x forall a. a -> [a] -> [a] :) instance Semigroup (DList a) where DList [a] -> [a] f <> :: DList a -> DList a -> DList a <> DList [a] -> [a] g = forall a. ([a] -> [a]) -> DList a DList ([a] -> [a] f forall b c a. (b -> c) -> (a -> b) -> a -> c . [a] -> [a] g) instance Monoid (DList a) where mempty :: DList a mempty = forall a. ([a] -> [a]) -> DList a DList forall a. a -> a id