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 :: DList a -> [a] toList (DList [a] -> [a] f) = [a] -> [a] f [] singleton :: a -> DList a singleton :: a -> DList a singleton a x = ([a] -> [a]) -> DList a forall a. ([a] -> [a]) -> DList a DList (a x a -> [a] -> [a] forall a. a -> [a] -> [a] :) instance Semigroup (DList a) where DList [a] -> [a] f <> :: DList a -> DList a -> DList a <> DList [a] -> [a] g = ([a] -> [a]) -> DList a forall a. ([a] -> [a]) -> DList a DList ([a] -> [a] f ([a] -> [a]) -> ([a] -> [a]) -> [a] -> [a] forall b c a. (b -> c) -> (a -> b) -> a -> c . [a] -> [a] g) instance Monoid (DList a) where mempty :: DList a mempty = ([a] -> [a]) -> DList a forall a. ([a] -> [a]) -> DList a DList [a] -> [a] forall a. a -> a id