module Agda.TypeChecking.LevelConstraints ( simplifyLevelConstraint ) where
import Data.List
import Agda.Syntax.Common (Nat)
import Agda.Syntax.Internal
import Agda.TypeChecking.Monad.Base
import Agda.TypeChecking.Substitute
import Agda.Utils.Size
simplifyLevelConstraint :: Int -> Constraint -> Constraints -> Constraint
simplifyLevelConstraint n new old =
case inequalities new of
[a :=< b] | elem (b' :=< a') leqs -> LevelCmp CmpEq (Max [a]) (Max [b])
where (a', b') = raise (waterLevel n) (a, b)
_ -> new
where
unClosure c = (size (envContext $ clEnv cl), clValue cl)
where cl = theConstraint c
(ns, ls) = unzip $ map unClosure old
waterLevel :: Nat
waterLevel = maximum (n:ns)
leqs = concatMap inequalities $ zipWith raise (map (waterLevel ) ns) ls
data Leq = PlusLevel :=< PlusLevel
deriving (Show, Eq)
inequalities (LevelCmp CmpEq (Max [a, b]) (Max [c]))
| a == c = [b :=< a]
| b == c = [a :=< b]
inequalities (LevelCmp CmpEq (Max [a]) (Max [b, c]))
| a == b = [c :=< b]
| a == c = [b :=< c]
inequalities _ = []