{-# LANGUAGE TemplateHaskell #-}
module AST.Infer.ScopeLevel
( ScopeLevel(..), _ScopeLevel
, MonadScopeLevel(..)
) where
import Algebra.PartialOrd (PartialOrd(..))
import AST.Unify.Constraints (TypeConstraints(..))
import Control.DeepSeq (NFData)
import Data.Binary (Binary)
import Control.Lens (makePrisms)
import GHC.Generics (Generic)
import qualified Text.PrettyPrint as Pretty
import Text.PrettyPrint.HughesPJClass (Pretty(..))
import Prelude.Compat
newtype ScopeLevel = ScopeLevel Int
deriving stock (Eq, Ord, Show, Generic)
makePrisms ''ScopeLevel
instance PartialOrd ScopeLevel where
{-# INLINE leq #-}
ScopeLevel x `leq` ScopeLevel y = x >= y
instance Semigroup ScopeLevel where
{-# INLINE (<>) #-}
ScopeLevel x <> ScopeLevel y = ScopeLevel (min x y)
instance Monoid ScopeLevel where
{-# INLINE mempty #-}
mempty = ScopeLevel maxBound
instance TypeConstraints ScopeLevel where
{-# INLINE generalizeConstraints #-}
generalizeConstraints _ = mempty
toScopeConstraints = id
instance Pretty ScopeLevel where
pPrint (ScopeLevel x) = Pretty.text "scope#" <> pPrint x
instance NFData ScopeLevel
instance Binary ScopeLevel
class Monad m => MonadScopeLevel m where
localLevel :: m a -> m a