{-# OPTIONS_GHC -fno-warn-unrecognised-pragmas #-}
module Darcs.Patch.Effect ( Effect(..) ) where

import Darcs.Prelude

import Darcs.Patch.FromPrim ( PrimOf )

import Darcs.Patch.Witnesses.Ordered
    ( FL(..), RL(..), reverseRL
    , concatFL, mapFL_FL
    )


-- | Patches whose concrete effect can be expressed as a list of
--   primitive patches.
--
--   A minimal definition would be either of @effect@ or @effectRL@.
class Effect p where
    effect :: p wX wY -> FL (PrimOf p) wX wY

instance Effect p => Effect (FL p) where
    effect :: FL p wX wY -> FL (PrimOf (FL p)) wX wY
effect = FL (FL (PrimOf p)) wX wY -> FL (PrimOf p) wX wY
forall (a :: * -> * -> *) wX wZ. FL (FL a) wX wZ -> FL a wX wZ
concatFL (FL (FL (PrimOf p)) wX wY -> FL (PrimOf p) wX wY)
-> (FL p wX wY -> FL (FL (PrimOf p)) wX wY)
-> FL p wX wY
-> FL (PrimOf p) wX wY
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (forall wW wY. p wW wY -> FL (PrimOf p) wW wY)
-> FL p wX wY -> FL (FL (PrimOf p)) wX wY
forall (a :: * -> * -> *) (b :: * -> * -> *) wX wZ.
(forall wW wY. a wW wY -> b wW wY) -> FL a wX wZ -> FL b wX wZ
mapFL_FL forall wW wY. p wW wY -> FL (PrimOf p) wW wY
forall (p :: * -> * -> *) wX wY.
Effect p =>
p wX wY -> FL (PrimOf p) wX wY
effect

instance Effect p => Effect (RL p) where
    effect :: RL p wX wY -> FL (PrimOf (RL p)) wX wY
effect = FL p wX wY -> FL (PrimOf p) wX wY
forall (p :: * -> * -> *) wX wY.
Effect p =>
p wX wY -> FL (PrimOf p) wX wY
effect (FL p wX wY -> FL (PrimOf p) wX wY)
-> (RL p wX wY -> FL p wX wY) -> RL p wX wY -> FL (PrimOf p) wX wY
forall b c a. (b -> c) -> (a -> b) -> a -> c
. RL p wX wY -> FL p wX wY
forall (a :: * -> * -> *) wX wZ. RL a wX wZ -> FL a wX wZ
reverseRL