{-# LANGUAGE CPP #-}
module Agda.TypeChecking.DropArgs where
import Control.Arrow (first, second)
import Agda.Syntax.Common
import Agda.Syntax.Internal
import Agda.TypeChecking.Monad.Base
import Agda.TypeChecking.Substitute
import Agda.TypeChecking.CompiledClause
import Agda.TypeChecking.Coverage.SplitTree
import Agda.Utils.Functor
import Agda.Utils.Permutation
#include "undefined.h"
import Agda.Utils.Impossible
class DropArgs a where
dropArgs :: Int -> a -> a
instance DropArgs a => DropArgs (Maybe a) where
dropArgs n = fmap (dropArgs n)
instance DropArgs Telescope where
dropArgs n tel = telFromList $ drop n $ telToList tel
instance DropArgs Permutation where
dropArgs n (Perm m p) = Perm (m - n) $ map (subtract n) $ drop n p
instance DropArgs Clause where
dropArgs n cl =
cl{
namedClausePats = drop n $ namedClausePats cl
}
instance DropArgs FunctionInverse where
dropArgs n finv = fmap (dropArgs n) finv
instance DropArgs Term where
dropArgs 0 v = v
dropArgs n v = case v of
Lam h b -> dropArgs (n - 1) (absBody b)
_ -> __IMPOSSIBLE__
instance DropArgs CompiledClauses where
dropArgs n cc = case cc of
Case i br | unArg i < n -> __IMPOSSIBLE__
| otherwise -> Case (i <&> \ j -> j - n) $ fmap (dropArgs n) br
Done xs t | length xs < n -> __IMPOSSIBLE__
| otherwise -> Done (drop n xs) t
Fail -> Fail
instance DropArgs SplitTree where
dropArgs n (SplittingDone m) = SplittingDone (m - n)
dropArgs n (SplitAt i ts) = SplitAt (subtract n <$> i) $ map (second $ dropArgs n) ts