{-
    This file is part of AEx.
    Copyright (C) 2016 Jeffrey Sharp
    
    AEx is free software: you can redistribute it and/or modify it
    under the terms of the GNU General Public License as published
    by the Free Software Foundation, either version 3 of the License,
    or (at your option) any later version.
    
    AEx is distributed in the hope that it will be useful, but
    WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
    the GNU General Public License for more details.
    
    You should have received a copy of the GNU General Public License
    along with AEx.  If not, see <http://www.gnu.org/licenses/>.
-}

{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE FlexibleInstances     #-}

-- | Accumulating Types
module Aex.Util.Accum where

import Data.Monoid

import qualified Data.Sequence as S

class Empty t where
    empty :: t

class Accum a t where
    (+>) :: t -> a -> t
    infixl 5 +>

-- Would be nice but causes undecidable instances
--instance Monoid m => Empty m where
--    empty = mempty
--instance Monoid m => Accum m m where
--    (+>) = (<>)

instance Empty (S.Seq a) where
    empty = S.empty

instance Accum a (S.Seq a) where
    (+>) = (S.|>)

