{-# LANGUAGE CPP #-}

{-| Some common syntactic entities are defined in this module.
-}
module Agda.Syntax.Common
  ( module Agda.Syntax.Common
  , Induction(..)
  )
  where

import Prelude hiding (null)

import Control.DeepSeq
import Control.Arrow ((&&&))
import Control.Applicative ((<|>), liftA2)

#if __GLASGOW_HASKELL__ < 804
import Data.Semigroup hiding (Arg)
#endif
import Data.Bifunctor
import Data.ByteString.Char8 (ByteString)
import qualified Data.ByteString.Char8 as ByteString
import qualified Data.Foldable as Fold
import Data.Function (on)
import Data.Hashable (Hashable(..))
import qualified Data.Strict.Maybe as Strict
import Data.Word
import Data.IntSet (IntSet)
import qualified Data.IntSet as IntSet
import Data.HashSet (HashSet)
import qualified Data.HashSet as HashSet

import GHC.Generics (Generic)

import Agda.Syntax.Position

import Agda.Utils.BiMap (HasTag(..))
import Agda.Utils.Functor
import Agda.Utils.Lens
import Agda.Utils.List1  ( List1, pattern (:|), (<|) )
import qualified Agda.Utils.List1 as List1
import Agda.Utils.Maybe
import Agda.Utils.Null
import Agda.Utils.PartialOrd
import Agda.Utils.POMonoid
import Agda.Syntax.Common.Aspect (Induction(..))
import Agda.Syntax.Common.Pretty

import Agda.Utils.Impossible

type Nat    = Int
type Arity  = Nat

---------------------------------------------------------------------------
-- * File
---------------------------------------------------------------------------

data FileType = AgdaFileType | MdFileType | RstFileType | TexFileType | OrgFileType | TypstFileType
  deriving (FileType -> FileType -> Bool
(FileType -> FileType -> Bool)
-> (FileType -> FileType -> Bool) -> Eq FileType
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: FileType -> FileType -> Bool
== :: FileType -> FileType -> Bool
$c/= :: FileType -> FileType -> Bool
/= :: FileType -> FileType -> Bool
Eq, Eq FileType
Eq FileType =>
(FileType -> FileType -> Ordering)
-> (FileType -> FileType -> Bool)
-> (FileType -> FileType -> Bool)
-> (FileType -> FileType -> Bool)
-> (FileType -> FileType -> Bool)
-> (FileType -> FileType -> FileType)
-> (FileType -> FileType -> FileType)
-> Ord FileType
FileType -> FileType -> Bool
FileType -> FileType -> Ordering
FileType -> FileType -> FileType
forall a.
Eq a =>
(a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
$ccompare :: FileType -> FileType -> Ordering
compare :: FileType -> FileType -> Ordering
$c< :: FileType -> FileType -> Bool
< :: FileType -> FileType -> Bool
$c<= :: FileType -> FileType -> Bool
<= :: FileType -> FileType -> Bool
$c> :: FileType -> FileType -> Bool
> :: FileType -> FileType -> Bool
$c>= :: FileType -> FileType -> Bool
>= :: FileType -> FileType -> Bool
$cmax :: FileType -> FileType -> FileType
max :: FileType -> FileType -> FileType
$cmin :: FileType -> FileType -> FileType
min :: FileType -> FileType -> FileType
Ord, Int -> FileType -> ShowS
[FileType] -> ShowS
FileType -> ArgName
(Int -> FileType -> ShowS)
-> (FileType -> ArgName) -> ([FileType] -> ShowS) -> Show FileType
forall a.
(Int -> a -> ShowS) -> (a -> ArgName) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> FileType -> ShowS
showsPrec :: Int -> FileType -> ShowS
$cshow :: FileType -> ArgName
show :: FileType -> ArgName
$cshowList :: [FileType] -> ShowS
showList :: [FileType] -> ShowS
Show, (forall x. FileType -> Rep FileType x)
-> (forall x. Rep FileType x -> FileType) -> Generic FileType
forall x. Rep FileType x -> FileType
forall x. FileType -> Rep FileType x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cfrom :: forall x. FileType -> Rep FileType x
from :: forall x. FileType -> Rep FileType x
$cto :: forall x. Rep FileType x -> FileType
to :: forall x. Rep FileType x -> FileType
Generic)

instance Pretty FileType where
  pretty :: FileType -> Doc
pretty = \case
    FileType
AgdaFileType -> Doc
"Agda"
    FileType
MdFileType   -> Doc
"Markdown"
    FileType
RstFileType  -> Doc
"ReStructedText"
    FileType
TexFileType  -> Doc
"LaTeX"
    FileType
OrgFileType  -> Doc
"org-mode"
    FileType
TypstFileType -> Doc
"Typst"

instance NFData FileType

---------------------------------------------------------------------------
-- * Agda variants
---------------------------------------------------------------------------

-- | Variants of Cubical Agda.

data Cubical = CErased | CFull
    deriving (Cubical -> Cubical -> Bool
(Cubical -> Cubical -> Bool)
-> (Cubical -> Cubical -> Bool) -> Eq Cubical
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: Cubical -> Cubical -> Bool
== :: Cubical -> Cubical -> Bool
$c/= :: Cubical -> Cubical -> Bool
/= :: Cubical -> Cubical -> Bool
Eq, Int -> Cubical -> ShowS
[Cubical] -> ShowS
Cubical -> ArgName
(Int -> Cubical -> ShowS)
-> (Cubical -> ArgName) -> ([Cubical] -> ShowS) -> Show Cubical
forall a.
(Int -> a -> ShowS) -> (a -> ArgName) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> Cubical -> ShowS
showsPrec :: Int -> Cubical -> ShowS
$cshow :: Cubical -> ArgName
show :: Cubical -> ArgName
$cshowList :: [Cubical] -> ShowS
showList :: [Cubical] -> ShowS
Show, (forall x. Cubical -> Rep Cubical x)
-> (forall x. Rep Cubical x -> Cubical) -> Generic Cubical
forall x. Rep Cubical x -> Cubical
forall x. Cubical -> Rep Cubical x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cfrom :: forall x. Cubical -> Rep Cubical x
from :: forall x. Cubical -> Rep Cubical x
$cto :: forall x. Rep Cubical x -> Cubical
to :: forall x. Rep Cubical x -> Cubical
Generic)

instance NFData Cubical

-- | Agda variants.
--
-- Only some variants are tracked.

data Language
  = WithoutK
  | WithK
  | Cubical Cubical
    deriving (Language -> Language -> Bool
(Language -> Language -> Bool)
-> (Language -> Language -> Bool) -> Eq Language
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: Language -> Language -> Bool
== :: Language -> Language -> Bool
$c/= :: Language -> Language -> Bool
/= :: Language -> Language -> Bool
Eq, Int -> Language -> ShowS
[Language] -> ShowS
Language -> ArgName
(Int -> Language -> ShowS)
-> (Language -> ArgName) -> ([Language] -> ShowS) -> Show Language
forall a.
(Int -> a -> ShowS) -> (a -> ArgName) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> Language -> ShowS
showsPrec :: Int -> Language -> ShowS
$cshow :: Language -> ArgName
show :: Language -> ArgName
$cshowList :: [Language] -> ShowS
showList :: [Language] -> ShowS
Show, (forall x. Language -> Rep Language x)
-> (forall x. Rep Language x -> Language) -> Generic Language
forall x. Rep Language x -> Language
forall x. Language -> Rep Language x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cfrom :: forall x. Language -> Rep Language x
from :: forall x. Language -> Rep Language x
$cto :: forall x. Rep Language x -> Language
to :: forall x. Rep Language x -> Language
Generic)

instance KillRange Language where
  killRange :: KillRangeT Language
killRange = KillRangeT Language
forall a. a -> a
id

instance NFData Language

---------------------------------------------------------------------------
-- * Record Directives
---------------------------------------------------------------------------

data RecordDirectives' a = RecordDirectives
  { forall a. RecordDirectives' a -> Maybe (Ranged Induction)
recInductive   :: Maybe (Ranged Induction)
  , forall a. RecordDirectives' a -> Maybe HasEta0
recHasEta      :: Maybe HasEta0
  , forall a. RecordDirectives' a -> Maybe Range
recPattern     :: Maybe Range
  , forall a. RecordDirectives' a -> Maybe a
recConstructor :: Maybe a
  } deriving ((forall a b.
 (a -> b) -> RecordDirectives' a -> RecordDirectives' b)
-> (forall a b. a -> RecordDirectives' b -> RecordDirectives' a)
-> Functor RecordDirectives'
forall a b. a -> RecordDirectives' b -> RecordDirectives' a
forall a b. (a -> b) -> RecordDirectives' a -> RecordDirectives' b
forall (f :: * -> *).
(forall a b. (a -> b) -> f a -> f b)
-> (forall a b. a -> f b -> f a) -> Functor f
$cfmap :: forall a b. (a -> b) -> RecordDirectives' a -> RecordDirectives' b
fmap :: forall a b. (a -> b) -> RecordDirectives' a -> RecordDirectives' b
$c<$ :: forall a b. a -> RecordDirectives' b -> RecordDirectives' a
<$ :: forall a b. a -> RecordDirectives' b -> RecordDirectives' a
Functor, Int -> RecordDirectives' a -> ShowS
[RecordDirectives' a] -> ShowS
RecordDirectives' a -> ArgName
(Int -> RecordDirectives' a -> ShowS)
-> (RecordDirectives' a -> ArgName)
-> ([RecordDirectives' a] -> ShowS)
-> Show (RecordDirectives' a)
forall a. Show a => Int -> RecordDirectives' a -> ShowS
forall a. Show a => [RecordDirectives' a] -> ShowS
forall a. Show a => RecordDirectives' a -> ArgName
forall a.
(Int -> a -> ShowS) -> (a -> ArgName) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: forall a. Show a => Int -> RecordDirectives' a -> ShowS
showsPrec :: Int -> RecordDirectives' a -> ShowS
$cshow :: forall a. Show a => RecordDirectives' a -> ArgName
show :: RecordDirectives' a -> ArgName
$cshowList :: forall a. Show a => [RecordDirectives' a] -> ShowS
showList :: [RecordDirectives' a] -> ShowS
Show, RecordDirectives' a -> RecordDirectives' a -> Bool
(RecordDirectives' a -> RecordDirectives' a -> Bool)
-> (RecordDirectives' a -> RecordDirectives' a -> Bool)
-> Eq (RecordDirectives' a)
forall a.
Eq a =>
RecordDirectives' a -> RecordDirectives' a -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: forall a.
Eq a =>
RecordDirectives' a -> RecordDirectives' a -> Bool
== :: RecordDirectives' a -> RecordDirectives' a -> Bool
$c/= :: forall a.
Eq a =>
RecordDirectives' a -> RecordDirectives' a -> Bool
/= :: RecordDirectives' a -> RecordDirectives' a -> Bool
Eq)

emptyRecordDirectives :: RecordDirectives' a
emptyRecordDirectives :: forall a. RecordDirectives' a
emptyRecordDirectives = Maybe (Ranged Induction)
-> Maybe HasEta0 -> Maybe Range -> Maybe a -> RecordDirectives' a
forall a.
Maybe (Ranged Induction)
-> Maybe HasEta0 -> Maybe Range -> Maybe a -> RecordDirectives' a
RecordDirectives Maybe (Ranged Induction)
forall a. Null a => a
empty Maybe HasEta0
forall a. Null a => a
empty Maybe Range
forall a. Null a => a
empty Maybe a
forall a. Null a => a
empty

instance HasRange a => HasRange (RecordDirectives' a) where
  getRange :: RecordDirectives' a -> Range
getRange (RecordDirectives Maybe (Ranged Induction)
a Maybe HasEta0
b Maybe Range
c Maybe a
d) = (Maybe (Ranged Induction), Maybe HasEta0, Maybe Range, Maybe a)
-> Range
forall a. HasRange a => a -> Range
getRange (Maybe (Ranged Induction)
a,Maybe HasEta0
b,Maybe Range
c,Maybe a
d)

instance KillRange a => KillRange (RecordDirectives' a) where
  killRange :: KillRangeT (RecordDirectives' a)
killRange (RecordDirectives Maybe (Ranged Induction)
a Maybe HasEta0
b Maybe Range
c Maybe a
d) = (Maybe (Ranged Induction)
 -> Maybe HasEta0 -> Maybe Range -> Maybe a -> RecordDirectives' a)
-> Maybe (Ranged Induction)
-> Maybe HasEta0
-> Maybe Range
-> Maybe a
-> RecordDirectives' a
forall t (b :: Bool).
(KILLRANGE t b, IsBase t ~ b, All KillRange (Domains t)) =>
t -> t
killRangeN Maybe (Ranged Induction)
-> Maybe HasEta0 -> Maybe Range -> Maybe a -> RecordDirectives' a
forall a.
Maybe (Ranged Induction)
-> Maybe HasEta0 -> Maybe Range -> Maybe a -> RecordDirectives' a
RecordDirectives Maybe (Ranged Induction)
a Maybe HasEta0
b Maybe Range
c Maybe a
d

instance NFData a => NFData (RecordDirectives' a) where
  rnf :: RecordDirectives' a -> ()
rnf (RecordDirectives Maybe (Ranged Induction)
a Maybe HasEta0
b Maybe Range
c Maybe a
d) = Maybe Range
c Maybe Range -> () -> ()
forall a b. a -> b -> b
`seq` (Maybe (Ranged Induction), Maybe HasEta0, Maybe a) -> ()
forall a. NFData a => a -> ()
rnf (Maybe (Ranged Induction)
a, Maybe HasEta0
b, Maybe a
d)

---------------------------------------------------------------------------
-- * Eta-equality
---------------------------------------------------------------------------

-- | Does a record come with eta-equality?
data HasEta' a
  = YesEta
  | NoEta a
  deriving (Int -> HasEta' a -> ShowS
[HasEta' a] -> ShowS
HasEta' a -> ArgName
(Int -> HasEta' a -> ShowS)
-> (HasEta' a -> ArgName)
-> ([HasEta' a] -> ShowS)
-> Show (HasEta' a)
forall a. Show a => Int -> HasEta' a -> ShowS
forall a. Show a => [HasEta' a] -> ShowS
forall a. Show a => HasEta' a -> ArgName
forall a.
(Int -> a -> ShowS) -> (a -> ArgName) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: forall a. Show a => Int -> HasEta' a -> ShowS
showsPrec :: Int -> HasEta' a -> ShowS
$cshow :: forall a. Show a => HasEta' a -> ArgName
show :: HasEta' a -> ArgName
$cshowList :: forall a. Show a => [HasEta' a] -> ShowS
showList :: [HasEta' a] -> ShowS
Show, HasEta' a -> HasEta' a -> Bool
(HasEta' a -> HasEta' a -> Bool)
-> (HasEta' a -> HasEta' a -> Bool) -> Eq (HasEta' a)
forall a. Eq a => HasEta' a -> HasEta' a -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: forall a. Eq a => HasEta' a -> HasEta' a -> Bool
== :: HasEta' a -> HasEta' a -> Bool
$c/= :: forall a. Eq a => HasEta' a -> HasEta' a -> Bool
/= :: HasEta' a -> HasEta' a -> Bool
Eq, Eq (HasEta' a)
Eq (HasEta' a) =>
(HasEta' a -> HasEta' a -> Ordering)
-> (HasEta' a -> HasEta' a -> Bool)
-> (HasEta' a -> HasEta' a -> Bool)
-> (HasEta' a -> HasEta' a -> Bool)
-> (HasEta' a -> HasEta' a -> Bool)
-> (HasEta' a -> HasEta' a -> HasEta' a)
-> (HasEta' a -> HasEta' a -> HasEta' a)
-> Ord (HasEta' a)
HasEta' a -> HasEta' a -> Bool
HasEta' a -> HasEta' a -> Ordering
HasEta' a -> HasEta' a -> HasEta' a
forall a.
Eq a =>
(a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
forall a. Ord a => Eq (HasEta' a)
forall a. Ord a => HasEta' a -> HasEta' a -> Bool
forall a. Ord a => HasEta' a -> HasEta' a -> Ordering
forall a. Ord a => HasEta' a -> HasEta' a -> HasEta' a
$ccompare :: forall a. Ord a => HasEta' a -> HasEta' a -> Ordering
compare :: HasEta' a -> HasEta' a -> Ordering
$c< :: forall a. Ord a => HasEta' a -> HasEta' a -> Bool
< :: HasEta' a -> HasEta' a -> Bool
$c<= :: forall a. Ord a => HasEta' a -> HasEta' a -> Bool
<= :: HasEta' a -> HasEta' a -> Bool
$c> :: forall a. Ord a => HasEta' a -> HasEta' a -> Bool
> :: HasEta' a -> HasEta' a -> Bool
$c>= :: forall a. Ord a => HasEta' a -> HasEta' a -> Bool
>= :: HasEta' a -> HasEta' a -> Bool
$cmax :: forall a. Ord a => HasEta' a -> HasEta' a -> HasEta' a
max :: HasEta' a -> HasEta' a -> HasEta' a
$cmin :: forall a. Ord a => HasEta' a -> HasEta' a -> HasEta' a
min :: HasEta' a -> HasEta' a -> HasEta' a
Ord, (forall a b. (a -> b) -> HasEta' a -> HasEta' b)
-> (forall a b. a -> HasEta' b -> HasEta' a) -> Functor HasEta'
forall a b. a -> HasEta' b -> HasEta' a
forall a b. (a -> b) -> HasEta' a -> HasEta' b
forall (f :: * -> *).
(forall a b. (a -> b) -> f a -> f b)
-> (forall a b. a -> f b -> f a) -> Functor f
$cfmap :: forall a b. (a -> b) -> HasEta' a -> HasEta' b
fmap :: forall a b. (a -> b) -> HasEta' a -> HasEta' b
$c<$ :: forall a b. a -> HasEta' b -> HasEta' a
<$ :: forall a b. a -> HasEta' b -> HasEta' a
Functor, (forall m. Monoid m => HasEta' m -> m)
-> (forall m a. Monoid m => (a -> m) -> HasEta' a -> m)
-> (forall m a. Monoid m => (a -> m) -> HasEta' a -> m)
-> (forall a b. (a -> b -> b) -> b -> HasEta' a -> b)
-> (forall a b. (a -> b -> b) -> b -> HasEta' a -> b)
-> (forall b a. (b -> a -> b) -> b -> HasEta' a -> b)
-> (forall b a. (b -> a -> b) -> b -> HasEta' a -> b)
-> (forall a. (a -> a -> a) -> HasEta' a -> a)
-> (forall a. (a -> a -> a) -> HasEta' a -> a)
-> (forall a. HasEta' a -> [a])
-> (forall a. HasEta' a -> Bool)
-> (forall a. HasEta' a -> Int)
-> (forall a. Eq a => a -> HasEta' a -> Bool)
-> (forall a. Ord a => HasEta' a -> a)
-> (forall a. Ord a => HasEta' a -> a)
-> (forall a. Num a => HasEta' a -> a)
-> (forall a. Num a => HasEta' a -> a)
-> Foldable HasEta'
forall a. Eq a => a -> HasEta' a -> Bool
forall a. Num a => HasEta' a -> a
forall a. Ord a => HasEta' a -> a
forall m. Monoid m => HasEta' m -> m
forall a. HasEta' a -> Bool
forall a. HasEta' a -> Int
forall a. HasEta' a -> [a]
forall a. (a -> a -> a) -> HasEta' a -> a
forall m a. Monoid m => (a -> m) -> HasEta' a -> m
forall b a. (b -> a -> b) -> b -> HasEta' a -> b
forall a b. (a -> b -> b) -> b -> HasEta' a -> b
forall (t :: * -> *).
(forall m. Monoid m => t m -> m)
-> (forall m a. Monoid m => (a -> m) -> t a -> m)
-> (forall m a. Monoid m => (a -> m) -> t a -> m)
-> (forall a b. (a -> b -> b) -> b -> t a -> b)
-> (forall a b. (a -> b -> b) -> b -> t a -> b)
-> (forall b a. (b -> a -> b) -> b -> t a -> b)
-> (forall b a. (b -> a -> b) -> b -> t a -> b)
-> (forall a. (a -> a -> a) -> t a -> a)
-> (forall a. (a -> a -> a) -> t a -> a)
-> (forall a. t a -> [a])
-> (forall a. t a -> Bool)
-> (forall a. t a -> Int)
-> (forall a. Eq a => a -> t a -> Bool)
-> (forall a. Ord a => t a -> a)
-> (forall a. Ord a => t a -> a)
-> (forall a. Num a => t a -> a)
-> (forall a. Num a => t a -> a)
-> Foldable t
$cfold :: forall m. Monoid m => HasEta' m -> m
fold :: forall m. Monoid m => HasEta' m -> m
$cfoldMap :: forall m a. Monoid m => (a -> m) -> HasEta' a -> m
foldMap :: forall m a. Monoid m => (a -> m) -> HasEta' a -> m
$cfoldMap' :: forall m a. Monoid m => (a -> m) -> HasEta' a -> m
foldMap' :: forall m a. Monoid m => (a -> m) -> HasEta' a -> m
$cfoldr :: forall a b. (a -> b -> b) -> b -> HasEta' a -> b
foldr :: forall a b. (a -> b -> b) -> b -> HasEta' a -> b
$cfoldr' :: forall a b. (a -> b -> b) -> b -> HasEta' a -> b
foldr' :: forall a b. (a -> b -> b) -> b -> HasEta' a -> b
$cfoldl :: forall b a. (b -> a -> b) -> b -> HasEta' a -> b
foldl :: forall b a. (b -> a -> b) -> b -> HasEta' a -> b
$cfoldl' :: forall b a. (b -> a -> b) -> b -> HasEta' a -> b
foldl' :: forall b a. (b -> a -> b) -> b -> HasEta' a -> b
$cfoldr1 :: forall a. (a -> a -> a) -> HasEta' a -> a
foldr1 :: forall a. (a -> a -> a) -> HasEta' a -> a
$cfoldl1 :: forall a. (a -> a -> a) -> HasEta' a -> a
foldl1 :: forall a. (a -> a -> a) -> HasEta' a -> a
$ctoList :: forall a. HasEta' a -> [a]
toList :: forall a. HasEta' a -> [a]
$cnull :: forall a. HasEta' a -> Bool
null :: forall a. HasEta' a -> Bool
$clength :: forall a. HasEta' a -> Int
length :: forall a. HasEta' a -> Int
$celem :: forall a. Eq a => a -> HasEta' a -> Bool
elem :: forall a. Eq a => a -> HasEta' a -> Bool
$cmaximum :: forall a. Ord a => HasEta' a -> a
maximum :: forall a. Ord a => HasEta' a -> a
$cminimum :: forall a. Ord a => HasEta' a -> a
minimum :: forall a. Ord a => HasEta' a -> a
$csum :: forall a. Num a => HasEta' a -> a
sum :: forall a. Num a => HasEta' a -> a
$cproduct :: forall a. Num a => HasEta' a -> a
product :: forall a. Num a => HasEta' a -> a
Foldable, Functor HasEta'
Foldable HasEta'
(Functor HasEta', Foldable HasEta') =>
(forall (f :: * -> *) a b.
 Applicative f =>
 (a -> f b) -> HasEta' a -> f (HasEta' b))
-> (forall (f :: * -> *) a.
    Applicative f =>
    HasEta' (f a) -> f (HasEta' a))
-> (forall (m :: * -> *) a b.
    Monad m =>
    (a -> m b) -> HasEta' a -> m (HasEta' b))
-> (forall (m :: * -> *) a.
    Monad m =>
    HasEta' (m a) -> m (HasEta' a))
-> Traversable HasEta'
forall (t :: * -> *).
(Functor t, Foldable t) =>
(forall (f :: * -> *) a b.
 Applicative f =>
 (a -> f b) -> t a -> f (t b))
-> (forall (f :: * -> *) a. Applicative f => t (f a) -> f (t a))
-> (forall (m :: * -> *) a b.
    Monad m =>
    (a -> m b) -> t a -> m (t b))
-> (forall (m :: * -> *) a. Monad m => t (m a) -> m (t a))
-> Traversable t
forall (m :: * -> *) a. Monad m => HasEta' (m a) -> m (HasEta' a)
forall (f :: * -> *) a.
Applicative f =>
HasEta' (f a) -> f (HasEta' a)
forall (m :: * -> *) a b.
Monad m =>
(a -> m b) -> HasEta' a -> m (HasEta' b)
forall (f :: * -> *) a b.
Applicative f =>
(a -> f b) -> HasEta' a -> f (HasEta' b)
$ctraverse :: forall (f :: * -> *) a b.
Applicative f =>
(a -> f b) -> HasEta' a -> f (HasEta' b)
traverse :: forall (f :: * -> *) a b.
Applicative f =>
(a -> f b) -> HasEta' a -> f (HasEta' b)
$csequenceA :: forall (f :: * -> *) a.
Applicative f =>
HasEta' (f a) -> f (HasEta' a)
sequenceA :: forall (f :: * -> *) a.
Applicative f =>
HasEta' (f a) -> f (HasEta' a)
$cmapM :: forall (m :: * -> *) a b.
Monad m =>
(a -> m b) -> HasEta' a -> m (HasEta' b)
mapM :: forall (m :: * -> *) a b.
Monad m =>
(a -> m b) -> HasEta' a -> m (HasEta' b)
$csequence :: forall (m :: * -> *) a. Monad m => HasEta' (m a) -> m (HasEta' a)
sequence :: forall (m :: * -> *) a. Monad m => HasEta' (m a) -> m (HasEta' a)
Traversable)

instance HasRange a => HasRange (HasEta' a) where
  getRange :: HasEta' a -> Range
getRange = (a -> Range) -> HasEta' a -> Range
forall m a. Monoid m => (a -> m) -> HasEta' a -> m
forall (t :: * -> *) m a.
(Foldable t, Monoid m) =>
(a -> m) -> t a -> m
foldMap a -> Range
forall a. HasRange a => a -> Range
getRange

instance KillRange a => KillRange (HasEta' a) where
  killRange :: KillRangeT (HasEta' a)
killRange = (a -> a) -> KillRangeT (HasEta' a)
forall a b. (a -> b) -> HasEta' a -> HasEta' b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap a -> a
forall a. KillRange a => KillRangeT a
killRange

instance NFData a => NFData (HasEta' a) where
  rnf :: HasEta' a -> ()
rnf HasEta' a
YesEta    = ()
  rnf (NoEta a
p) = a -> ()
forall a. NFData a => a -> ()
rnf a
p

-- | Pattern and copattern matching is allowed in the presence of eta.
--
--   In the absence of eta, we have to choose whether we want to allow
--   matching on the constructor or copattern matching with the projections.
--   Having both leads to breakage of subject reduction (issue #4560).

type HasEta  = HasEta' PatternOrCopattern
type HasEta0 = HasEta' ()

-- | For a record without eta, which type of matching do we allow?
data PatternOrCopattern
  = PatternMatching
      -- ^ Can match on the record constructor.
  | CopatternMatching
      -- ^ Can copattern match using the projections. (Default.)
  deriving (Int -> PatternOrCopattern -> ShowS
[PatternOrCopattern] -> ShowS
PatternOrCopattern -> ArgName
(Int -> PatternOrCopattern -> ShowS)
-> (PatternOrCopattern -> ArgName)
-> ([PatternOrCopattern] -> ShowS)
-> Show PatternOrCopattern
forall a.
(Int -> a -> ShowS) -> (a -> ArgName) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> PatternOrCopattern -> ShowS
showsPrec :: Int -> PatternOrCopattern -> ShowS
$cshow :: PatternOrCopattern -> ArgName
show :: PatternOrCopattern -> ArgName
$cshowList :: [PatternOrCopattern] -> ShowS
showList :: [PatternOrCopattern] -> ShowS
Show, PatternOrCopattern -> PatternOrCopattern -> Bool
(PatternOrCopattern -> PatternOrCopattern -> Bool)
-> (PatternOrCopattern -> PatternOrCopattern -> Bool)
-> Eq PatternOrCopattern
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: PatternOrCopattern -> PatternOrCopattern -> Bool
== :: PatternOrCopattern -> PatternOrCopattern -> Bool
$c/= :: PatternOrCopattern -> PatternOrCopattern -> Bool
/= :: PatternOrCopattern -> PatternOrCopattern -> Bool
Eq, Eq PatternOrCopattern
Eq PatternOrCopattern =>
(PatternOrCopattern -> PatternOrCopattern -> Ordering)
-> (PatternOrCopattern -> PatternOrCopattern -> Bool)
-> (PatternOrCopattern -> PatternOrCopattern -> Bool)
-> (PatternOrCopattern -> PatternOrCopattern -> Bool)
-> (PatternOrCopattern -> PatternOrCopattern -> Bool)
-> (PatternOrCopattern -> PatternOrCopattern -> PatternOrCopattern)
-> (PatternOrCopattern -> PatternOrCopattern -> PatternOrCopattern)
-> Ord PatternOrCopattern
PatternOrCopattern -> PatternOrCopattern -> Bool
PatternOrCopattern -> PatternOrCopattern -> Ordering
PatternOrCopattern -> PatternOrCopattern -> PatternOrCopattern
forall a.
Eq a =>
(a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
$ccompare :: PatternOrCopattern -> PatternOrCopattern -> Ordering
compare :: PatternOrCopattern -> PatternOrCopattern -> Ordering
$c< :: PatternOrCopattern -> PatternOrCopattern -> Bool
< :: PatternOrCopattern -> PatternOrCopattern -> Bool
$c<= :: PatternOrCopattern -> PatternOrCopattern -> Bool
<= :: PatternOrCopattern -> PatternOrCopattern -> Bool
$c> :: PatternOrCopattern -> PatternOrCopattern -> Bool
> :: PatternOrCopattern -> PatternOrCopattern -> Bool
$c>= :: PatternOrCopattern -> PatternOrCopattern -> Bool
>= :: PatternOrCopattern -> PatternOrCopattern -> Bool
$cmax :: PatternOrCopattern -> PatternOrCopattern -> PatternOrCopattern
max :: PatternOrCopattern -> PatternOrCopattern -> PatternOrCopattern
$cmin :: PatternOrCopattern -> PatternOrCopattern -> PatternOrCopattern
min :: PatternOrCopattern -> PatternOrCopattern -> PatternOrCopattern
Ord, Int -> PatternOrCopattern
PatternOrCopattern -> Int
PatternOrCopattern -> [PatternOrCopattern]
PatternOrCopattern -> PatternOrCopattern
PatternOrCopattern -> PatternOrCopattern -> [PatternOrCopattern]
PatternOrCopattern
-> PatternOrCopattern -> PatternOrCopattern -> [PatternOrCopattern]
(PatternOrCopattern -> PatternOrCopattern)
-> (PatternOrCopattern -> PatternOrCopattern)
-> (Int -> PatternOrCopattern)
-> (PatternOrCopattern -> Int)
-> (PatternOrCopattern -> [PatternOrCopattern])
-> (PatternOrCopattern
    -> PatternOrCopattern -> [PatternOrCopattern])
-> (PatternOrCopattern
    -> PatternOrCopattern -> [PatternOrCopattern])
-> (PatternOrCopattern
    -> PatternOrCopattern
    -> PatternOrCopattern
    -> [PatternOrCopattern])
-> Enum PatternOrCopattern
forall a.
(a -> a)
-> (a -> a)
-> (Int -> a)
-> (a -> Int)
-> (a -> [a])
-> (a -> a -> [a])
-> (a -> a -> [a])
-> (a -> a -> a -> [a])
-> Enum a
$csucc :: PatternOrCopattern -> PatternOrCopattern
succ :: PatternOrCopattern -> PatternOrCopattern
$cpred :: PatternOrCopattern -> PatternOrCopattern
pred :: PatternOrCopattern -> PatternOrCopattern
$ctoEnum :: Int -> PatternOrCopattern
toEnum :: Int -> PatternOrCopattern
$cfromEnum :: PatternOrCopattern -> Int
fromEnum :: PatternOrCopattern -> Int
$cenumFrom :: PatternOrCopattern -> [PatternOrCopattern]
enumFrom :: PatternOrCopattern -> [PatternOrCopattern]
$cenumFromThen :: PatternOrCopattern -> PatternOrCopattern -> [PatternOrCopattern]
enumFromThen :: PatternOrCopattern -> PatternOrCopattern -> [PatternOrCopattern]
$cenumFromTo :: PatternOrCopattern -> PatternOrCopattern -> [PatternOrCopattern]
enumFromTo :: PatternOrCopattern -> PatternOrCopattern -> [PatternOrCopattern]
$cenumFromThenTo :: PatternOrCopattern
-> PatternOrCopattern -> PatternOrCopattern -> [PatternOrCopattern]
enumFromThenTo :: PatternOrCopattern
-> PatternOrCopattern -> PatternOrCopattern -> [PatternOrCopattern]
Enum, PatternOrCopattern
PatternOrCopattern
-> PatternOrCopattern -> Bounded PatternOrCopattern
forall a. a -> a -> Bounded a
$cminBound :: PatternOrCopattern
minBound :: PatternOrCopattern
$cmaxBound :: PatternOrCopattern
maxBound :: PatternOrCopattern
Bounded)

instance NFData PatternOrCopattern where
  rnf :: PatternOrCopattern -> ()
rnf PatternOrCopattern
PatternMatching   = ()
  rnf PatternOrCopattern
CopatternMatching = ()

instance HasRange PatternOrCopattern where
  getRange :: PatternOrCopattern -> Range
getRange PatternOrCopattern
_ = Range
forall a. Range' a
noRange

instance KillRange PatternOrCopattern where
  killRange :: PatternOrCopattern -> PatternOrCopattern
killRange = PatternOrCopattern -> PatternOrCopattern
forall a. a -> a
id

-- | Can we pattern match on the record constructor?
class PatternMatchingAllowed a where
  patternMatchingAllowed :: a -> Bool

instance PatternMatchingAllowed PatternOrCopattern where
  patternMatchingAllowed :: PatternOrCopattern -> Bool
patternMatchingAllowed = (PatternOrCopattern -> PatternOrCopattern -> Bool
forall a. Eq a => a -> a -> Bool
== PatternOrCopattern
PatternMatching)

instance PatternMatchingAllowed HasEta where
  patternMatchingAllowed :: HasEta -> Bool
patternMatchingAllowed = \case
    HasEta
YesEta -> Bool
True
    NoEta PatternOrCopattern
p -> PatternOrCopattern -> Bool
forall a. PatternMatchingAllowed a => a -> Bool
patternMatchingAllowed PatternOrCopattern
p


-- | Can we construct a record by copattern matching?
class CopatternMatchingAllowed a where
  copatternMatchingAllowed :: a -> Bool

instance CopatternMatchingAllowed PatternOrCopattern where
  copatternMatchingAllowed :: PatternOrCopattern -> Bool
copatternMatchingAllowed = (PatternOrCopattern -> PatternOrCopattern -> Bool
forall a. Eq a => a -> a -> Bool
== PatternOrCopattern
CopatternMatching)

instance CopatternMatchingAllowed HasEta where
  copatternMatchingAllowed :: HasEta -> Bool
copatternMatchingAllowed = \case
    HasEta
YesEta -> Bool
True
    NoEta PatternOrCopattern
p -> PatternOrCopattern -> Bool
forall a. CopatternMatchingAllowed a => a -> Bool
copatternMatchingAllowed PatternOrCopattern
p

---------------------------------------------------------------------------
-- * Induction
---------------------------------------------------------------------------

instance Pretty Induction where
  pretty :: Induction -> Doc
pretty Induction
Inductive   = Doc
"inductive"
  pretty Induction
CoInductive = Doc
"coinductive"

instance HasRange Induction where
  getRange :: Induction -> Range
getRange Induction
_ = Range
forall a. Range' a
noRange

instance KillRange Induction where
  killRange :: KillRangeT Induction
killRange = KillRangeT Induction
forall a. a -> a
id

instance PatternMatchingAllowed Induction where
  patternMatchingAllowed :: Induction -> Bool
patternMatchingAllowed = (Induction -> Induction -> Bool
forall a. Eq a => a -> a -> Bool
== Induction
Inductive)

---------------------------------------------------------------------------
-- * Hiding
---------------------------------------------------------------------------

data Overlappable = YesOverlap | NoOverlap
  deriving (Int -> Overlappable -> ShowS
[Overlappable] -> ShowS
Overlappable -> ArgName
(Int -> Overlappable -> ShowS)
-> (Overlappable -> ArgName)
-> ([Overlappable] -> ShowS)
-> Show Overlappable
forall a.
(Int -> a -> ShowS) -> (a -> ArgName) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> Overlappable -> ShowS
showsPrec :: Int -> Overlappable -> ShowS
$cshow :: Overlappable -> ArgName
show :: Overlappable -> ArgName
$cshowList :: [Overlappable] -> ShowS
showList :: [Overlappable] -> ShowS
Show, Overlappable -> Overlappable -> Bool
(Overlappable -> Overlappable -> Bool)
-> (Overlappable -> Overlappable -> Bool) -> Eq Overlappable
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: Overlappable -> Overlappable -> Bool
== :: Overlappable -> Overlappable -> Bool
$c/= :: Overlappable -> Overlappable -> Bool
/= :: Overlappable -> Overlappable -> Bool
Eq, Eq Overlappable
Eq Overlappable =>
(Overlappable -> Overlappable -> Ordering)
-> (Overlappable -> Overlappable -> Bool)
-> (Overlappable -> Overlappable -> Bool)
-> (Overlappable -> Overlappable -> Bool)
-> (Overlappable -> Overlappable -> Bool)
-> (Overlappable -> Overlappable -> Overlappable)
-> (Overlappable -> Overlappable -> Overlappable)
-> Ord Overlappable
Overlappable -> Overlappable -> Bool
Overlappable -> Overlappable -> Ordering
Overlappable -> Overlappable -> Overlappable
forall a.
Eq a =>
(a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
$ccompare :: Overlappable -> Overlappable -> Ordering
compare :: Overlappable -> Overlappable -> Ordering
$c< :: Overlappable -> Overlappable -> Bool
< :: Overlappable -> Overlappable -> Bool
$c<= :: Overlappable -> Overlappable -> Bool
<= :: Overlappable -> Overlappable -> Bool
$c> :: Overlappable -> Overlappable -> Bool
> :: Overlappable -> Overlappable -> Bool
$c>= :: Overlappable -> Overlappable -> Bool
>= :: Overlappable -> Overlappable -> Bool
$cmax :: Overlappable -> Overlappable -> Overlappable
max :: Overlappable -> Overlappable -> Overlappable
$cmin :: Overlappable -> Overlappable -> Overlappable
min :: Overlappable -> Overlappable -> Overlappable
Ord)

data Hiding  = Hidden | Instance Overlappable | NotHidden
  deriving (Int -> Hiding -> ShowS
[Hiding] -> ShowS
Hiding -> ArgName
(Int -> Hiding -> ShowS)
-> (Hiding -> ArgName) -> ([Hiding] -> ShowS) -> Show Hiding
forall a.
(Int -> a -> ShowS) -> (a -> ArgName) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> Hiding -> ShowS
showsPrec :: Int -> Hiding -> ShowS
$cshow :: Hiding -> ArgName
show :: Hiding -> ArgName
$cshowList :: [Hiding] -> ShowS
showList :: [Hiding] -> ShowS
Show, Hiding -> Hiding -> Bool
(Hiding -> Hiding -> Bool)
-> (Hiding -> Hiding -> Bool) -> Eq Hiding
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: Hiding -> Hiding -> Bool
== :: Hiding -> Hiding -> Bool
$c/= :: Hiding -> Hiding -> Bool
/= :: Hiding -> Hiding -> Bool
Eq, Eq Hiding
Eq Hiding =>
(Hiding -> Hiding -> Ordering)
-> (Hiding -> Hiding -> Bool)
-> (Hiding -> Hiding -> Bool)
-> (Hiding -> Hiding -> Bool)
-> (Hiding -> Hiding -> Bool)
-> (Hiding -> Hiding -> Hiding)
-> (Hiding -> Hiding -> Hiding)
-> Ord Hiding
Hiding -> Hiding -> Bool
Hiding -> Hiding -> Ordering
Hiding -> Hiding -> Hiding
forall a.
Eq a =>
(a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
$ccompare :: Hiding -> Hiding -> Ordering
compare :: Hiding -> Hiding -> Ordering
$c< :: Hiding -> Hiding -> Bool
< :: Hiding -> Hiding -> Bool
$c<= :: Hiding -> Hiding -> Bool
<= :: Hiding -> Hiding -> Bool
$c> :: Hiding -> Hiding -> Bool
> :: Hiding -> Hiding -> Bool
$c>= :: Hiding -> Hiding -> Bool
>= :: Hiding -> Hiding -> Bool
$cmax :: Hiding -> Hiding -> Hiding
max :: Hiding -> Hiding -> Hiding
$cmin :: Hiding -> Hiding -> Hiding
min :: Hiding -> Hiding -> Hiding
Ord)

instance Pretty Hiding where
  pretty :: Hiding -> Doc
pretty = \case
    Hiding
Hidden     -> Doc
"hidden"
    Hiding
NotHidden  -> Doc
"visible"
    Instance{} -> Doc
"instance"

-- | Just for the 'Hiding' instance. Should never combine different
--   overlapping.
instance Semigroup Overlappable where
  Overlappable
NoOverlap  <> :: Overlappable -> Overlappable -> Overlappable
<> Overlappable
NoOverlap  = Overlappable
NoOverlap
  Overlappable
YesOverlap <> Overlappable
YesOverlap = Overlappable
YesOverlap
  Overlappable
_          <> Overlappable
_          = Overlappable
forall a. HasCallStack => a
__IMPOSSIBLE__

-- | 'Hiding' is an idempotent partial monoid, with unit 'NotHidden'.
--   'Instance' and 'NotHidden' are incompatible.
instance Semigroup Hiding where
  Hiding
NotHidden  <> :: Hiding -> Hiding -> Hiding
<> Hiding
h           = Hiding
h
  Hiding
h          <> Hiding
NotHidden   = Hiding
h
  Hiding
Hidden     <> Hiding
Hidden      = Hiding
Hidden
  Instance Overlappable
o <> Instance Overlappable
o' = Overlappable -> Hiding
Instance (Overlappable
o Overlappable -> Overlappable -> Overlappable
forall a. Semigroup a => a -> a -> a
<> Overlappable
o')
  Hiding
_          <> Hiding
_           = Hiding
forall a. HasCallStack => a
__IMPOSSIBLE__

instance Monoid Overlappable where
  mempty :: Overlappable
mempty  = Overlappable
NoOverlap
  mappend :: Overlappable -> Overlappable -> Overlappable
mappend = Overlappable -> Overlappable -> Overlappable
forall a. Semigroup a => a -> a -> a
(<>)

instance Monoid Hiding where
  mempty :: Hiding
mempty = Hiding
NotHidden
  mappend :: Hiding -> Hiding -> Hiding
mappend = Hiding -> Hiding -> Hiding
forall a. Semigroup a => a -> a -> a
(<>)

instance HasRange Hiding where
  getRange :: Hiding -> Range
getRange Hiding
_ = Range
forall a. Range' a
noRange

instance KillRange Hiding where
  killRange :: Hiding -> Hiding
killRange = Hiding -> Hiding
forall a. a -> a
id

instance NFData Overlappable where
  rnf :: Overlappable -> ()
rnf Overlappable
NoOverlap  = ()
  rnf Overlappable
YesOverlap = ()

instance NFData Hiding where
  rnf :: Hiding -> ()
rnf Hiding
Hidden       = ()
  rnf (Instance Overlappable
o) = Overlappable -> ()
forall a. NFData a => a -> ()
rnf Overlappable
o
  rnf Hiding
NotHidden    = ()

-- | Decorating something with 'Hiding' information.
data WithHiding a = WithHiding
  { forall a. WithHiding a -> Hiding
whHiding :: !Hiding
  , forall a. WithHiding a -> a
whThing  :: a
  }
  deriving (WithHiding a -> WithHiding a -> Bool
(WithHiding a -> WithHiding a -> Bool)
-> (WithHiding a -> WithHiding a -> Bool) -> Eq (WithHiding a)
forall a. Eq a => WithHiding a -> WithHiding a -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: forall a. Eq a => WithHiding a -> WithHiding a -> Bool
== :: WithHiding a -> WithHiding a -> Bool
$c/= :: forall a. Eq a => WithHiding a -> WithHiding a -> Bool
/= :: WithHiding a -> WithHiding a -> Bool
Eq, Eq (WithHiding a)
Eq (WithHiding a) =>
(WithHiding a -> WithHiding a -> Ordering)
-> (WithHiding a -> WithHiding a -> Bool)
-> (WithHiding a -> WithHiding a -> Bool)
-> (WithHiding a -> WithHiding a -> Bool)
-> (WithHiding a -> WithHiding a -> Bool)
-> (WithHiding a -> WithHiding a -> WithHiding a)
-> (WithHiding a -> WithHiding a -> WithHiding a)
-> Ord (WithHiding a)
WithHiding a -> WithHiding a -> Bool
WithHiding a -> WithHiding a -> Ordering
WithHiding a -> WithHiding a -> WithHiding a
forall a.
Eq a =>
(a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
forall a. Ord a => Eq (WithHiding a)
forall a. Ord a => WithHiding a -> WithHiding a -> Bool
forall a. Ord a => WithHiding a -> WithHiding a -> Ordering
forall a. Ord a => WithHiding a -> WithHiding a -> WithHiding a
$ccompare :: forall a. Ord a => WithHiding a -> WithHiding a -> Ordering
compare :: WithHiding a -> WithHiding a -> Ordering
$c< :: forall a. Ord a => WithHiding a -> WithHiding a -> Bool
< :: WithHiding a -> WithHiding a -> Bool
$c<= :: forall a. Ord a => WithHiding a -> WithHiding a -> Bool
<= :: WithHiding a -> WithHiding a -> Bool
$c> :: forall a. Ord a => WithHiding a -> WithHiding a -> Bool
> :: WithHiding a -> WithHiding a -> Bool
$c>= :: forall a. Ord a => WithHiding a -> WithHiding a -> Bool
>= :: WithHiding a -> WithHiding a -> Bool
$cmax :: forall a. Ord a => WithHiding a -> WithHiding a -> WithHiding a
max :: WithHiding a -> WithHiding a -> WithHiding a
$cmin :: forall a. Ord a => WithHiding a -> WithHiding a -> WithHiding a
min :: WithHiding a -> WithHiding a -> WithHiding a
Ord, Int -> WithHiding a -> ShowS
[WithHiding a] -> ShowS
WithHiding a -> ArgName
(Int -> WithHiding a -> ShowS)
-> (WithHiding a -> ArgName)
-> ([WithHiding a] -> ShowS)
-> Show (WithHiding a)
forall a. Show a => Int -> WithHiding a -> ShowS
forall a. Show a => [WithHiding a] -> ShowS
forall a. Show a => WithHiding a -> ArgName
forall a.
(Int -> a -> ShowS) -> (a -> ArgName) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: forall a. Show a => Int -> WithHiding a -> ShowS
showsPrec :: Int -> WithHiding a -> ShowS
$cshow :: forall a. Show a => WithHiding a -> ArgName
show :: WithHiding a -> ArgName
$cshowList :: forall a. Show a => [WithHiding a] -> ShowS
showList :: [WithHiding a] -> ShowS
Show, (forall a b. (a -> b) -> WithHiding a -> WithHiding b)
-> (forall a b. a -> WithHiding b -> WithHiding a)
-> Functor WithHiding
forall a b. a -> WithHiding b -> WithHiding a
forall a b. (a -> b) -> WithHiding a -> WithHiding b
forall (f :: * -> *).
(forall a b. (a -> b) -> f a -> f b)
-> (forall a b. a -> f b -> f a) -> Functor f
$cfmap :: forall a b. (a -> b) -> WithHiding a -> WithHiding b
fmap :: forall a b. (a -> b) -> WithHiding a -> WithHiding b
$c<$ :: forall a b. a -> WithHiding b -> WithHiding a
<$ :: forall a b. a -> WithHiding b -> WithHiding a
Functor, (forall m. Monoid m => WithHiding m -> m)
-> (forall m a. Monoid m => (a -> m) -> WithHiding a -> m)
-> (forall m a. Monoid m => (a -> m) -> WithHiding a -> m)
-> (forall a b. (a -> b -> b) -> b -> WithHiding a -> b)
-> (forall a b. (a -> b -> b) -> b -> WithHiding a -> b)
-> (forall b a. (b -> a -> b) -> b -> WithHiding a -> b)
-> (forall b a. (b -> a -> b) -> b -> WithHiding a -> b)
-> (forall a. (a -> a -> a) -> WithHiding a -> a)
-> (forall a. (a -> a -> a) -> WithHiding a -> a)
-> (forall a. WithHiding a -> [a])
-> (forall a. WithHiding a -> Bool)
-> (forall a. WithHiding a -> Int)
-> (forall a. Eq a => a -> WithHiding a -> Bool)
-> (forall a. Ord a => WithHiding a -> a)
-> (forall a. Ord a => WithHiding a -> a)
-> (forall a. Num a => WithHiding a -> a)
-> (forall a. Num a => WithHiding a -> a)
-> Foldable WithHiding
forall a. Eq a => a -> WithHiding a -> Bool
forall a. Num a => WithHiding a -> a
forall a. Ord a => WithHiding a -> a
forall m. Monoid m => WithHiding m -> m
forall a. WithHiding a -> Bool
forall a. WithHiding a -> Int
forall a. WithHiding a -> [a]
forall a. (a -> a -> a) -> WithHiding a -> a
forall m a. Monoid m => (a -> m) -> WithHiding a -> m
forall b a. (b -> a -> b) -> b -> WithHiding a -> b
forall a b. (a -> b -> b) -> b -> WithHiding a -> b
forall (t :: * -> *).
(forall m. Monoid m => t m -> m)
-> (forall m a. Monoid m => (a -> m) -> t a -> m)
-> (forall m a. Monoid m => (a -> m) -> t a -> m)
-> (forall a b. (a -> b -> b) -> b -> t a -> b)
-> (forall a b. (a -> b -> b) -> b -> t a -> b)
-> (forall b a. (b -> a -> b) -> b -> t a -> b)
-> (forall b a. (b -> a -> b) -> b -> t a -> b)
-> (forall a. (a -> a -> a) -> t a -> a)
-> (forall a. (a -> a -> a) -> t a -> a)
-> (forall a. t a -> [a])
-> (forall a. t a -> Bool)
-> (forall a. t a -> Int)
-> (forall a. Eq a => a -> t a -> Bool)
-> (forall a. Ord a => t a -> a)
-> (forall a. Ord a => t a -> a)
-> (forall a. Num a => t a -> a)
-> (forall a. Num a => t a -> a)
-> Foldable t
$cfold :: forall m. Monoid m => WithHiding m -> m
fold :: forall m. Monoid m => WithHiding m -> m
$cfoldMap :: forall m a. Monoid m => (a -> m) -> WithHiding a -> m
foldMap :: forall m a. Monoid m => (a -> m) -> WithHiding a -> m
$cfoldMap' :: forall m a. Monoid m => (a -> m) -> WithHiding a -> m
foldMap' :: forall m a. Monoid m => (a -> m) -> WithHiding a -> m
$cfoldr :: forall a b. (a -> b -> b) -> b -> WithHiding a -> b
foldr :: forall a b. (a -> b -> b) -> b -> WithHiding a -> b
$cfoldr' :: forall a b. (a -> b -> b) -> b -> WithHiding a -> b
foldr' :: forall a b. (a -> b -> b) -> b -> WithHiding a -> b
$cfoldl :: forall b a. (b -> a -> b) -> b -> WithHiding a -> b
foldl :: forall b a. (b -> a -> b) -> b -> WithHiding a -> b
$cfoldl' :: forall b a. (b -> a -> b) -> b -> WithHiding a -> b
foldl' :: forall b a. (b -> a -> b) -> b -> WithHiding a -> b
$cfoldr1 :: forall a. (a -> a -> a) -> WithHiding a -> a
foldr1 :: forall a. (a -> a -> a) -> WithHiding a -> a
$cfoldl1 :: forall a. (a -> a -> a) -> WithHiding a -> a
foldl1 :: forall a. (a -> a -> a) -> WithHiding a -> a
$ctoList :: forall a. WithHiding a -> [a]
toList :: forall a. WithHiding a -> [a]
$cnull :: forall a. WithHiding a -> Bool
null :: forall a. WithHiding a -> Bool
$clength :: forall a. WithHiding a -> Int
length :: forall a. WithHiding a -> Int
$celem :: forall a. Eq a => a -> WithHiding a -> Bool
elem :: forall a. Eq a => a -> WithHiding a -> Bool
$cmaximum :: forall a. Ord a => WithHiding a -> a
maximum :: forall a. Ord a => WithHiding a -> a
$cminimum :: forall a. Ord a => WithHiding a -> a
minimum :: forall a. Ord a => WithHiding a -> a
$csum :: forall a. Num a => WithHiding a -> a
sum :: forall a. Num a => WithHiding a -> a
$cproduct :: forall a. Num a => WithHiding a -> a
product :: forall a. Num a => WithHiding a -> a
Foldable, Functor WithHiding
Foldable WithHiding
(Functor WithHiding, Foldable WithHiding) =>
(forall (f :: * -> *) a b.
 Applicative f =>
 (a -> f b) -> WithHiding a -> f (WithHiding b))
-> (forall (f :: * -> *) a.
    Applicative f =>
    WithHiding (f a) -> f (WithHiding a))
-> (forall (m :: * -> *) a b.
    Monad m =>
    (a -> m b) -> WithHiding a -> m (WithHiding b))
-> (forall (m :: * -> *) a.
    Monad m =>
    WithHiding (m a) -> m (WithHiding a))
-> Traversable WithHiding
forall (t :: * -> *).
(Functor t, Foldable t) =>
(forall (f :: * -> *) a b.
 Applicative f =>
 (a -> f b) -> t a -> f (t b))
-> (forall (f :: * -> *) a. Applicative f => t (f a) -> f (t a))
-> (forall (m :: * -> *) a b.
    Monad m =>
    (a -> m b) -> t a -> m (t b))
-> (forall (m :: * -> *) a. Monad m => t (m a) -> m (t a))
-> Traversable t
forall (m :: * -> *) a.
Monad m =>
WithHiding (m a) -> m (WithHiding a)
forall (f :: * -> *) a.
Applicative f =>
WithHiding (f a) -> f (WithHiding a)
forall (m :: * -> *) a b.
Monad m =>
(a -> m b) -> WithHiding a -> m (WithHiding b)
forall (f :: * -> *) a b.
Applicative f =>
(a -> f b) -> WithHiding a -> f (WithHiding b)
$ctraverse :: forall (f :: * -> *) a b.
Applicative f =>
(a -> f b) -> WithHiding a -> f (WithHiding b)
traverse :: forall (f :: * -> *) a b.
Applicative f =>
(a -> f b) -> WithHiding a -> f (WithHiding b)
$csequenceA :: forall (f :: * -> *) a.
Applicative f =>
WithHiding (f a) -> f (WithHiding a)
sequenceA :: forall (f :: * -> *) a.
Applicative f =>
WithHiding (f a) -> f (WithHiding a)
$cmapM :: forall (m :: * -> *) a b.
Monad m =>
(a -> m b) -> WithHiding a -> m (WithHiding b)
mapM :: forall (m :: * -> *) a b.
Monad m =>
(a -> m b) -> WithHiding a -> m (WithHiding b)
$csequence :: forall (m :: * -> *) a.
Monad m =>
WithHiding (m a) -> m (WithHiding a)
sequence :: forall (m :: * -> *) a.
Monad m =>
WithHiding (m a) -> m (WithHiding a)
Traversable)

instance Decoration WithHiding where
  traverseF :: forall (m :: * -> *) a b.
Functor m =>
(a -> m b) -> WithHiding a -> m (WithHiding b)
traverseF a -> m b
f (WithHiding Hiding
h a
a) = Hiding -> b -> WithHiding b
forall a. Hiding -> a -> WithHiding a
WithHiding Hiding
h (b -> WithHiding b) -> m b -> m (WithHiding b)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> a -> m b
f a
a

instance Applicative WithHiding where
  pure :: forall a. a -> WithHiding a
pure = Hiding -> a -> WithHiding a
forall a. Hiding -> a -> WithHiding a
WithHiding Hiding
forall a. Monoid a => a
mempty
  WithHiding Hiding
h a -> b
f <*> :: forall a b. WithHiding (a -> b) -> WithHiding a -> WithHiding b
<*> WithHiding Hiding
h' a
a = Hiding -> b -> WithHiding b
forall a. Hiding -> a -> WithHiding a
WithHiding (Hiding -> Hiding -> Hiding
forall a. Monoid a => a -> a -> a
mappend Hiding
h Hiding
h') (a -> b
f a
a)

instance HasRange a => HasRange (WithHiding a) where
  getRange :: WithHiding a -> Range
getRange = a -> Range
forall a. HasRange a => a -> Range
getRange (a -> Range) -> (WithHiding a -> a) -> WithHiding a -> Range
forall b c a. (b -> c) -> (a -> b) -> a -> c
. WithHiding a -> a
forall (t :: * -> *) a. Decoration t => t a -> a
dget

instance SetRange a => SetRange (WithHiding a) where
  setRange :: Range -> WithHiding a -> WithHiding a
setRange = (a -> a) -> WithHiding a -> WithHiding a
forall a b. (a -> b) -> WithHiding a -> WithHiding b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap ((a -> a) -> WithHiding a -> WithHiding a)
-> (Range -> a -> a) -> Range -> WithHiding a -> WithHiding a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Range -> a -> a
forall a. SetRange a => Range -> a -> a
setRange

instance KillRange a => KillRange (WithHiding a) where
  killRange :: KillRangeT (WithHiding a)
killRange = (a -> a) -> KillRangeT (WithHiding a)
forall a b. (a -> b) -> WithHiding a -> WithHiding b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap a -> a
forall a. KillRange a => KillRangeT a
killRange

instance NFData a => NFData (WithHiding a) where
  rnf :: WithHiding a -> ()
rnf (WithHiding Hiding
_ a
a) = a -> ()
forall a. NFData a => a -> ()
rnf a
a

-- | A lens to access the 'Hiding' attribute in data structures.
--   Minimal implementation: @getHiding@ and @mapHiding@ or @LensArgInfo@.
class LensHiding a where

  getHiding :: a -> Hiding

  setHiding :: Hiding -> a -> a
  setHiding Hiding
h = (Hiding -> Hiding) -> a -> a
forall a. LensHiding a => (Hiding -> Hiding) -> a -> a
mapHiding (Hiding -> Hiding -> Hiding
forall a b. a -> b -> a
const Hiding
h)

  mapHiding :: (Hiding -> Hiding) -> a -> a

  default getHiding :: LensArgInfo a => a -> Hiding
  getHiding = ArgInfo -> Hiding
argInfoHiding (ArgInfo -> Hiding) -> (a -> ArgInfo) -> a -> Hiding
forall b c a. (b -> c) -> (a -> b) -> a -> c
. a -> ArgInfo
forall a. LensArgInfo a => a -> ArgInfo
getArgInfo

  default mapHiding :: LensArgInfo a => (Hiding -> Hiding) -> a -> a
  mapHiding Hiding -> Hiding
f = (ArgInfo -> ArgInfo) -> a -> a
forall a. LensArgInfo a => (ArgInfo -> ArgInfo) -> a -> a
mapArgInfo ((ArgInfo -> ArgInfo) -> a -> a) -> (ArgInfo -> ArgInfo) -> a -> a
forall a b. (a -> b) -> a -> b
$ \ ArgInfo
ai -> ArgInfo
ai { argInfoHiding = f $ argInfoHiding ai }

instance LensHiding Hiding where
  getHiding :: Hiding -> Hiding
getHiding = Hiding -> Hiding
forall a. a -> a
id
  setHiding :: Hiding -> Hiding -> Hiding
setHiding = Hiding -> Hiding -> Hiding
forall a b. a -> b -> a
const
  mapHiding :: (Hiding -> Hiding) -> Hiding -> Hiding
mapHiding = (Hiding -> Hiding) -> Hiding -> Hiding
forall a. a -> a
id

instance LensHiding (WithHiding a) where
  getHiding :: WithHiding a -> Hiding
getHiding   (WithHiding Hiding
h a
_) = Hiding
h
  setHiding :: Hiding -> WithHiding a -> WithHiding a
setHiding Hiding
h (WithHiding Hiding
_ a
a) = Hiding -> a -> WithHiding a
forall a. Hiding -> a -> WithHiding a
WithHiding Hiding
h a
a
  mapHiding :: (Hiding -> Hiding) -> WithHiding a -> WithHiding a
mapHiding Hiding -> Hiding
f (WithHiding Hiding
h a
a) = Hiding -> a -> WithHiding a
forall a. Hiding -> a -> WithHiding a
WithHiding (Hiding -> Hiding
f Hiding
h) a
a

instance LensHiding a => LensHiding (Named nm a) where
  getHiding :: Named nm a -> Hiding
getHiding = a -> Hiding
forall a. LensHiding a => a -> Hiding
getHiding (a -> Hiding) -> (Named nm a -> a) -> Named nm a -> Hiding
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Named nm a -> a
forall name a. Named name a -> a
namedThing
  setHiding :: Hiding -> Named nm a -> Named nm a
setHiding = (a -> a) -> Named nm a -> Named nm a
forall a b. (a -> b) -> Named nm a -> Named nm b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap ((a -> a) -> Named nm a -> Named nm a)
-> (Hiding -> a -> a) -> Hiding -> Named nm a -> Named nm a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Hiding -> a -> a
forall a. LensHiding a => Hiding -> a -> a
setHiding
  mapHiding :: (Hiding -> Hiding) -> Named nm a -> Named nm a
mapHiding = (a -> a) -> Named nm a -> Named nm a
forall a b. (a -> b) -> Named nm a -> Named nm b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap ((a -> a) -> Named nm a -> Named nm a)
-> ((Hiding -> Hiding) -> a -> a)
-> (Hiding -> Hiding)
-> Named nm a
-> Named nm a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Hiding -> Hiding) -> a -> a
forall a. LensHiding a => (Hiding -> Hiding) -> a -> a
mapHiding

-- | Monoidal composition of 'Hiding' information in some data.
mergeHiding :: LensHiding a => WithHiding a -> a
mergeHiding :: forall a. LensHiding a => WithHiding a -> a
mergeHiding (WithHiding Hiding
h a
a) = (Hiding -> Hiding) -> a -> a
forall a. LensHiding a => (Hiding -> Hiding) -> a -> a
mapHiding (Hiding -> Hiding -> Hiding
forall a. Monoid a => a -> a -> a
mappend Hiding
h) a
a

-- | 'NotHidden' arguments are @visible@.
visible :: LensHiding a => a -> Bool
visible :: forall a. LensHiding a => a -> Bool
visible a
a = a -> Hiding
forall a. LensHiding a => a -> Hiding
getHiding a
a Hiding -> Hiding -> Bool
forall a. Eq a => a -> a -> Bool
== Hiding
NotHidden

-- | 'Instance' and 'Hidden' arguments are @notVisible@.
notVisible :: LensHiding a => a -> Bool
notVisible :: forall a. LensHiding a => a -> Bool
notVisible a
a = a -> Hiding
forall a. LensHiding a => a -> Hiding
getHiding a
a Hiding -> Hiding -> Bool
forall a. Eq a => a -> a -> Bool
/= Hiding
NotHidden

-- | 'Hidden' arguments are @hidden@.
hidden :: LensHiding a => a -> Bool
hidden :: forall a. LensHiding a => a -> Bool
hidden a
a = a -> Hiding
forall a. LensHiding a => a -> Hiding
getHiding a
a Hiding -> Hiding -> Bool
forall a. Eq a => a -> a -> Bool
== Hiding
Hidden

hide :: LensHiding a => a -> a
hide :: forall a. LensHiding a => a -> a
hide = Hiding -> a -> a
forall a. LensHiding a => Hiding -> a -> a
setHiding Hiding
Hidden

hideOrKeepInstance :: LensHiding a => a -> a
hideOrKeepInstance :: forall a. LensHiding a => a -> a
hideOrKeepInstance a
x =
  case a -> Hiding
forall a. LensHiding a => a -> Hiding
getHiding a
x of
    Hiding
Hidden     -> a
x
    Instance{} -> a
x
    Hiding
NotHidden  -> Hiding -> a -> a
forall a. LensHiding a => Hiding -> a -> a
setHiding Hiding
Hidden a
x

makeInstance :: LensHiding a => a -> a
makeInstance :: forall a. LensHiding a => a -> a
makeInstance = Overlappable -> a -> a
forall a. LensHiding a => Overlappable -> a -> a
makeInstance' Overlappable
NoOverlap

makeInstance' :: LensHiding a => Overlappable -> a -> a
makeInstance' :: forall a. LensHiding a => Overlappable -> a -> a
makeInstance' Overlappable
o = Hiding -> a -> a
forall a. LensHiding a => Hiding -> a -> a
setHiding (Overlappable -> Hiding
Instance Overlappable
o)

isOverlappable :: LensHiding a => a -> Bool
isOverlappable :: forall a. LensHiding a => a -> Bool
isOverlappable a
x =
  case a -> Hiding
forall a. LensHiding a => a -> Hiding
getHiding a
x of
    Instance Overlappable
YesOverlap -> Bool
True
    Hiding
_ -> Bool
False

isInstance :: LensHiding a => a -> Bool
isInstance :: forall a. LensHiding a => a -> Bool
isInstance a
x =
  case a -> Hiding
forall a. LensHiding a => a -> Hiding
getHiding a
x of
    Instance{} -> Bool
True
    Hiding
_          -> Bool
False

-- | Ignores 'Overlappable'.
sameHiding :: (LensHiding a, LensHiding b) => a -> b -> Bool
sameHiding :: forall a b. (LensHiding a, LensHiding b) => a -> b -> Bool
sameHiding a
x b
y =
  case (a -> Hiding
forall a. LensHiding a => a -> Hiding
getHiding a
x, b -> Hiding
forall a. LensHiding a => a -> Hiding
getHiding b
y) of
    (Instance{}, Instance{}) -> Bool
True
    (Hiding
hx, Hiding
hy)                 -> Hiding
hx Hiding -> Hiding -> Bool
forall a. Eq a => a -> a -> Bool
== Hiding
hy

---------------------------------------------------------------------------
-- * Modalities
---------------------------------------------------------------------------

-- | Type wrapper to indicate additive monoid/semigroup context.
newtype UnderAddition t = UnderAddition t deriving (Int -> UnderAddition t -> ShowS
[UnderAddition t] -> ShowS
UnderAddition t -> ArgName
(Int -> UnderAddition t -> ShowS)
-> (UnderAddition t -> ArgName)
-> ([UnderAddition t] -> ShowS)
-> Show (UnderAddition t)
forall t. Show t => Int -> UnderAddition t -> ShowS
forall t. Show t => [UnderAddition t] -> ShowS
forall t. Show t => UnderAddition t -> ArgName
forall a.
(Int -> a -> ShowS) -> (a -> ArgName) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: forall t. Show t => Int -> UnderAddition t -> ShowS
showsPrec :: Int -> UnderAddition t -> ShowS
$cshow :: forall t. Show t => UnderAddition t -> ArgName
show :: UnderAddition t -> ArgName
$cshowList :: forall t. Show t => [UnderAddition t] -> ShowS
showList :: [UnderAddition t] -> ShowS
Show, (forall a b. (a -> b) -> UnderAddition a -> UnderAddition b)
-> (forall a b. a -> UnderAddition b -> UnderAddition a)
-> Functor UnderAddition
forall a b. a -> UnderAddition b -> UnderAddition a
forall a b. (a -> b) -> UnderAddition a -> UnderAddition b
forall (f :: * -> *).
(forall a b. (a -> b) -> f a -> f b)
-> (forall a b. a -> f b -> f a) -> Functor f
$cfmap :: forall a b. (a -> b) -> UnderAddition a -> UnderAddition b
fmap :: forall a b. (a -> b) -> UnderAddition a -> UnderAddition b
$c<$ :: forall a b. a -> UnderAddition b -> UnderAddition a
<$ :: forall a b. a -> UnderAddition b -> UnderAddition a
Functor, UnderAddition t -> UnderAddition t -> Bool
(UnderAddition t -> UnderAddition t -> Bool)
-> (UnderAddition t -> UnderAddition t -> Bool)
-> Eq (UnderAddition t)
forall t. Eq t => UnderAddition t -> UnderAddition t -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: forall t. Eq t => UnderAddition t -> UnderAddition t -> Bool
== :: UnderAddition t -> UnderAddition t -> Bool
$c/= :: forall t. Eq t => UnderAddition t -> UnderAddition t -> Bool
/= :: UnderAddition t -> UnderAddition t -> Bool
Eq, Eq (UnderAddition t)
Eq (UnderAddition t) =>
(UnderAddition t -> UnderAddition t -> Ordering)
-> (UnderAddition t -> UnderAddition t -> Bool)
-> (UnderAddition t -> UnderAddition t -> Bool)
-> (UnderAddition t -> UnderAddition t -> Bool)
-> (UnderAddition t -> UnderAddition t -> Bool)
-> (UnderAddition t -> UnderAddition t -> UnderAddition t)
-> (UnderAddition t -> UnderAddition t -> UnderAddition t)
-> Ord (UnderAddition t)
UnderAddition t -> UnderAddition t -> Bool
UnderAddition t -> UnderAddition t -> Ordering
UnderAddition t -> UnderAddition t -> UnderAddition t
forall a.
Eq a =>
(a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
forall t. Ord t => Eq (UnderAddition t)
forall t. Ord t => UnderAddition t -> UnderAddition t -> Bool
forall t. Ord t => UnderAddition t -> UnderAddition t -> Ordering
forall t.
Ord t =>
UnderAddition t -> UnderAddition t -> UnderAddition t
$ccompare :: forall t. Ord t => UnderAddition t -> UnderAddition t -> Ordering
compare :: UnderAddition t -> UnderAddition t -> Ordering
$c< :: forall t. Ord t => UnderAddition t -> UnderAddition t -> Bool
< :: UnderAddition t -> UnderAddition t -> Bool
$c<= :: forall t. Ord t => UnderAddition t -> UnderAddition t -> Bool
<= :: UnderAddition t -> UnderAddition t -> Bool
$c> :: forall t. Ord t => UnderAddition t -> UnderAddition t -> Bool
> :: UnderAddition t -> UnderAddition t -> Bool
$c>= :: forall t. Ord t => UnderAddition t -> UnderAddition t -> Bool
>= :: UnderAddition t -> UnderAddition t -> Bool
$cmax :: forall t.
Ord t =>
UnderAddition t -> UnderAddition t -> UnderAddition t
max :: UnderAddition t -> UnderAddition t -> UnderAddition t
$cmin :: forall t.
Ord t =>
UnderAddition t -> UnderAddition t -> UnderAddition t
min :: UnderAddition t -> UnderAddition t -> UnderAddition t
Ord, Comparable (UnderAddition t)
Comparable (UnderAddition t) -> PartialOrd (UnderAddition t)
forall t. PartialOrd t => Comparable (UnderAddition t)
forall a. Comparable a -> PartialOrd a
$ccomparable :: forall t. PartialOrd t => Comparable (UnderAddition t)
comparable :: Comparable (UnderAddition t)
PartialOrd)

instance Applicative UnderAddition where
  pure :: forall a. a -> UnderAddition a
pure = a -> UnderAddition a
forall a. a -> UnderAddition a
UnderAddition
  <*> :: forall a b.
UnderAddition (a -> b) -> UnderAddition a -> UnderAddition b
(<*>) (UnderAddition a -> b
f) (UnderAddition a
a) = b -> UnderAddition b
forall a. a -> UnderAddition a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (a -> b
f a
a)

-- | Type wrapper to indicate composition or multiplicative monoid/semigroup context.
newtype UnderComposition t = UnderComposition t deriving (Int -> UnderComposition t -> ShowS
[UnderComposition t] -> ShowS
UnderComposition t -> ArgName
(Int -> UnderComposition t -> ShowS)
-> (UnderComposition t -> ArgName)
-> ([UnderComposition t] -> ShowS)
-> Show (UnderComposition t)
forall t. Show t => Int -> UnderComposition t -> ShowS
forall t. Show t => [UnderComposition t] -> ShowS
forall t. Show t => UnderComposition t -> ArgName
forall a.
(Int -> a -> ShowS) -> (a -> ArgName) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: forall t. Show t => Int -> UnderComposition t -> ShowS
showsPrec :: Int -> UnderComposition t -> ShowS
$cshow :: forall t. Show t => UnderComposition t -> ArgName
show :: UnderComposition t -> ArgName
$cshowList :: forall t. Show t => [UnderComposition t] -> ShowS
showList :: [UnderComposition t] -> ShowS
Show, (forall a b. (a -> b) -> UnderComposition a -> UnderComposition b)
-> (forall a b. a -> UnderComposition b -> UnderComposition a)
-> Functor UnderComposition
forall a b. a -> UnderComposition b -> UnderComposition a
forall a b. (a -> b) -> UnderComposition a -> UnderComposition b
forall (f :: * -> *).
(forall a b. (a -> b) -> f a -> f b)
-> (forall a b. a -> f b -> f a) -> Functor f
$cfmap :: forall a b. (a -> b) -> UnderComposition a -> UnderComposition b
fmap :: forall a b. (a -> b) -> UnderComposition a -> UnderComposition b
$c<$ :: forall a b. a -> UnderComposition b -> UnderComposition a
<$ :: forall a b. a -> UnderComposition b -> UnderComposition a
Functor, UnderComposition t -> UnderComposition t -> Bool
(UnderComposition t -> UnderComposition t -> Bool)
-> (UnderComposition t -> UnderComposition t -> Bool)
-> Eq (UnderComposition t)
forall t. Eq t => UnderComposition t -> UnderComposition t -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: forall t. Eq t => UnderComposition t -> UnderComposition t -> Bool
== :: UnderComposition t -> UnderComposition t -> Bool
$c/= :: forall t. Eq t => UnderComposition t -> UnderComposition t -> Bool
/= :: UnderComposition t -> UnderComposition t -> Bool
Eq, Eq (UnderComposition t)
Eq (UnderComposition t) =>
(UnderComposition t -> UnderComposition t -> Ordering)
-> (UnderComposition t -> UnderComposition t -> Bool)
-> (UnderComposition t -> UnderComposition t -> Bool)
-> (UnderComposition t -> UnderComposition t -> Bool)
-> (UnderComposition t -> UnderComposition t -> Bool)
-> (UnderComposition t -> UnderComposition t -> UnderComposition t)
-> (UnderComposition t -> UnderComposition t -> UnderComposition t)
-> Ord (UnderComposition t)
UnderComposition t -> UnderComposition t -> Bool
UnderComposition t -> UnderComposition t -> Ordering
UnderComposition t -> UnderComposition t -> UnderComposition t
forall a.
Eq a =>
(a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
forall t. Ord t => Eq (UnderComposition t)
forall t. Ord t => UnderComposition t -> UnderComposition t -> Bool
forall t.
Ord t =>
UnderComposition t -> UnderComposition t -> Ordering
forall t.
Ord t =>
UnderComposition t -> UnderComposition t -> UnderComposition t
$ccompare :: forall t.
Ord t =>
UnderComposition t -> UnderComposition t -> Ordering
compare :: UnderComposition t -> UnderComposition t -> Ordering
$c< :: forall t. Ord t => UnderComposition t -> UnderComposition t -> Bool
< :: UnderComposition t -> UnderComposition t -> Bool
$c<= :: forall t. Ord t => UnderComposition t -> UnderComposition t -> Bool
<= :: UnderComposition t -> UnderComposition t -> Bool
$c> :: forall t. Ord t => UnderComposition t -> UnderComposition t -> Bool
> :: UnderComposition t -> UnderComposition t -> Bool
$c>= :: forall t. Ord t => UnderComposition t -> UnderComposition t -> Bool
>= :: UnderComposition t -> UnderComposition t -> Bool
$cmax :: forall t.
Ord t =>
UnderComposition t -> UnderComposition t -> UnderComposition t
max :: UnderComposition t -> UnderComposition t -> UnderComposition t
$cmin :: forall t.
Ord t =>
UnderComposition t -> UnderComposition t -> UnderComposition t
min :: UnderComposition t -> UnderComposition t -> UnderComposition t
Ord, Comparable (UnderComposition t)
Comparable (UnderComposition t) -> PartialOrd (UnderComposition t)
forall t. PartialOrd t => Comparable (UnderComposition t)
forall a. Comparable a -> PartialOrd a
$ccomparable :: forall t. PartialOrd t => Comparable (UnderComposition t)
comparable :: Comparable (UnderComposition t)
PartialOrd)

instance Applicative UnderComposition where
  pure :: forall a. a -> UnderComposition a
pure = a -> UnderComposition a
forall a. a -> UnderComposition a
UnderComposition
  <*> :: forall a b.
UnderComposition (a -> b)
-> UnderComposition a -> UnderComposition b
(<*>) (UnderComposition a -> b
f) (UnderComposition a
a) = b -> UnderComposition b
forall a. a -> UnderComposition a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (a -> b
f a
a)

-- | We have a tuple of modalities, which might not be fully orthogonal.
--   For instance, irrelevant stuff is also run-time irrelevant.
data Modality = Modality
  { Modality -> Relevance
modRelevance :: Relevance
      -- ^ Legacy irrelevance.
      --   See Pfenning, LiCS 2001; Abel/Vezzosi/Winterhalter, ICFP 2017.
  , Modality -> Quantity
modQuantity  :: Quantity
      -- ^ Cardinality / runtime erasure.
      --   See Conor McBride, I got plenty o' nutting, Wadlerfest 2016.
      --   See Bob Atkey, Syntax and Semantics of Quantitative Type Theory, LiCS 2018.
  , Modality -> Cohesion
modCohesion :: Cohesion
      -- ^ Cohesion/what was in Agda-flat.
      --   see "Brouwer's fixed-point theorem in real-cohesive homotopy type theory" (arXiv:1509.07584)
      --   Currently only the comonad is implemented.
  } deriving (Modality -> Modality -> Bool
(Modality -> Modality -> Bool)
-> (Modality -> Modality -> Bool) -> Eq Modality
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: Modality -> Modality -> Bool
== :: Modality -> Modality -> Bool
$c/= :: Modality -> Modality -> Bool
/= :: Modality -> Modality -> Bool
Eq, Eq Modality
Eq Modality =>
(Modality -> Modality -> Ordering)
-> (Modality -> Modality -> Bool)
-> (Modality -> Modality -> Bool)
-> (Modality -> Modality -> Bool)
-> (Modality -> Modality -> Bool)
-> (Modality -> Modality -> Modality)
-> (Modality -> Modality -> Modality)
-> Ord Modality
Modality -> Modality -> Bool
Modality -> Modality -> Ordering
Modality -> Modality -> Modality
forall a.
Eq a =>
(a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
$ccompare :: Modality -> Modality -> Ordering
compare :: Modality -> Modality -> Ordering
$c< :: Modality -> Modality -> Bool
< :: Modality -> Modality -> Bool
$c<= :: Modality -> Modality -> Bool
<= :: Modality -> Modality -> Bool
$c> :: Modality -> Modality -> Bool
> :: Modality -> Modality -> Bool
$c>= :: Modality -> Modality -> Bool
>= :: Modality -> Modality -> Bool
$cmax :: Modality -> Modality -> Modality
max :: Modality -> Modality -> Modality
$cmin :: Modality -> Modality -> Modality
min :: Modality -> Modality -> Modality
Ord, Int -> Modality -> ShowS
[Modality] -> ShowS
Modality -> ArgName
(Int -> Modality -> ShowS)
-> (Modality -> ArgName) -> ([Modality] -> ShowS) -> Show Modality
forall a.
(Int -> a -> ShowS) -> (a -> ArgName) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> Modality -> ShowS
showsPrec :: Int -> Modality -> ShowS
$cshow :: Modality -> ArgName
show :: Modality -> ArgName
$cshowList :: [Modality] -> ShowS
showList :: [Modality] -> ShowS
Show, (forall x. Modality -> Rep Modality x)
-> (forall x. Rep Modality x -> Modality) -> Generic Modality
forall x. Rep Modality x -> Modality
forall x. Modality -> Rep Modality x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cfrom :: forall x. Modality -> Rep Modality x
from :: forall x. Modality -> Rep Modality x
$cto :: forall x. Rep Modality x -> Modality
to :: forall x. Rep Modality x -> Modality
Generic)

-- | Dominance ordering.
instance PartialOrd Modality where
  comparable :: Comparable Modality
comparable (Modality Relevance
r Quantity
q Cohesion
c) (Modality Relevance
r' Quantity
q' Cohesion
c') = Comparable (Relevance, (Quantity, Cohesion))
forall a. PartialOrd a => Comparable a
comparable (Relevance
r, (Quantity
q, Cohesion
c)) (Relevance
r', (Quantity
q', Cohesion
c'))

-- | Pointwise composition.
instance Semigroup (UnderComposition Modality) where
  <> :: UnderComposition Modality
-> UnderComposition Modality -> UnderComposition Modality
(<>) = (Modality -> Modality -> Modality)
-> UnderComposition Modality
-> UnderComposition Modality
-> UnderComposition Modality
forall a b c.
(a -> b -> c)
-> UnderComposition a -> UnderComposition b -> UnderComposition c
forall (f :: * -> *) a b c.
Applicative f =>
(a -> b -> c) -> f a -> f b -> f c
liftA2 Modality -> Modality -> Modality
composeModality

-- | Pointwise composition unit.
instance Monoid (UnderComposition Modality) where
  mempty :: UnderComposition Modality
mempty  = Modality -> UnderComposition Modality
forall a. a -> UnderComposition a
forall (f :: * -> *) a. Applicative f => a -> f a
pure Modality
unitModality
  mappend :: UnderComposition Modality
-> UnderComposition Modality -> UnderComposition Modality
mappend = UnderComposition Modality
-> UnderComposition Modality -> UnderComposition Modality
forall a. Semigroup a => a -> a -> a
(<>)

instance POSemigroup (UnderComposition Modality) where
instance POMonoid (UnderComposition Modality) where

instance LeftClosedPOMonoid (UnderComposition Modality) where
  inverseCompose :: UnderComposition Modality
-> UnderComposition Modality -> UnderComposition Modality
inverseCompose = (Modality -> Modality -> Modality)
-> UnderComposition Modality
-> UnderComposition Modality
-> UnderComposition Modality
forall a b c.
(a -> b -> c)
-> UnderComposition a -> UnderComposition b -> UnderComposition c
forall (f :: * -> *) a b c.
Applicative f =>
(a -> b -> c) -> f a -> f b -> f c
liftA2 Modality -> Modality -> Modality
inverseComposeModality

-- | Pointwise addition.
instance Semigroup (UnderAddition Modality) where
  <> :: UnderAddition Modality
-> UnderAddition Modality -> UnderAddition Modality
(<>) = (Modality -> Modality -> Modality)
-> UnderAddition Modality
-> UnderAddition Modality
-> UnderAddition Modality
forall a b c.
(a -> b -> c)
-> UnderAddition a -> UnderAddition b -> UnderAddition c
forall (f :: * -> *) a b c.
Applicative f =>
(a -> b -> c) -> f a -> f b -> f c
liftA2 Modality -> Modality -> Modality
addModality

-- | Pointwise additive unit.
instance Monoid (UnderAddition Modality) where
  mempty :: UnderAddition Modality
mempty  = Modality -> UnderAddition Modality
forall a. a -> UnderAddition a
forall (f :: * -> *) a. Applicative f => a -> f a
pure Modality
zeroModality
  mappend :: UnderAddition Modality
-> UnderAddition Modality -> UnderAddition Modality
mappend = UnderAddition Modality
-> UnderAddition Modality -> UnderAddition Modality
forall a. Semigroup a => a -> a -> a
(<>)

instance POSemigroup (UnderAddition Modality) where
instance POMonoid (UnderAddition Modality) where

-- | @m `moreUsableModality` m'@ means that an @m@ can be used
--   where ever an @m'@ is required.

moreUsableModality :: Modality -> Modality -> Bool
moreUsableModality :: Modality -> Modality -> Bool
moreUsableModality Modality
m Modality
m' = Modality -> PartialOrdering -> Modality -> Bool
forall a. PartialOrd a => a -> PartialOrdering -> a -> Bool
related Modality
m PartialOrdering
POLE Modality
m'

usableModality :: LensModality a => a -> Bool
usableModality :: forall a. LensModality a => a -> Bool
usableModality a
a = Modality -> Bool
forall a. LensRelevance a => a -> Bool
usableRelevance Modality
m Bool -> Bool -> Bool
&& Modality -> Bool
forall a. LensQuantity a => a -> Bool
usableQuantity Modality
m Bool -> Bool -> Bool
&& Modality -> Bool
forall a. LensCohesion a => a -> Bool
usableCohesion Modality
m
  where m :: Modality
m = a -> Modality
forall a. LensModality a => a -> Modality
getModality a
a

-- | Multiplicative monoid (standard monoid).
composeModality :: Modality -> Modality -> Modality
composeModality :: Modality -> Modality -> Modality
composeModality (Modality Relevance
r Quantity
q Cohesion
c) (Modality Relevance
r' Quantity
q' Cohesion
c') =
    Relevance -> Quantity -> Cohesion -> Modality
Modality (Relevance
r Relevance -> Relevance -> Relevance
`composeRelevance` Relevance
r')
             (Quantity
q Quantity -> Quantity -> Quantity
`composeQuantity` Quantity
q')
             (Cohesion
c Cohesion -> Cohesion -> Cohesion
`composeCohesion` Cohesion
c')

-- | Compose with modality flag from the left.
--   This function is e.g. used to update the modality information
--   on pattern variables @a@ after a match against something of modality @q@.
applyModality :: LensModality a => Modality -> a -> a
applyModality :: forall a. LensModality a => Modality -> a -> a
applyModality Modality
m = (Modality -> Modality) -> a -> a
forall a. LensModality a => (Modality -> Modality) -> a -> a
mapModality (Modality
m Modality -> Modality -> Modality
`composeModality`)

-- | @inverseComposeModality r x@ returns the least modality @y@
--   such that forall @x@, @y@ we have
--   @x \`moreUsableModality\` (r \`composeModality\` y)@
--   iff
--   @(r \`inverseComposeModality\` x) \`moreUsableModality\` y@ (Galois connection).
inverseComposeModality :: Modality -> Modality -> Modality
inverseComposeModality :: Modality -> Modality -> Modality
inverseComposeModality (Modality Relevance
r Quantity
q Cohesion
c) (Modality Relevance
r' Quantity
q' Cohesion
c') =
  Relevance -> Quantity -> Cohesion -> Modality
Modality (Relevance
r Relevance -> Relevance -> Relevance
`inverseComposeRelevance` Relevance
r')
           (Quantity
q Quantity -> Quantity -> Quantity
`inverseComposeQuantity`  Quantity
q')
           (Cohesion
c Cohesion -> Cohesion -> Cohesion
`inverseComposeCohesion`  Cohesion
c')

-- | Left division by a 'Modality'.
--   Used e.g. to modify context when going into a @m@ argument.
--
-- Note that this function does not change quantities.
inverseApplyModalityButNotQuantity :: LensModality a => Modality -> a -> a
inverseApplyModalityButNotQuantity :: forall a. LensModality a => Modality -> a -> a
inverseApplyModalityButNotQuantity Modality
m =
  (Modality -> Modality) -> a -> a
forall a. LensModality a => (Modality -> Modality) -> a -> a
mapModality (Modality
m' Modality -> Modality -> Modality
`inverseComposeModality`)
  where
  m' :: Modality
m' = Quantity -> Modality -> Modality
forall a. LensQuantity a => Quantity -> a -> a
setQuantity (Q1Origin -> Quantity
Quantity1 Q1Origin
Q1Inferred) Modality
m

-- | 'Modality' forms a pointwise additive monoid.
addModality :: Modality -> Modality -> Modality
addModality :: Modality -> Modality -> Modality
addModality (Modality Relevance
r Quantity
q Cohesion
c) (Modality Relevance
r' Quantity
q' Cohesion
c') = Relevance -> Quantity -> Cohesion -> Modality
Modality (Relevance -> Relevance -> Relevance
addRelevance Relevance
r Relevance
r') (Quantity -> Quantity -> Quantity
addQuantity Quantity
q Quantity
q') (Cohesion -> Cohesion -> Cohesion
addCohesion Cohesion
c Cohesion
c')

-- | Identity under addition
zeroModality :: Modality
zeroModality :: Modality
zeroModality = Relevance -> Quantity -> Cohesion -> Modality
Modality Relevance
zeroRelevance Quantity
zeroQuantity Cohesion
zeroCohesion

-- | Identity under composition
unitModality :: Modality
unitModality :: Modality
unitModality = Relevance -> Quantity -> Cohesion -> Modality
Modality Relevance
unitRelevance Quantity
unitQuantity Cohesion
unitCohesion

-- | Absorptive element under addition.
topModality :: Modality
topModality :: Modality
topModality = Relevance -> Quantity -> Cohesion -> Modality
Modality Relevance
topRelevance Quantity
topQuantity Cohesion
topCohesion

-- | The default Modality
--   Beware that this is neither the additive unit nor the unit under
--   composition, because the default quantity is ω.
defaultModality :: Modality
defaultModality :: Modality
defaultModality = Relevance -> Quantity -> Cohesion -> Modality
Modality Relevance
defaultRelevance Quantity
defaultQuantity Cohesion
defaultCohesion

-- | Equality ignoring origin.

sameModality :: (LensModality a, LensModality b) => a -> b -> Bool
sameModality :: forall a b. (LensModality a, LensModality b) => a -> b -> Bool
sameModality a
x b
y = case (a -> Modality
forall a. LensModality a => a -> Modality
getModality a
x , b -> Modality
forall a. LensModality a => a -> Modality
getModality b
y) of
  (Modality Relevance
r Quantity
q Cohesion
c , Modality Relevance
r' Quantity
q' Cohesion
c') -> Relevance -> Relevance -> Bool
sameRelevance Relevance
r Relevance
r' Bool -> Bool -> Bool
&& Quantity -> Quantity -> Bool
sameQuantity Quantity
q Quantity
q' Bool -> Bool -> Bool
&& Cohesion -> Cohesion -> Bool
sameCohesion Cohesion
c Cohesion
c'

-- boilerplate instances

instance HasRange Modality where
  getRange :: Modality -> Range
getRange (Modality Relevance
r Quantity
q Cohesion
c) = (Relevance, Quantity, Cohesion) -> Range
forall a. HasRange a => a -> Range
getRange (Relevance
r, Quantity
q, Cohesion
c)

instance KillRange Modality where
  killRange :: Modality -> Modality
killRange (Modality Relevance
r Quantity
q Cohesion
c) = (Relevance -> Quantity -> Cohesion -> Modality)
-> Relevance -> Quantity -> Cohesion -> Modality
forall t (b :: Bool).
(KILLRANGE t b, IsBase t ~ b, All KillRange (Domains t)) =>
t -> t
killRangeN Relevance -> Quantity -> Cohesion -> Modality
Modality Relevance
r Quantity
q Cohesion
c

instance NFData Modality where

-- Lens stuff

lModRelevance :: Lens' Modality Relevance
lModRelevance :: Lens' Modality Relevance
lModRelevance Relevance -> f Relevance
f Modality
m = Relevance -> f Relevance
f (Modality -> Relevance
modRelevance Modality
m) f Relevance -> (Relevance -> Modality) -> f Modality
forall (m :: * -> *) a b. Functor m => m a -> (a -> b) -> m b
<&> \ Relevance
r -> Modality
m { modRelevance = r }

lModQuantity :: Lens' Modality Quantity
lModQuantity :: Lens' Modality Quantity
lModQuantity Quantity -> f Quantity
f Modality
m = Quantity -> f Quantity
f (Modality -> Quantity
modQuantity Modality
m) f Quantity -> (Quantity -> Modality) -> f Modality
forall (m :: * -> *) a b. Functor m => m a -> (a -> b) -> m b
<&> \ Quantity
q -> Modality
m { modQuantity = q }

lModCohesion :: Lens' Modality Cohesion
lModCohesion :: Lens' Modality Cohesion
lModCohesion Cohesion -> f Cohesion
f Modality
m = Cohesion -> f Cohesion
f (Modality -> Cohesion
modCohesion Modality
m) f Cohesion -> (Cohesion -> Modality) -> f Modality
forall (m :: * -> *) a b. Functor m => m a -> (a -> b) -> m b
<&> \ Cohesion
q -> Modality
m { modCohesion = q }

class LensModality a where

  getModality :: a -> Modality

  setModality :: Modality -> a -> a
  setModality = (Modality -> Modality) -> a -> a
forall a. LensModality a => (Modality -> Modality) -> a -> a
mapModality ((Modality -> Modality) -> a -> a)
-> (Modality -> Modality -> Modality) -> Modality -> a -> a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Modality -> Modality -> Modality
forall a b. a -> b -> a
const

  mapModality :: (Modality -> Modality) -> a -> a

  default getModality :: LensArgInfo a => a -> Modality
  getModality = ArgInfo -> Modality
argInfoModality (ArgInfo -> Modality) -> (a -> ArgInfo) -> a -> Modality
forall b c a. (b -> c) -> (a -> b) -> a -> c
. a -> ArgInfo
forall a. LensArgInfo a => a -> ArgInfo
getArgInfo

  default mapModality :: LensArgInfo a => (Modality -> Modality) -> a -> a
  mapModality Modality -> Modality
f = (ArgInfo -> ArgInfo) -> a -> a
forall a. LensArgInfo a => (ArgInfo -> ArgInfo) -> a -> a
mapArgInfo ((ArgInfo -> ArgInfo) -> a -> a) -> (ArgInfo -> ArgInfo) -> a -> a
forall a b. (a -> b) -> a -> b
$ \ ArgInfo
ai -> ArgInfo
ai { argInfoModality = f $ argInfoModality ai }

instance LensModality Modality where
  getModality :: Modality -> Modality
getModality = Modality -> Modality
forall a. a -> a
id
  setModality :: Modality -> Modality -> Modality
setModality = Modality -> Modality -> Modality
forall a b. a -> b -> a
const
  mapModality :: (Modality -> Modality) -> Modality -> Modality
mapModality = (Modality -> Modality) -> Modality -> Modality
forall a. a -> a
id

instance LensRelevance Modality where
  getRelevance :: Modality -> Relevance
getRelevance = Modality -> Relevance
modRelevance
  setRelevance :: Relevance -> Modality -> Modality
setRelevance Relevance
h Modality
m = Modality
m { modRelevance = h }
  mapRelevance :: (Relevance -> Relevance) -> Modality -> Modality
mapRelevance Relevance -> Relevance
f Modality
m = Modality
m { modRelevance = f (modRelevance m) }

instance LensQuantity Modality where
  getQuantity :: Modality -> Quantity
getQuantity = Modality -> Quantity
modQuantity
  setQuantity :: Quantity -> Modality -> Modality
setQuantity Quantity
h Modality
m = Modality
m { modQuantity = h }
  mapQuantity :: (Quantity -> Quantity) -> Modality -> Modality
mapQuantity Quantity -> Quantity
f Modality
m = Modality
m { modQuantity = f (modQuantity m) }

instance LensCohesion Modality where
  getCohesion :: Modality -> Cohesion
getCohesion = Modality -> Cohesion
modCohesion
  setCohesion :: Cohesion -> Modality -> Modality
setCohesion Cohesion
h Modality
m = Modality
m { modCohesion = h }
  mapCohesion :: (Cohesion -> Cohesion) -> Modality -> Modality
mapCohesion Cohesion -> Cohesion
f Modality
m = Modality
m { modCohesion = f (modCohesion m) }

-- default accessors for Relevance

getRelevanceMod :: LensModality a => LensGet a Relevance
getRelevanceMod :: forall a. LensModality a => LensGet a Relevance
getRelevanceMod = Modality -> Relevance
forall a. LensRelevance a => a -> Relevance
getRelevance (Modality -> Relevance) -> (a -> Modality) -> a -> Relevance
forall b c a. (b -> c) -> (a -> b) -> a -> c
. a -> Modality
forall a. LensModality a => a -> Modality
getModality

setRelevanceMod :: LensModality a => LensSet a Relevance
setRelevanceMod :: forall a. LensModality a => LensSet a Relevance
setRelevanceMod = (Modality -> Modality) -> a -> a
forall a. LensModality a => (Modality -> Modality) -> a -> a
mapModality ((Modality -> Modality) -> a -> a)
-> (Relevance -> Modality -> Modality) -> Relevance -> a -> a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Relevance -> Modality -> Modality
forall a. LensRelevance a => Relevance -> a -> a
setRelevance

mapRelevanceMod :: LensModality a => LensMap a Relevance
mapRelevanceMod :: forall a. LensModality a => LensMap a Relevance
mapRelevanceMod = (Modality -> Modality) -> a -> a
forall a. LensModality a => (Modality -> Modality) -> a -> a
mapModality ((Modality -> Modality) -> a -> a)
-> ((Relevance -> Relevance) -> Modality -> Modality)
-> (Relevance -> Relevance)
-> a
-> a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Relevance -> Relevance) -> Modality -> Modality
forall a. LensRelevance a => (Relevance -> Relevance) -> a -> a
mapRelevance

-- default accessors for Quantity

getQuantityMod :: LensModality a => LensGet a Quantity
getQuantityMod :: forall a. LensModality a => LensGet a Quantity
getQuantityMod = Modality -> Quantity
forall a. LensQuantity a => a -> Quantity
getQuantity (Modality -> Quantity) -> (a -> Modality) -> a -> Quantity
forall b c a. (b -> c) -> (a -> b) -> a -> c
. a -> Modality
forall a. LensModality a => a -> Modality
getModality

setQuantityMod :: LensModality a => LensSet a Quantity
setQuantityMod :: forall a. LensModality a => LensSet a Quantity
setQuantityMod = (Modality -> Modality) -> a -> a
forall a. LensModality a => (Modality -> Modality) -> a -> a
mapModality ((Modality -> Modality) -> a -> a)
-> (Quantity -> Modality -> Modality) -> Quantity -> a -> a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Quantity -> Modality -> Modality
forall a. LensQuantity a => Quantity -> a -> a
setQuantity

mapQuantityMod :: LensModality a => LensMap a Quantity
mapQuantityMod :: forall a. LensModality a => LensMap a Quantity
mapQuantityMod = (Modality -> Modality) -> a -> a
forall a. LensModality a => (Modality -> Modality) -> a -> a
mapModality ((Modality -> Modality) -> a -> a)
-> ((Quantity -> Quantity) -> Modality -> Modality)
-> (Quantity -> Quantity)
-> a
-> a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Quantity -> Quantity) -> Modality -> Modality
forall a. LensQuantity a => (Quantity -> Quantity) -> a -> a
mapQuantity

-- default accessors for Cohesion

getCohesionMod :: LensModality a => LensGet a Cohesion
getCohesionMod :: forall a. LensModality a => LensGet a Cohesion
getCohesionMod = Modality -> Cohesion
forall a. LensCohesion a => a -> Cohesion
getCohesion (Modality -> Cohesion) -> (a -> Modality) -> a -> Cohesion
forall b c a. (b -> c) -> (a -> b) -> a -> c
. a -> Modality
forall a. LensModality a => a -> Modality
getModality

setCohesionMod :: LensModality a => LensSet a Cohesion
setCohesionMod :: forall a. LensModality a => LensSet a Cohesion
setCohesionMod = (Modality -> Modality) -> a -> a
forall a. LensModality a => (Modality -> Modality) -> a -> a
mapModality ((Modality -> Modality) -> a -> a)
-> (Cohesion -> Modality -> Modality) -> Cohesion -> a -> a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Cohesion -> Modality -> Modality
forall a. LensCohesion a => Cohesion -> a -> a
setCohesion

mapCohesionMod :: LensModality a => LensMap a Cohesion
mapCohesionMod :: forall a. LensModality a => LensMap a Cohesion
mapCohesionMod = (Modality -> Modality) -> a -> a
forall a. LensModality a => (Modality -> Modality) -> a -> a
mapModality ((Modality -> Modality) -> a -> a)
-> ((Cohesion -> Cohesion) -> Modality -> Modality)
-> (Cohesion -> Cohesion)
-> a
-> a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Cohesion -> Cohesion) -> Modality -> Modality
forall a. LensCohesion a => (Cohesion -> Cohesion) -> a -> a
mapCohesion

---------------------------------------------------------------------------
-- * Quantities
---------------------------------------------------------------------------

-- ** Quantity origin.

-- | Origin of 'Quantity0'.
data Q0Origin
  = Q0Inferred       -- ^ User wrote nothing.
  | Q0       Range   -- ^ User wrote "@0".
  | Q0Erased Range   -- ^ User wrote "@erased".
  deriving (Int -> Q0Origin -> ShowS
[Q0Origin] -> ShowS
Q0Origin -> ArgName
(Int -> Q0Origin -> ShowS)
-> (Q0Origin -> ArgName) -> ([Q0Origin] -> ShowS) -> Show Q0Origin
forall a.
(Int -> a -> ShowS) -> (a -> ArgName) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> Q0Origin -> ShowS
showsPrec :: Int -> Q0Origin -> ShowS
$cshow :: Q0Origin -> ArgName
show :: Q0Origin -> ArgName
$cshowList :: [Q0Origin] -> ShowS
showList :: [Q0Origin] -> ShowS
Show, (forall x. Q0Origin -> Rep Q0Origin x)
-> (forall x. Rep Q0Origin x -> Q0Origin) -> Generic Q0Origin
forall x. Rep Q0Origin x -> Q0Origin
forall x. Q0Origin -> Rep Q0Origin x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cfrom :: forall x. Q0Origin -> Rep Q0Origin x
from :: forall x. Q0Origin -> Rep Q0Origin x
$cto :: forall x. Rep Q0Origin x -> Q0Origin
to :: forall x. Rep Q0Origin x -> Q0Origin
Generic, Q0Origin -> Q0Origin -> Bool
(Q0Origin -> Q0Origin -> Bool)
-> (Q0Origin -> Q0Origin -> Bool) -> Eq Q0Origin
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: Q0Origin -> Q0Origin -> Bool
== :: Q0Origin -> Q0Origin -> Bool
$c/= :: Q0Origin -> Q0Origin -> Bool
/= :: Q0Origin -> Q0Origin -> Bool
Eq, Eq Q0Origin
Eq Q0Origin =>
(Q0Origin -> Q0Origin -> Ordering)
-> (Q0Origin -> Q0Origin -> Bool)
-> (Q0Origin -> Q0Origin -> Bool)
-> (Q0Origin -> Q0Origin -> Bool)
-> (Q0Origin -> Q0Origin -> Bool)
-> (Q0Origin -> Q0Origin -> Q0Origin)
-> (Q0Origin -> Q0Origin -> Q0Origin)
-> Ord Q0Origin
Q0Origin -> Q0Origin -> Bool
Q0Origin -> Q0Origin -> Ordering
Q0Origin -> Q0Origin -> Q0Origin
forall a.
Eq a =>
(a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
$ccompare :: Q0Origin -> Q0Origin -> Ordering
compare :: Q0Origin -> Q0Origin -> Ordering
$c< :: Q0Origin -> Q0Origin -> Bool
< :: Q0Origin -> Q0Origin -> Bool
$c<= :: Q0Origin -> Q0Origin -> Bool
<= :: Q0Origin -> Q0Origin -> Bool
$c> :: Q0Origin -> Q0Origin -> Bool
> :: Q0Origin -> Q0Origin -> Bool
$c>= :: Q0Origin -> Q0Origin -> Bool
>= :: Q0Origin -> Q0Origin -> Bool
$cmax :: Q0Origin -> Q0Origin -> Q0Origin
max :: Q0Origin -> Q0Origin -> Q0Origin
$cmin :: Q0Origin -> Q0Origin -> Q0Origin
min :: Q0Origin -> Q0Origin -> Q0Origin
Ord)

-- | Origin of 'Quantity1'.
data Q1Origin
  = Q1Inferred       -- ^ User wrote nothing.
  | Q1       Range   -- ^ User wrote "@1".
  | Q1Linear Range   -- ^ User wrote "@linear".
  deriving (Int -> Q1Origin -> ShowS
[Q1Origin] -> ShowS
Q1Origin -> ArgName
(Int -> Q1Origin -> ShowS)
-> (Q1Origin -> ArgName) -> ([Q1Origin] -> ShowS) -> Show Q1Origin
forall a.
(Int -> a -> ShowS) -> (a -> ArgName) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> Q1Origin -> ShowS
showsPrec :: Int -> Q1Origin -> ShowS
$cshow :: Q1Origin -> ArgName
show :: Q1Origin -> ArgName
$cshowList :: [Q1Origin] -> ShowS
showList :: [Q1Origin] -> ShowS
Show, (forall x. Q1Origin -> Rep Q1Origin x)
-> (forall x. Rep Q1Origin x -> Q1Origin) -> Generic Q1Origin
forall x. Rep Q1Origin x -> Q1Origin
forall x. Q1Origin -> Rep Q1Origin x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cfrom :: forall x. Q1Origin -> Rep Q1Origin x
from :: forall x. Q1Origin -> Rep Q1Origin x
$cto :: forall x. Rep Q1Origin x -> Q1Origin
to :: forall x. Rep Q1Origin x -> Q1Origin
Generic, Q1Origin -> Q1Origin -> Bool
(Q1Origin -> Q1Origin -> Bool)
-> (Q1Origin -> Q1Origin -> Bool) -> Eq Q1Origin
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: Q1Origin -> Q1Origin -> Bool
== :: Q1Origin -> Q1Origin -> Bool
$c/= :: Q1Origin -> Q1Origin -> Bool
/= :: Q1Origin -> Q1Origin -> Bool
Eq, Eq Q1Origin
Eq Q1Origin =>
(Q1Origin -> Q1Origin -> Ordering)
-> (Q1Origin -> Q1Origin -> Bool)
-> (Q1Origin -> Q1Origin -> Bool)
-> (Q1Origin -> Q1Origin -> Bool)
-> (Q1Origin -> Q1Origin -> Bool)
-> (Q1Origin -> Q1Origin -> Q1Origin)
-> (Q1Origin -> Q1Origin -> Q1Origin)
-> Ord Q1Origin
Q1Origin -> Q1Origin -> Bool
Q1Origin -> Q1Origin -> Ordering
Q1Origin -> Q1Origin -> Q1Origin
forall a.
Eq a =>
(a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
$ccompare :: Q1Origin -> Q1Origin -> Ordering
compare :: Q1Origin -> Q1Origin -> Ordering
$c< :: Q1Origin -> Q1Origin -> Bool
< :: Q1Origin -> Q1Origin -> Bool
$c<= :: Q1Origin -> Q1Origin -> Bool
<= :: Q1Origin -> Q1Origin -> Bool
$c> :: Q1Origin -> Q1Origin -> Bool
> :: Q1Origin -> Q1Origin -> Bool
$c>= :: Q1Origin -> Q1Origin -> Bool
>= :: Q1Origin -> Q1Origin -> Bool
$cmax :: Q1Origin -> Q1Origin -> Q1Origin
max :: Q1Origin -> Q1Origin -> Q1Origin
$cmin :: Q1Origin -> Q1Origin -> Q1Origin
min :: Q1Origin -> Q1Origin -> Q1Origin
Ord)

-- | Origin of 'Quantityω'.
data QωOrigin
  = QωInferred       -- ^ User wrote nothing.
  |        Range   -- ^ User wrote "@ω".
  | QωPlenty Range   -- ^ User wrote "@plenty".
  deriving (Int -> QωOrigin -> ShowS
[QωOrigin] -> ShowS
QωOrigin -> ArgName
(Int -> QωOrigin -> ShowS)
-> (QωOrigin -> ArgName) -> ([QωOrigin] -> ShowS) -> Show QωOrigin
forall a.
(Int -> a -> ShowS) -> (a -> ArgName) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> QωOrigin -> ShowS
showsPrec :: Int -> QωOrigin -> ShowS
$cshow :: QωOrigin -> ArgName
show :: QωOrigin -> ArgName
$cshowList :: [QωOrigin] -> ShowS
showList :: [QωOrigin] -> ShowS
Show, (forall x. QωOrigin -> Rep QωOrigin x)
-> (forall x. Rep QωOrigin x -> QωOrigin) -> Generic QωOrigin
forall x. Rep QωOrigin x -> QωOrigin
forall x. QωOrigin -> Rep QωOrigin x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cfrom :: forall x. QωOrigin -> Rep QωOrigin x
from :: forall x. QωOrigin -> Rep QωOrigin x
$cto :: forall x. Rep QωOrigin x -> QωOrigin
to :: forall x. Rep QωOrigin x -> QωOrigin
Generic, QωOrigin -> QωOrigin -> Bool
(QωOrigin -> QωOrigin -> Bool)
-> (QωOrigin -> QωOrigin -> Bool) -> Eq QωOrigin
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: QωOrigin -> QωOrigin -> Bool
== :: QωOrigin -> QωOrigin -> Bool
$c/= :: QωOrigin -> QωOrigin -> Bool
/= :: QωOrigin -> QωOrigin -> Bool
Eq, Eq QωOrigin
Eq QωOrigin =>
(QωOrigin -> QωOrigin -> Ordering)
-> (QωOrigin -> QωOrigin -> Bool)
-> (QωOrigin -> QωOrigin -> Bool)
-> (QωOrigin -> QωOrigin -> Bool)
-> (QωOrigin -> QωOrigin -> Bool)
-> (QωOrigin -> QωOrigin -> QωOrigin)
-> (QωOrigin -> QωOrigin -> QωOrigin)
-> Ord QωOrigin
QωOrigin -> QωOrigin -> Bool
QωOrigin -> QωOrigin -> Ordering
QωOrigin -> QωOrigin -> QωOrigin
forall a.
Eq a =>
(a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
$ccompare :: QωOrigin -> QωOrigin -> Ordering
compare :: QωOrigin -> QωOrigin -> Ordering
$c< :: QωOrigin -> QωOrigin -> Bool
< :: QωOrigin -> QωOrigin -> Bool
$c<= :: QωOrigin -> QωOrigin -> Bool
<= :: QωOrigin -> QωOrigin -> Bool
$c> :: QωOrigin -> QωOrigin -> Bool
> :: QωOrigin -> QωOrigin -> Bool
$c>= :: QωOrigin -> QωOrigin -> Bool
>= :: QωOrigin -> QωOrigin -> Bool
$cmax :: QωOrigin -> QωOrigin -> QωOrigin
max :: QωOrigin -> QωOrigin -> QωOrigin
$cmin :: QωOrigin -> QωOrigin -> QωOrigin
min :: QωOrigin -> QωOrigin -> QωOrigin
Ord)

-- *** Instances for 'Q0Origin'.

-- | Right-biased composition, because the left quantity
--   acts as context, and the right one as occurrence.
instance Semigroup Q0Origin where
  <> :: Q0Origin -> Q0Origin -> Q0Origin
(<>) = ((Q0Origin, Q0Origin) -> Q0Origin)
-> Q0Origin -> Q0Origin -> Q0Origin
forall a b c. ((a, b) -> c) -> a -> b -> c
curry (((Q0Origin, Q0Origin) -> Q0Origin)
 -> Q0Origin -> Q0Origin -> Q0Origin)
-> ((Q0Origin, Q0Origin) -> Q0Origin)
-> Q0Origin
-> Q0Origin
-> Q0Origin
forall a b. (a -> b) -> a -> b
$ \case
    (Q0Origin
Q0Inferred, Q0Origin
o) -> Q0Origin
o
    (Q0Origin
o, Q0Origin
Q0Inferred) -> Q0Origin
o
    (Q0Origin
o, Q0       Range
r) -> Range -> Q0Origin
Q0 (Range -> Q0Origin) -> Range -> Q0Origin
forall a b. (a -> b) -> a -> b
$ Q0Origin -> Range -> Range
forall u t. (HasRange u, HasRange t) => u -> t -> Range
fuseRange Q0Origin
o Range
r
    (Q0Origin
o, Q0Erased Range
r) -> Range -> Q0Origin
Q0 (Range -> Q0Origin) -> Range -> Q0Origin
forall a b. (a -> b) -> a -> b
$ Q0Origin -> Range -> Range
forall u t. (HasRange u, HasRange t) => u -> t -> Range
fuseRange Q0Origin
o Range
r

instance Monoid Q0Origin where
  mempty :: Q0Origin
mempty = Q0Origin
Q0Inferred
  mappend :: Q0Origin -> Q0Origin -> Q0Origin
mappend = Q0Origin -> Q0Origin -> Q0Origin
forall a. Semigroup a => a -> a -> a
(<>)

instance Null Q0Origin where
  empty :: Q0Origin
empty = Q0Origin
forall a. Monoid a => a
mempty

instance HasRange Q0Origin where
  getRange :: Q0Origin -> Range
getRange = \case
    Q0Origin
Q0Inferred -> Range
forall a. Range' a
noRange
    Q0       Range
r -> Range
r
    Q0Erased Range
r -> Range
r

instance SetRange Q0Origin where
  setRange :: Range -> Q0Origin -> Q0Origin
setRange Range
r = \case
    Q0Origin
Q0Inferred -> Q0Origin
Q0Inferred
    Q0       Range
_ -> Range -> Q0Origin
Q0       Range
r
    Q0Erased Range
_ -> Range -> Q0Origin
Q0Erased Range
r

instance KillRange Q0Origin where
  killRange :: Q0Origin -> Q0Origin
killRange = \case
    Q0Origin
Q0Inferred -> Q0Origin
Q0Inferred
    Q0       Range
_ -> Range -> Q0Origin
Q0       Range
forall a. Range' a
noRange
    Q0Erased Range
_ -> Range -> Q0Origin
Q0Erased Range
forall a. Range' a
noRange

instance NFData Q0Origin where
  rnf :: Q0Origin -> ()
rnf = \case
    Q0Origin
Q0Inferred -> ()
    Q0       Range
_ -> ()
    Q0Erased Range
_ -> ()

-- *** Instances for 'Q1Origin'.

-- | Right-biased composition, because the left quantity
--   acts as context, and the right one as occurrence.
instance Semigroup Q1Origin where
  <> :: Q1Origin -> Q1Origin -> Q1Origin
(<>) = ((Q1Origin, Q1Origin) -> Q1Origin)
-> Q1Origin -> Q1Origin -> Q1Origin
forall a b c. ((a, b) -> c) -> a -> b -> c
curry (((Q1Origin, Q1Origin) -> Q1Origin)
 -> Q1Origin -> Q1Origin -> Q1Origin)
-> ((Q1Origin, Q1Origin) -> Q1Origin)
-> Q1Origin
-> Q1Origin
-> Q1Origin
forall a b. (a -> b) -> a -> b
$ \case
    (Q1Origin
Q1Inferred, Q1Origin
o) -> Q1Origin
o
    (Q1Origin
o, Q1Origin
Q1Inferred) -> Q1Origin
o
    (Q1Origin
o, Q1       Range
r) -> Range -> Q1Origin
Q1 (Range -> Q1Origin) -> Range -> Q1Origin
forall a b. (a -> b) -> a -> b
$ Q1Origin -> Range -> Range
forall u t. (HasRange u, HasRange t) => u -> t -> Range
fuseRange Q1Origin
o Range
r
    (Q1Origin
o, Q1Linear Range
r) -> Range -> Q1Origin
Q1 (Range -> Q1Origin) -> Range -> Q1Origin
forall a b. (a -> b) -> a -> b
$ Q1Origin -> Range -> Range
forall u t. (HasRange u, HasRange t) => u -> t -> Range
fuseRange Q1Origin
o Range
r

instance Monoid Q1Origin where
  mempty :: Q1Origin
mempty = Q1Origin
Q1Inferred
  mappend :: Q1Origin -> Q1Origin -> Q1Origin
mappend = Q1Origin -> Q1Origin -> Q1Origin
forall a. Semigroup a => a -> a -> a
(<>)

instance Null Q1Origin where
  empty :: Q1Origin
empty = Q1Origin
forall a. Monoid a => a
mempty

instance HasRange Q1Origin where
  getRange :: Q1Origin -> Range
getRange = \case
    Q1Origin
Q1Inferred -> Range
forall a. Range' a
noRange
    Q1       Range
r -> Range
r
    Q1Linear Range
r -> Range
r

instance SetRange Q1Origin where
  setRange :: Range -> Q1Origin -> Q1Origin
setRange Range
r = \case
    Q1Origin
Q1Inferred -> Q1Origin
Q1Inferred
    Q1       Range
_ -> Range -> Q1Origin
Q1       Range
r
    Q1Linear Range
_ -> Range -> Q1Origin
Q1Linear Range
r

instance KillRange Q1Origin where
  killRange :: Q1Origin -> Q1Origin
killRange = \case
    Q1Origin
Q1Inferred -> Q1Origin
Q1Inferred
    Q1       Range
_ -> Range -> Q1Origin
Q1       Range
forall a. Range' a
noRange
    Q1Linear Range
_ -> Range -> Q1Origin
Q1Linear Range
forall a. Range' a
noRange

instance NFData Q1Origin where
  rnf :: Q1Origin -> ()
rnf = \case
    Q1Origin
Q1Inferred -> ()
    Q1       Range
_ -> ()
    Q1Linear Range
_ -> ()

-- *** Instances for 'QωOrigin'.

-- | Right-biased composition, because the left quantity
--   acts as context, and the right one as occurrence.
instance Semigroup QωOrigin where
  <> :: QωOrigin -> QωOrigin -> QωOrigin
(<>) = ((QωOrigin, QωOrigin) -> QωOrigin)
-> QωOrigin -> QωOrigin -> QωOrigin
forall a b c. ((a, b) -> c) -> a -> b -> c
curry (((QωOrigin, QωOrigin) -> QωOrigin)
 -> QωOrigin -> QωOrigin -> QωOrigin)
-> ((QωOrigin, QωOrigin) -> QωOrigin)
-> QωOrigin
-> QωOrigin
-> QωOrigin
forall a b. (a -> b) -> a -> b
$ \case
    (QωOrigin
QωInferred, QωOrigin
o) -> QωOrigin
o
    (QωOrigin
o, QωOrigin
QωInferred) -> QωOrigin
o
    (QωOrigin
o,        Range
r) -> Range -> QωOrigin
 (Range -> QωOrigin) -> Range -> QωOrigin
forall a b. (a -> b) -> a -> b
$ QωOrigin -> Range -> Range
forall u t. (HasRange u, HasRange t) => u -> t -> Range
fuseRange QωOrigin
o Range
r
    (QωOrigin
o, QωPlenty Range
r) -> Range -> QωOrigin
 (Range -> QωOrigin) -> Range -> QωOrigin
forall a b. (a -> b) -> a -> b
$ QωOrigin -> Range -> Range
forall u t. (HasRange u, HasRange t) => u -> t -> Range
fuseRange QωOrigin
o Range
r

instance Monoid QωOrigin where
  mempty :: QωOrigin
mempty = QωOrigin
QωInferred
  mappend :: QωOrigin -> QωOrigin -> QωOrigin
mappend = QωOrigin -> QωOrigin -> QωOrigin
forall a. Semigroup a => a -> a -> a
(<>)

instance Null QωOrigin where
  empty :: QωOrigin
empty = QωOrigin
forall a. Monoid a => a
mempty

instance HasRange QωOrigin where
  getRange :: QωOrigin -> Range
getRange = \case
    QωOrigin
QωInferred -> Range
forall a. Range' a
noRange
           Range
r -> Range
r
    QωPlenty Range
r -> Range
r

instance SetRange QωOrigin where
  setRange :: Range -> QωOrigin -> QωOrigin
setRange Range
r = \case
    QωOrigin
QωInferred -> QωOrigin
QωInferred
           Range
_ -> Range -> QωOrigin
       Range
r
    QωPlenty Range
_ -> Range -> QωOrigin
QωPlenty Range
r

instance KillRange QωOrigin where
  killRange :: QωOrigin -> QωOrigin
killRange = \case
    QωOrigin
QωInferred -> QωOrigin
QωInferred
           Range
_ -> Range -> QωOrigin
       Range
forall a. Range' a
noRange
    QωPlenty Range
_ -> Range -> QωOrigin
QωPlenty Range
forall a. Range' a
noRange

instance NFData QωOrigin where
  rnf :: QωOrigin -> ()
rnf = \case
    QωOrigin
QωInferred -> ()
           Range
_ -> ()
    QωPlenty Range
_ -> ()

-- ** Quantity.

-- | Quantity for linearity.
--
--   A quantity is a set of natural numbers, indicating possible semantic
--   uses of a variable.  A singleton set @{n}@ requires that the
--   corresponding variable is used exactly @n@ times.
--
data Quantity
  = Quantity0 Q0Origin -- ^ Zero uses @{0}@, erased at runtime.
  | Quantity1 Q1Origin -- ^ Linear use @{1}@ (could be updated destructively).
    -- Mostly TODO (needs postponable constraints between quantities to compute uses).
  | Quantityω QωOrigin -- ^ Unrestricted use @ℕ@.
  deriving (Int -> Quantity -> ShowS
[Quantity] -> ShowS
Quantity -> ArgName
(Int -> Quantity -> ShowS)
-> (Quantity -> ArgName) -> ([Quantity] -> ShowS) -> Show Quantity
forall a.
(Int -> a -> ShowS) -> (a -> ArgName) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> Quantity -> ShowS
showsPrec :: Int -> Quantity -> ShowS
$cshow :: Quantity -> ArgName
show :: Quantity -> ArgName
$cshowList :: [Quantity] -> ShowS
showList :: [Quantity] -> ShowS
Show, (forall x. Quantity -> Rep Quantity x)
-> (forall x. Rep Quantity x -> Quantity) -> Generic Quantity
forall x. Rep Quantity x -> Quantity
forall x. Quantity -> Rep Quantity x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cfrom :: forall x. Quantity -> Rep Quantity x
from :: forall x. Quantity -> Rep Quantity x
$cto :: forall x. Rep Quantity x -> Quantity
to :: forall x. Rep Quantity x -> Quantity
Generic, Quantity -> Quantity -> Bool
(Quantity -> Quantity -> Bool)
-> (Quantity -> Quantity -> Bool) -> Eq Quantity
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: Quantity -> Quantity -> Bool
== :: Quantity -> Quantity -> Bool
$c/= :: Quantity -> Quantity -> Bool
/= :: Quantity -> Quantity -> Bool
Eq, Eq Quantity
Eq Quantity =>
(Quantity -> Quantity -> Ordering)
-> (Quantity -> Quantity -> Bool)
-> (Quantity -> Quantity -> Bool)
-> (Quantity -> Quantity -> Bool)
-> (Quantity -> Quantity -> Bool)
-> (Quantity -> Quantity -> Quantity)
-> (Quantity -> Quantity -> Quantity)
-> Ord Quantity
Quantity -> Quantity -> Bool
Quantity -> Quantity -> Ordering
Quantity -> Quantity -> Quantity
forall a.
Eq a =>
(a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
$ccompare :: Quantity -> Quantity -> Ordering
compare :: Quantity -> Quantity -> Ordering
$c< :: Quantity -> Quantity -> Bool
< :: Quantity -> Quantity -> Bool
$c<= :: Quantity -> Quantity -> Bool
<= :: Quantity -> Quantity -> Bool
$c> :: Quantity -> Quantity -> Bool
> :: Quantity -> Quantity -> Bool
$c>= :: Quantity -> Quantity -> Bool
>= :: Quantity -> Quantity -> Bool
$cmax :: Quantity -> Quantity -> Quantity
max :: Quantity -> Quantity -> Quantity
$cmin :: Quantity -> Quantity -> Quantity
min :: Quantity -> Quantity -> Quantity
Ord)
    -- @Ord@ instance in case @Quantity@ is used in keys for maps etc.

-- | Equality ignoring origin.

sameQuantity :: Quantity -> Quantity -> Bool
sameQuantity :: Quantity -> Quantity -> Bool
sameQuantity = ((Quantity, Quantity) -> Bool) -> Quantity -> Quantity -> Bool
forall a b c. ((a, b) -> c) -> a -> b -> c
curry (((Quantity, Quantity) -> Bool) -> Quantity -> Quantity -> Bool)
-> ((Quantity, Quantity) -> Bool) -> Quantity -> Quantity -> Bool
forall a b. (a -> b) -> a -> b
$ \case
  (Quantity0{}, Quantity0{}) -> Bool
True
  (Quantity1{}, Quantity1{}) -> Bool
True
  (Quantityω{}, Quantityω{}) -> Bool
True
  (Quantity, Quantity)
_ -> Bool
False

-- | Composition of quantities (multiplication).
--
-- 'Quantity0' is dominant.
-- 'Quantity1' is neutral.
--
-- Right-biased for origin.
--
instance Semigroup (UnderComposition Quantity) where
  <> :: UnderComposition Quantity
-> UnderComposition Quantity -> UnderComposition Quantity
(<>) = (Quantity -> Quantity -> Quantity)
-> UnderComposition Quantity
-> UnderComposition Quantity
-> UnderComposition Quantity
forall a b c.
(a -> b -> c)
-> UnderComposition a -> UnderComposition b -> UnderComposition c
forall (f :: * -> *) a b c.
Applicative f =>
(a -> b -> c) -> f a -> f b -> f c
liftA2 Quantity -> Quantity -> Quantity
composeQuantity

-- | In the absense of finite quantities besides 0, ω is the unit.
--   Otherwise, 1 is the unit.
instance Monoid (UnderComposition Quantity) where
  mempty :: UnderComposition Quantity
mempty  = Quantity -> UnderComposition Quantity
forall a. a -> UnderComposition a
forall (f :: * -> *) a. Applicative f => a -> f a
pure Quantity
unitQuantity
  mappend :: UnderComposition Quantity
-> UnderComposition Quantity -> UnderComposition Quantity
mappend = UnderComposition Quantity
-> UnderComposition Quantity -> UnderComposition Quantity
forall a. Semigroup a => a -> a -> a
(<>)

instance POSemigroup (UnderComposition Quantity) where
instance POMonoid (UnderComposition Quantity) where

instance LeftClosedPOMonoid (UnderComposition Quantity) where
  inverseCompose :: UnderComposition Quantity
-> UnderComposition Quantity -> UnderComposition Quantity
inverseCompose = (Quantity -> Quantity -> Quantity)
-> UnderComposition Quantity
-> UnderComposition Quantity
-> UnderComposition Quantity
forall a b c.
(a -> b -> c)
-> UnderComposition a -> UnderComposition b -> UnderComposition c
forall (f :: * -> *) a b c.
Applicative f =>
(a -> b -> c) -> f a -> f b -> f c
liftA2 Quantity -> Quantity -> Quantity
inverseComposeQuantity

instance Semigroup (UnderAddition Quantity) where
  <> :: UnderAddition Quantity
-> UnderAddition Quantity -> UnderAddition Quantity
(<>) = (Quantity -> Quantity -> Quantity)
-> UnderAddition Quantity
-> UnderAddition Quantity
-> UnderAddition Quantity
forall a b c.
(a -> b -> c)
-> UnderAddition a -> UnderAddition b -> UnderAddition c
forall (f :: * -> *) a b c.
Applicative f =>
(a -> b -> c) -> f a -> f b -> f c
liftA2 Quantity -> Quantity -> Quantity
addQuantity

instance Monoid (UnderAddition Quantity) where
  mempty :: UnderAddition Quantity
mempty  = Quantity -> UnderAddition Quantity
forall a. a -> UnderAddition a
forall (f :: * -> *) a. Applicative f => a -> f a
pure Quantity
zeroQuantity
  mappend :: UnderAddition Quantity
-> UnderAddition Quantity -> UnderAddition Quantity
mappend = UnderAddition Quantity
-> UnderAddition Quantity -> UnderAddition Quantity
forall a. Semigroup a => a -> a -> a
(<>)

instance POSemigroup (UnderAddition Quantity) where
instance POMonoid (UnderAddition Quantity) where

-- | Note that the order is @ω ≤ 0,1@, more options is smaller.
instance PartialOrd Quantity where
  comparable :: Comparable Quantity
comparable = ((Quantity, Quantity) -> PartialOrdering) -> Comparable Quantity
forall a b c. ((a, b) -> c) -> a -> b -> c
curry (((Quantity, Quantity) -> PartialOrdering) -> Comparable Quantity)
-> ((Quantity, Quantity) -> PartialOrdering) -> Comparable Quantity
forall a b. (a -> b) -> a -> b
$ \case
    (Quantity
q, Quantity
q') | Quantity -> Quantity -> Bool
sameQuantity Quantity
q Quantity
q' -> PartialOrdering
POEQ
    -- ω is least
    (Quantityω{}, Quantity
_)  -> PartialOrdering
POLT
    (Quantity
_, Quantityω{})  -> PartialOrdering
POGT
    -- others are uncomparable
    (Quantity, Quantity)
_ -> PartialOrdering
POAny

-- | 'Quantity' forms an additive monoid with zero Quantity0.
addQuantity :: Quantity -> Quantity -> Quantity
addQuantity :: Quantity -> Quantity -> Quantity
addQuantity = ((Quantity, Quantity) -> Quantity)
-> Quantity -> Quantity -> Quantity
forall a b c. ((a, b) -> c) -> a -> b -> c
curry (((Quantity, Quantity) -> Quantity)
 -> Quantity -> Quantity -> Quantity)
-> ((Quantity, Quantity) -> Quantity)
-> Quantity
-> Quantity
-> Quantity
forall a b. (a -> b) -> a -> b
$ \case
  -- ω is absorptive
  (q :: Quantity
q@Quantityω{}, Quantity
_) -> Quantity
q
  (Quantity
_, q :: Quantity
q@Quantityω{}) -> Quantity
q
  -- 0 is neutral
  (Quantity0{}, Quantity
q) -> Quantity
q
  (Quantity
q, Quantity0{}) -> Quantity
q
  -- 1 + 1 = ω
  (Quantity1 Q1Origin
_, Quantity1 Q1Origin
_) -> Quantity
topQuantity

-- | Identity element under addition
zeroQuantity :: Quantity
zeroQuantity :: Quantity
zeroQuantity = Q0Origin -> Quantity
Quantity0 Q0Origin
forall a. Monoid a => a
mempty

-- | Absorptive element!
--   This differs from Relevance and Cohesion whose default
--   is the multiplicative unit.
defaultQuantity :: Quantity
defaultQuantity :: Quantity
defaultQuantity = Quantity
topQuantity

-- | Identity element under composition
unitQuantity :: Quantity
unitQuantity :: Quantity
unitQuantity = QωOrigin -> Quantity
Quantityω QωOrigin
forall a. Monoid a => a
mempty

-- | Absorptive element is ω.
topQuantity :: Quantity
topQuantity :: Quantity
topQuantity = QωOrigin -> Quantity
Quantityω QωOrigin
forall a. Monoid a => a
mempty

-- | @m `moreUsableQuantity` m'@ means that an @m@ can be used
--   where ever an @m'@ is required.

moreQuantity :: Quantity -> Quantity -> Bool
moreQuantity :: Quantity -> Quantity -> Bool
moreQuantity Quantity
m Quantity
m' = Quantity -> PartialOrdering -> Quantity -> Bool
forall a. PartialOrd a => a -> PartialOrdering -> a -> Bool
related Quantity
m PartialOrdering
POLE Quantity
m'

-- | Composition of quantities (multiplication).
--
-- 'Quantity0' is dominant.
-- 'Quantity1' is neutral.
--
-- Right-biased for origin.
--
composeQuantity :: Quantity -> Quantity -> Quantity
composeQuantity :: Quantity -> Quantity -> Quantity
composeQuantity = ((Quantity, Quantity) -> Quantity)
-> Quantity -> Quantity -> Quantity
forall a b c. ((a, b) -> c) -> a -> b -> c
curry (((Quantity, Quantity) -> Quantity)
 -> Quantity -> Quantity -> Quantity)
-> ((Quantity, Quantity) -> Quantity)
-> Quantity
-> Quantity
-> Quantity
forall a b. (a -> b) -> a -> b
$ \case
  (Quantity1 Q1Origin
o, Quantity1 Q1Origin
o') -> Q1Origin -> Quantity
Quantity1 (Q1Origin
o Q1Origin -> Q1Origin -> Q1Origin
forall a. Semigroup a => a -> a -> a
<> Q1Origin
o')
  (Quantity1{}, Quantity
q           ) -> Quantity
q
  (Quantity
q          , Quantity1{} ) -> Quantity
q
  (Quantity0 Q0Origin
o, Quantity0 Q0Origin
o') -> Q0Origin -> Quantity
Quantity0 (Q0Origin
o Q0Origin -> Q0Origin -> Q0Origin
forall a. Semigroup a => a -> a -> a
<> Q0Origin
o')
  (Quantity
_          , Quantity0 Q0Origin
o ) -> Q0Origin -> Quantity
Quantity0 Q0Origin
o
  (Quantity0 Q0Origin
o, Quantity
_           ) -> Q0Origin -> Quantity
Quantity0 Q0Origin
o
  (Quantityω QωOrigin
o, Quantityω QωOrigin
o') -> QωOrigin -> Quantity
Quantityω (QωOrigin
o QωOrigin -> QωOrigin -> QωOrigin
forall a. Semigroup a => a -> a -> a
<> QωOrigin
o')

-- | Compose with quantity flag from the left.
--   This function is e.g. used to update the quantity information
--   on pattern variables @a@ after a match against something of quantity @q@.

applyQuantity :: LensQuantity a => Quantity -> a -> a
applyQuantity :: forall a. LensQuantity a => Quantity -> a -> a
applyQuantity Quantity
q = (Quantity -> Quantity) -> a -> a
forall a. LensQuantity a => (Quantity -> Quantity) -> a -> a
mapQuantity (Quantity
q Quantity -> Quantity -> Quantity
`composeQuantity`)

-- | @inverseComposeQuantity r x@ returns the least quantity @y@
--   such that forall @x@, @y@ we have
--   @x \`moreQuantity\` (r \`composeQuantity\` y)@
--   iff
--   @(r \`inverseComposeQuantity\` x) \`moreQuantity\` y@ (Galois connection).

inverseComposeQuantity :: Quantity -> Quantity -> Quantity
inverseComposeQuantity :: Quantity -> Quantity -> Quantity
inverseComposeQuantity = ((Quantity, Quantity) -> Quantity)
-> Quantity -> Quantity -> Quantity
forall a b c. ((a, b) -> c) -> a -> b -> c
curry (((Quantity, Quantity) -> Quantity)
 -> Quantity -> Quantity -> Quantity)
-> ((Quantity, Quantity) -> Quantity)
-> Quantity
-> Quantity
-> Quantity
forall a b. (a -> b) -> a -> b
$ \case
    (Quantity1{} , Quantity
x)              -> Quantity
x             -- going to linear arg: nothing changes
    (Quantity0{} , Quantity
x)              -> Quantity
topQuantity   -- going to erased arg: every thing usable
    (Quantityω{} , x :: Quantity
x@Quantityω{})  -> Quantity
x
    (Quantityω{} , Quantity
_)              -> Quantity
zeroQuantity  -- linear resources are unusable as arguments to unrestricted functions

-- | Left division by a 'Quantity'.
--   Used e.g. to modify context when going into a @q@ argument.

inverseApplyQuantity :: LensQuantity a => Quantity -> a -> a
inverseApplyQuantity :: forall a. LensQuantity a => Quantity -> a -> a
inverseApplyQuantity Quantity
q = (Quantity -> Quantity) -> a -> a
forall a. LensQuantity a => (Quantity -> Quantity) -> a -> a
mapQuantity (Quantity
q Quantity -> Quantity -> Quantity
`inverseComposeQuantity`)

-- | Check for 'Quantity0'.

hasQuantity0 :: LensQuantity a => a -> Bool
hasQuantity0 :: forall a. LensQuantity a => a -> Bool
hasQuantity0 a
a
  | Quantity0{} <- a -> Quantity
forall a. LensQuantity a => a -> Quantity
getQuantity a
a = Bool
True
  | Bool
otherwise = Bool
False

-- | Check for 'Quantity1'.

hasQuantity1 :: LensQuantity a => a -> Bool
hasQuantity1 :: forall a. LensQuantity a => a -> Bool
hasQuantity1 a
a
  | Quantity1{} <- a -> Quantity
forall a. LensQuantity a => a -> Quantity
getQuantity a
a = Bool
True
  | Bool
otherwise = Bool
False

-- | Check for 'Quantityω'.

hasQuantityω :: LensQuantity a => a -> Bool
hasQuantityω :: forall a. LensQuantity a => a -> Bool
hasQuantityω a
a
  | Quantityω{} <- a -> Quantity
forall a. LensQuantity a => a -> Quantity
getQuantity a
a = Bool
True
  | Bool
otherwise = Bool
False

-- | Did the user supply a quantity annotation?

noUserQuantity :: LensQuantity a => a -> Bool
noUserQuantity :: forall a. LensQuantity a => a -> Bool
noUserQuantity a
a = case a -> Quantity
forall a. LensQuantity a => a -> Quantity
getQuantity a
a of
  Quantity0 Q0Origin
o -> Q0Origin -> Bool
forall a. Null a => a -> Bool
null Q0Origin
o
  Quantity1 Q1Origin
o -> Q1Origin -> Bool
forall a. Null a => a -> Bool
null Q1Origin
o
  Quantityω QωOrigin
o -> QωOrigin -> Bool
forall a. Null a => a -> Bool
null QωOrigin
o

-- | A thing of quantity 0 is unusable, all others are usable.

usableQuantity :: LensQuantity a => a -> Bool
usableQuantity :: forall a. LensQuantity a => a -> Bool
usableQuantity = Bool -> Bool
not (Bool -> Bool) -> (a -> Bool) -> a -> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. a -> Bool
forall a. LensQuantity a => a -> Bool
hasQuantity0

-- boilerplate instances

class LensQuantity a where

  getQuantity :: a -> Quantity

  setQuantity :: Quantity -> a -> a
  setQuantity = (Quantity -> Quantity) -> a -> a
forall a. LensQuantity a => (Quantity -> Quantity) -> a -> a
mapQuantity ((Quantity -> Quantity) -> a -> a)
-> (Quantity -> Quantity -> Quantity) -> Quantity -> a -> a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Quantity -> Quantity -> Quantity
forall a b. a -> b -> a
const

  mapQuantity :: (Quantity -> Quantity) -> a -> a

  default getQuantity :: LensModality a => a -> Quantity
  getQuantity = Modality -> Quantity
modQuantity (Modality -> Quantity) -> (a -> Modality) -> a -> Quantity
forall b c a. (b -> c) -> (a -> b) -> a -> c
. a -> Modality
forall a. LensModality a => a -> Modality
getModality

  default mapQuantity :: LensModality a => (Quantity -> Quantity) -> a -> a
  mapQuantity Quantity -> Quantity
f = (Modality -> Modality) -> a -> a
forall a. LensModality a => (Modality -> Modality) -> a -> a
mapModality ((Modality -> Modality) -> a -> a)
-> (Modality -> Modality) -> a -> a
forall a b. (a -> b) -> a -> b
$ \ Modality
ai -> Modality
ai { modQuantity = f $ modQuantity ai }

instance LensQuantity Quantity where
  getQuantity :: Quantity -> Quantity
getQuantity = Quantity -> Quantity
forall a. a -> a
id
  setQuantity :: Quantity -> Quantity -> Quantity
setQuantity = Quantity -> Quantity -> Quantity
forall a b. a -> b -> a
const
  mapQuantity :: (Quantity -> Quantity) -> Quantity -> Quantity
mapQuantity = (Quantity -> Quantity) -> Quantity -> Quantity
forall a. a -> a
id

instance HasRange Quantity where
  getRange :: Quantity -> Range
getRange = \case
    Quantity0 Q0Origin
o -> Q0Origin -> Range
forall a. HasRange a => a -> Range
getRange Q0Origin
o
    Quantity1 Q1Origin
o -> Q1Origin -> Range
forall a. HasRange a => a -> Range
getRange Q1Origin
o
    Quantityω QωOrigin
o -> QωOrigin -> Range
forall a. HasRange a => a -> Range
getRange QωOrigin
o

instance SetRange Quantity where
  setRange :: Range -> Quantity -> Quantity
setRange Range
r = \case
    Quantity0 Q0Origin
o -> Q0Origin -> Quantity
Quantity0 (Q0Origin -> Quantity) -> Q0Origin -> Quantity
forall a b. (a -> b) -> a -> b
$ Range -> Q0Origin -> Q0Origin
forall a. SetRange a => Range -> a -> a
setRange Range
r Q0Origin
o
    Quantity1 Q1Origin
o -> Q1Origin -> Quantity
Quantity1 (Q1Origin -> Quantity) -> Q1Origin -> Quantity
forall a b. (a -> b) -> a -> b
$ Range -> Q1Origin -> Q1Origin
forall a. SetRange a => Range -> a -> a
setRange Range
r Q1Origin
o
    Quantityω QωOrigin
o -> QωOrigin -> Quantity
Quantityω (QωOrigin -> Quantity) -> QωOrigin -> Quantity
forall a b. (a -> b) -> a -> b
$ Range -> QωOrigin -> QωOrigin
forall a. SetRange a => Range -> a -> a
setRange Range
r QωOrigin
o

instance KillRange Quantity where
  killRange :: Quantity -> Quantity
killRange = \case
    Quantity0 Q0Origin
o -> Q0Origin -> Quantity
Quantity0 (Q0Origin -> Quantity) -> Q0Origin -> Quantity
forall a b. (a -> b) -> a -> b
$ Q0Origin -> Q0Origin
forall a. KillRange a => KillRangeT a
killRange Q0Origin
o
    Quantity1 Q1Origin
o -> Q1Origin -> Quantity
Quantity1 (Q1Origin -> Quantity) -> Q1Origin -> Quantity
forall a b. (a -> b) -> a -> b
$ Q1Origin -> Q1Origin
forall a. KillRange a => KillRangeT a
killRange Q1Origin
o
    Quantityω QωOrigin
o -> QωOrigin -> Quantity
Quantityω (QωOrigin -> Quantity) -> QωOrigin -> Quantity
forall a b. (a -> b) -> a -> b
$ QωOrigin -> QωOrigin
forall a. KillRange a => KillRangeT a
killRange QωOrigin
o

instance NFData Quantity where
  rnf :: Quantity -> ()
rnf (Quantity0 Q0Origin
o) = Q0Origin -> ()
forall a. NFData a => a -> ()
rnf Q0Origin
o
  rnf (Quantity1 Q1Origin
o) = Q1Origin -> ()
forall a. NFData a => a -> ()
rnf Q1Origin
o
  rnf (Quantityω QωOrigin
o) = QωOrigin -> ()
forall a. NFData a => a -> ()
rnf QωOrigin
o

-- ** Erased.

-- | A special case of 'Quantity': erased or not.
--
-- Note that the 'Ord' instance does *not* ignore the origin
-- arguments.

data Erased
  = Erased Q0Origin
  | NotErased QωOrigin
  deriving (Int -> Erased -> ShowS
[Erased] -> ShowS
Erased -> ArgName
(Int -> Erased -> ShowS)
-> (Erased -> ArgName) -> ([Erased] -> ShowS) -> Show Erased
forall a.
(Int -> a -> ShowS) -> (a -> ArgName) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> Erased -> ShowS
showsPrec :: Int -> Erased -> ShowS
$cshow :: Erased -> ArgName
show :: Erased -> ArgName
$cshowList :: [Erased] -> ShowS
showList :: [Erased] -> ShowS
Show, Erased -> Erased -> Bool
(Erased -> Erased -> Bool)
-> (Erased -> Erased -> Bool) -> Eq Erased
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: Erased -> Erased -> Bool
== :: Erased -> Erased -> Bool
$c/= :: Erased -> Erased -> Bool
/= :: Erased -> Erased -> Bool
Eq, Eq Erased
Eq Erased =>
(Erased -> Erased -> Ordering)
-> (Erased -> Erased -> Bool)
-> (Erased -> Erased -> Bool)
-> (Erased -> Erased -> Bool)
-> (Erased -> Erased -> Bool)
-> (Erased -> Erased -> Erased)
-> (Erased -> Erased -> Erased)
-> Ord Erased
Erased -> Erased -> Bool
Erased -> Erased -> Ordering
Erased -> Erased -> Erased
forall a.
Eq a =>
(a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
$ccompare :: Erased -> Erased -> Ordering
compare :: Erased -> Erased -> Ordering
$c< :: Erased -> Erased -> Bool
< :: Erased -> Erased -> Bool
$c<= :: Erased -> Erased -> Bool
<= :: Erased -> Erased -> Bool
$c> :: Erased -> Erased -> Bool
> :: Erased -> Erased -> Bool
$c>= :: Erased -> Erased -> Bool
>= :: Erased -> Erased -> Bool
$cmax :: Erased -> Erased -> Erased
max :: Erased -> Erased -> Erased
$cmin :: Erased -> Erased -> Erased
min :: Erased -> Erased -> Erased
Ord, (forall x. Erased -> Rep Erased x)
-> (forall x. Rep Erased x -> Erased) -> Generic Erased
forall x. Rep Erased x -> Erased
forall x. Erased -> Rep Erased x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cfrom :: forall x. Erased -> Rep Erased x
from :: forall x. Erased -> Rep Erased x
$cto :: forall x. Rep Erased x -> Erased
to :: forall x. Rep Erased x -> Erased
Generic)

-- | The default value of type 'Erased': not erased.

defaultErased :: Erased
defaultErased :: Erased
defaultErased = QωOrigin -> Erased
NotErased QωOrigin
QωInferred

-- | 'Erased' can be embedded into 'Quantity'.

asQuantity :: Erased -> Quantity
asQuantity :: Erased -> Quantity
asQuantity (Erased    Q0Origin
o) = Q0Origin -> Quantity
Quantity0 Q0Origin
o
asQuantity (NotErased QωOrigin
o) = QωOrigin -> Quantity
Quantityω QωOrigin
o

-- | 'Quantity' can be projected onto 'Erased'.

erasedFromQuantity :: Quantity -> Maybe Erased
erasedFromQuantity :: Quantity -> Maybe Erased
erasedFromQuantity = \case
  Quantity1{} -> Maybe Erased
forall a. Maybe a
Nothing
  Quantity0 Q0Origin
o -> Erased -> Maybe Erased
forall a. a -> Maybe a
Just (Erased -> Maybe Erased) -> Erased -> Maybe Erased
forall a b. (a -> b) -> a -> b
$ Q0Origin -> Erased
Erased    Q0Origin
o
  Quantityω QωOrigin
o -> Erased -> Maybe Erased
forall a. a -> Maybe a
Just (Erased -> Maybe Erased) -> Erased -> Maybe Erased
forall a b. (a -> b) -> a -> b
$ QωOrigin -> Erased
NotErased QωOrigin
o

-- | Equality ignoring origin.

sameErased :: Erased -> Erased -> Bool
sameErased :: Erased -> Erased -> Bool
sameErased = Quantity -> Quantity -> Bool
sameQuantity (Quantity -> Quantity -> Bool)
-> (Erased -> Quantity) -> Erased -> Erased -> Bool
forall b c a. (b -> b -> c) -> (a -> b) -> a -> a -> c
`on` Erased -> Quantity
asQuantity

-- | Is the value \"erased\"?

isErased :: Erased -> Bool
isErased :: Erased -> Bool
isErased = Quantity -> Bool
forall a. LensQuantity a => a -> Bool
hasQuantity0 (Quantity -> Bool) -> (Erased -> Quantity) -> Erased -> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Erased -> Quantity
asQuantity

instance NFData Erased

instance HasRange Erased where
  getRange :: Erased -> Range
getRange = Quantity -> Range
forall a. HasRange a => a -> Range
getRange (Quantity -> Range) -> (Erased -> Quantity) -> Erased -> Range
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Erased -> Quantity
asQuantity

instance KillRange Erased where
  killRange :: Erased -> Erased
killRange = \case
    Erased Q0Origin
o    -> Q0Origin -> Erased
Erased (Q0Origin -> Erased) -> Q0Origin -> Erased
forall a b. (a -> b) -> a -> b
$ Q0Origin -> Q0Origin
forall a. KillRange a => KillRangeT a
killRange Q0Origin
o
    NotErased QωOrigin
o -> QωOrigin -> Erased
NotErased (QωOrigin -> Erased) -> QωOrigin -> Erased
forall a b. (a -> b) -> a -> b
$ QωOrigin -> QωOrigin
forall a. KillRange a => KillRangeT a
killRange QωOrigin
o

-- | Composition of values of type 'Erased'.
--
-- 'Erased' is dominant.
-- 'NotErased' is neutral.
--
-- Right-biased for the origin.

composeErased :: Erased -> Erased -> Erased
composeErased :: Erased -> Erased -> Erased
composeErased = ((Erased, Erased) -> Erased) -> Erased -> Erased -> Erased
forall a b c. ((a, b) -> c) -> a -> b -> c
curry (((Erased, Erased) -> Erased) -> Erased -> Erased -> Erased)
-> ((Erased, Erased) -> Erased) -> Erased -> Erased -> Erased
forall a b. (a -> b) -> a -> b
$ \case
  (Erased Q0Origin
o,    Erased Q0Origin
o')    -> Q0Origin -> Erased
Erased (Q0Origin
o Q0Origin -> Q0Origin -> Q0Origin
forall a. Semigroup a => a -> a -> a
<> Q0Origin
o')
  (NotErased QωOrigin
_, Erased Q0Origin
o)     -> Q0Origin -> Erased
Erased Q0Origin
o
  (Erased Q0Origin
o,    NotErased QωOrigin
_)  -> Q0Origin -> Erased
Erased Q0Origin
o
  (NotErased QωOrigin
o, NotErased QωOrigin
o') -> QωOrigin -> Erased
NotErased (QωOrigin
o QωOrigin -> QωOrigin -> QωOrigin
forall a. Semigroup a => a -> a -> a
<> QωOrigin
o')

instance Semigroup (UnderComposition Erased) where
  <> :: UnderComposition Erased
-> UnderComposition Erased -> UnderComposition Erased
(<>) = (Erased -> Erased -> Erased)
-> UnderComposition Erased
-> UnderComposition Erased
-> UnderComposition Erased
forall a b c.
(a -> b -> c)
-> UnderComposition a -> UnderComposition b -> UnderComposition c
forall (f :: * -> *) a b c.
Applicative f =>
(a -> b -> c) -> f a -> f b -> f c
liftA2 Erased -> Erased -> Erased
composeErased

---------------------------------------------------------------------------
-- * Relevance
---------------------------------------------------------------------------

-- | A function argument can be relevant or irrelevant.
--   See "Agda.TypeChecking.Irrelevance".
data Relevance
  = Relevant    -- ^ The argument is (possibly) relevant at compile-time.
  | NonStrict   -- ^ The argument may never flow into evaluation position.
                --   Therefore, it is irrelevant at run-time.
                --   It is treated relevantly during equality checking.
                --
                --   The above comment is probably obsolete, as we currently have
                --   erasure (/at/0, @Quantity0@) for that. What's described here is probably
                --   shape-irrelevance (..). If you enable @--experimental-irrelevance@,
                --   then the type of an irrelevant function is forced to be shape-irrelevant.
                --   See:
                --   - <https://doi.org/10.2168/LMCS-8(1:29)2012> example 2.8
                --     (Not enforcing shape-irrelevant codomains can break subject reduction!)
                --   - <https://dl.acm.org/doi/10.1145/3110277>
                --   - <https://doi.org/10.1145/3209108.3209119>
  | Irrelevant  -- ^ The argument is irrelevant at compile- and runtime.
    deriving (Int -> Relevance -> ShowS
[Relevance] -> ShowS
Relevance -> ArgName
(Int -> Relevance -> ShowS)
-> (Relevance -> ArgName)
-> ([Relevance] -> ShowS)
-> Show Relevance
forall a.
(Int -> a -> ShowS) -> (a -> ArgName) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> Relevance -> ShowS
showsPrec :: Int -> Relevance -> ShowS
$cshow :: Relevance -> ArgName
show :: Relevance -> ArgName
$cshowList :: [Relevance] -> ShowS
showList :: [Relevance] -> ShowS
Show, Relevance -> Relevance -> Bool
(Relevance -> Relevance -> Bool)
-> (Relevance -> Relevance -> Bool) -> Eq Relevance
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: Relevance -> Relevance -> Bool
== :: Relevance -> Relevance -> Bool
$c/= :: Relevance -> Relevance -> Bool
/= :: Relevance -> Relevance -> Bool
Eq, Int -> Relevance
Relevance -> Int
Relevance -> [Relevance]
Relevance -> Relevance
Relevance -> Relevance -> [Relevance]
Relevance -> Relevance -> Relevance -> [Relevance]
(Relevance -> Relevance)
-> (Relevance -> Relevance)
-> (Int -> Relevance)
-> (Relevance -> Int)
-> (Relevance -> [Relevance])
-> (Relevance -> Relevance -> [Relevance])
-> (Relevance -> Relevance -> [Relevance])
-> (Relevance -> Relevance -> Relevance -> [Relevance])
-> Enum Relevance
forall a.
(a -> a)
-> (a -> a)
-> (Int -> a)
-> (a -> Int)
-> (a -> [a])
-> (a -> a -> [a])
-> (a -> a -> [a])
-> (a -> a -> a -> [a])
-> Enum a
$csucc :: Relevance -> Relevance
succ :: Relevance -> Relevance
$cpred :: Relevance -> Relevance
pred :: Relevance -> Relevance
$ctoEnum :: Int -> Relevance
toEnum :: Int -> Relevance
$cfromEnum :: Relevance -> Int
fromEnum :: Relevance -> Int
$cenumFrom :: Relevance -> [Relevance]
enumFrom :: Relevance -> [Relevance]
$cenumFromThen :: Relevance -> Relevance -> [Relevance]
enumFromThen :: Relevance -> Relevance -> [Relevance]
$cenumFromTo :: Relevance -> Relevance -> [Relevance]
enumFromTo :: Relevance -> Relevance -> [Relevance]
$cenumFromThenTo :: Relevance -> Relevance -> Relevance -> [Relevance]
enumFromThenTo :: Relevance -> Relevance -> Relevance -> [Relevance]
Enum, Relevance
Relevance -> Relevance -> Bounded Relevance
forall a. a -> a -> Bounded a
$cminBound :: Relevance
minBound :: Relevance
$cmaxBound :: Relevance
maxBound :: Relevance
Bounded, (forall x. Relevance -> Rep Relevance x)
-> (forall x. Rep Relevance x -> Relevance) -> Generic Relevance
forall x. Rep Relevance x -> Relevance
forall x. Relevance -> Rep Relevance x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cfrom :: forall x. Relevance -> Rep Relevance x
from :: forall x. Relevance -> Rep Relevance x
$cto :: forall x. Rep Relevance x -> Relevance
to :: forall x. Rep Relevance x -> Relevance
Generic)

allRelevances :: [Relevance]
allRelevances :: [Relevance]
allRelevances = [Relevance
forall a. Bounded a => a
minBound..Relevance
forall a. Bounded a => a
maxBound]

instance HasRange Relevance where
  getRange :: Relevance -> Range
getRange Relevance
_ = Range
forall a. Range' a
noRange

instance SetRange Relevance where
  setRange :: Range -> Relevance -> Relevance
setRange Range
_ = Relevance -> Relevance
forall a. a -> a
id

instance KillRange Relevance where
  killRange :: Relevance -> Relevance
killRange Relevance
rel = Relevance
rel -- no range to kill

instance NFData Relevance where
  rnf :: Relevance -> ()
rnf Relevance
Relevant   = ()
  rnf Relevance
NonStrict  = ()
  rnf Relevance
Irrelevant = ()

-- | A lens to access the 'Relevance' attribute in data structures.
--   Minimal implementation: @getRelevance@ and @mapRelevance@ or @LensModality@.
class LensRelevance a where

  getRelevance :: a -> Relevance

  setRelevance :: Relevance -> a -> a
  setRelevance Relevance
h = (Relevance -> Relevance) -> a -> a
forall a. LensRelevance a => (Relevance -> Relevance) -> a -> a
mapRelevance (Relevance -> Relevance -> Relevance
forall a b. a -> b -> a
const Relevance
h)

  mapRelevance :: (Relevance -> Relevance) -> a -> a

  default getRelevance :: LensModality a => a -> Relevance
  getRelevance = Modality -> Relevance
modRelevance (Modality -> Relevance) -> (a -> Modality) -> a -> Relevance
forall b c a. (b -> c) -> (a -> b) -> a -> c
. a -> Modality
forall a. LensModality a => a -> Modality
getModality

  default mapRelevance :: LensModality a => (Relevance -> Relevance) -> a -> a
  mapRelevance Relevance -> Relevance
f = (Modality -> Modality) -> a -> a
forall a. LensModality a => (Modality -> Modality) -> a -> a
mapModality ((Modality -> Modality) -> a -> a)
-> (Modality -> Modality) -> a -> a
forall a b. (a -> b) -> a -> b
$ \ Modality
ai -> Modality
ai { modRelevance = f $ modRelevance ai }

instance LensRelevance Relevance where
  getRelevance :: Relevance -> Relevance
getRelevance = Relevance -> Relevance
forall a. a -> a
id
  setRelevance :: Relevance -> Relevance -> Relevance
setRelevance = Relevance -> Relevance -> Relevance
forall a b. a -> b -> a
const
  mapRelevance :: (Relevance -> Relevance) -> Relevance -> Relevance
mapRelevance = (Relevance -> Relevance) -> Relevance -> Relevance
forall a. a -> a
id

isRelevant :: LensRelevance a => a -> Bool
isRelevant :: forall a. LensRelevance a => a -> Bool
isRelevant a
a = a -> Relevance
forall a. LensRelevance a => a -> Relevance
getRelevance a
a Relevance -> Relevance -> Bool
forall a. Eq a => a -> a -> Bool
== Relevance
Relevant

isIrrelevant :: LensRelevance a => a -> Bool
isIrrelevant :: forall a. LensRelevance a => a -> Bool
isIrrelevant a
a = a -> Relevance
forall a. LensRelevance a => a -> Relevance
getRelevance a
a Relevance -> Relevance -> Bool
forall a. Eq a => a -> a -> Bool
== Relevance
Irrelevant

isNonStrict :: LensRelevance a => a -> Bool
isNonStrict :: forall a. LensRelevance a => a -> Bool
isNonStrict a
a = a -> Relevance
forall a. LensRelevance a => a -> Relevance
getRelevance a
a Relevance -> Relevance -> Bool
forall a. Eq a => a -> a -> Bool
== Relevance
NonStrict

-- | Information ordering.
-- @Relevant  \`moreRelevant\`
--  NonStrict \`moreRelevant\`
--  Irrelevant@
moreRelevant :: Relevance -> Relevance -> Bool
moreRelevant :: Relevance -> Relevance -> Bool
moreRelevant = Relevance -> Relevance -> Bool
forall a. Ord a => a -> a -> Bool
(<=)

-- | Equality ignoring origin.
sameRelevance :: Relevance -> Relevance -> Bool
sameRelevance :: Relevance -> Relevance -> Bool
sameRelevance = Relevance -> Relevance -> Bool
forall a. Eq a => a -> a -> Bool
(==)

-- | More relevant is smaller.
instance Ord Relevance where
  compare :: Relevance -> Relevance -> Ordering
compare = ((Relevance, Relevance) -> Ordering)
-> Relevance -> Relevance -> Ordering
forall a b c. ((a, b) -> c) -> a -> b -> c
curry (((Relevance, Relevance) -> Ordering)
 -> Relevance -> Relevance -> Ordering)
-> ((Relevance, Relevance) -> Ordering)
-> Relevance
-> Relevance
-> Ordering
forall a b. (a -> b) -> a -> b
$ \case
    (Relevance
r, Relevance
r') | Relevance
r Relevance -> Relevance -> Bool
forall a. Eq a => a -> a -> Bool
== Relevance
r' -> Ordering
EQ
    -- top
    (Relevance
_, Relevance
Irrelevant) -> Ordering
LT
    (Relevance
Irrelevant, Relevance
_) -> Ordering
GT
    -- bottom
    (Relevance
Relevant, Relevance
_) -> Ordering
LT
    (Relevance
_, Relevance
Relevant) -> Ordering
GT
    -- redundant case
    (Relevance
NonStrict,Relevance
NonStrict) -> Ordering
EQ

-- | More relevant is smaller.
instance PartialOrd Relevance where
  comparable :: Comparable Relevance
comparable = Comparable Relevance
forall a. Ord a => Comparable a
comparableOrd

-- | @usableRelevance rel == False@ iff we cannot use a variable of @rel@.
usableRelevance :: LensRelevance a => a -> Bool
usableRelevance :: forall a. LensRelevance a => a -> Bool
usableRelevance = a -> Bool
forall a. LensRelevance a => a -> Bool
isRelevant

-- | 'Relevance' composition.
--   'Irrelevant' is dominant, 'Relevant' is neutral.
--   Composition coincides with 'max'.
composeRelevance :: Relevance -> Relevance -> Relevance
composeRelevance :: Relevance -> Relevance -> Relevance
composeRelevance Relevance
r Relevance
r' =
  case (Relevance
r, Relevance
r') of
    (Relevance
Irrelevant, Relevance
_) -> Relevance
Irrelevant
    (Relevance
_, Relevance
Irrelevant) -> Relevance
Irrelevant
    (Relevance
NonStrict, Relevance
_)  -> Relevance
NonStrict
    (Relevance
_, Relevance
NonStrict)  -> Relevance
NonStrict
    (Relevance
Relevant, Relevance
Relevant) -> Relevance
Relevant

-- | Compose with relevance flag from the left.
--   This function is e.g. used to update the relevance information
--   on pattern variables @a@ after a match against something @rel@.
applyRelevance :: LensRelevance a => Relevance -> a -> a
applyRelevance :: forall a. LensRelevance a => Relevance -> a -> a
applyRelevance Relevance
rel = (Relevance -> Relevance) -> a -> a
forall a. LensRelevance a => (Relevance -> Relevance) -> a -> a
mapRelevance (Relevance
rel Relevance -> Relevance -> Relevance
`composeRelevance`)

-- | @inverseComposeRelevance r x@ returns the most irrelevant @y@
--   such that forall @x@, @y@ we have
--   @x \`moreRelevant\` (r \`composeRelevance\` y)@
--   iff
--   @(r \`inverseComposeRelevance\` x) \`moreRelevant\` y@ (Galois connection).
inverseComposeRelevance :: Relevance -> Relevance -> Relevance
inverseComposeRelevance :: Relevance -> Relevance -> Relevance
inverseComposeRelevance Relevance
r Relevance
x =
  case (Relevance
r, Relevance
x) of
    (Relevance
Relevant  , Relevance
x)          -> Relevance
x          -- going to relevant arg.: nothing changes
                                           -- because Relevant is comp.-neutral
    (Relevance
Irrelevant, Relevance
x)          -> Relevance
Relevant   -- going irrelevant: every thing usable
    (Relevance
NonStrict , Relevance
Irrelevant) -> Relevance
Irrelevant -- otherwise: irrelevant things remain unusable
    (Relevance
NonStrict , Relevance
_)          -> Relevance
Relevant   -- but @NonStrict@s become usable

-- | Left division by a 'Relevance'.
--   Used e.g. to modify context when going into a @rel@ argument.
inverseApplyRelevance :: LensRelevance a => Relevance -> a -> a
inverseApplyRelevance :: forall a. LensRelevance a => Relevance -> a -> a
inverseApplyRelevance Relevance
rel = (Relevance -> Relevance) -> a -> a
forall a. LensRelevance a => (Relevance -> Relevance) -> a -> a
mapRelevance (Relevance
rel Relevance -> Relevance -> Relevance
`inverseComposeRelevance`)

-- | 'Relevance' forms a semigroup under composition.
instance Semigroup (UnderComposition Relevance) where
  <> :: UnderComposition Relevance
-> UnderComposition Relevance -> UnderComposition Relevance
(<>) = (Relevance -> Relevance -> Relevance)
-> UnderComposition Relevance
-> UnderComposition Relevance
-> UnderComposition Relevance
forall a b c.
(a -> b -> c)
-> UnderComposition a -> UnderComposition b -> UnderComposition c
forall (f :: * -> *) a b c.
Applicative f =>
(a -> b -> c) -> f a -> f b -> f c
liftA2 Relevance -> Relevance -> Relevance
composeRelevance

-- | 'Relevant' is the unit under composition.
instance Monoid (UnderComposition Relevance) where
  mempty :: UnderComposition Relevance
mempty  = Relevance -> UnderComposition Relevance
forall a. a -> UnderComposition a
forall (f :: * -> *) a. Applicative f => a -> f a
pure Relevance
unitRelevance
  mappend :: UnderComposition Relevance
-> UnderComposition Relevance -> UnderComposition Relevance
mappend = UnderComposition Relevance
-> UnderComposition Relevance -> UnderComposition Relevance
forall a. Semigroup a => a -> a -> a
(<>)

instance POSemigroup (UnderComposition Relevance) where
instance POMonoid (UnderComposition Relevance) where

instance LeftClosedPOMonoid (UnderComposition Relevance) where
  inverseCompose :: UnderComposition Relevance
-> UnderComposition Relevance -> UnderComposition Relevance
inverseCompose = (Relevance -> Relevance -> Relevance)
-> UnderComposition Relevance
-> UnderComposition Relevance
-> UnderComposition Relevance
forall a b c.
(a -> b -> c)
-> UnderComposition a -> UnderComposition b -> UnderComposition c
forall (f :: * -> *) a b c.
Applicative f =>
(a -> b -> c) -> f a -> f b -> f c
liftA2 Relevance -> Relevance -> Relevance
inverseComposeRelevance

instance Semigroup (UnderAddition Relevance) where
  <> :: UnderAddition Relevance
-> UnderAddition Relevance -> UnderAddition Relevance
(<>) = (Relevance -> Relevance -> Relevance)
-> UnderAddition Relevance
-> UnderAddition Relevance
-> UnderAddition Relevance
forall a b c.
(a -> b -> c)
-> UnderAddition a -> UnderAddition b -> UnderAddition c
forall (f :: * -> *) a b c.
Applicative f =>
(a -> b -> c) -> f a -> f b -> f c
liftA2 Relevance -> Relevance -> Relevance
addRelevance

instance Monoid (UnderAddition Relevance) where
  mempty :: UnderAddition Relevance
mempty  = Relevance -> UnderAddition Relevance
forall a. a -> UnderAddition a
forall (f :: * -> *) a. Applicative f => a -> f a
pure Relevance
zeroRelevance
  mappend :: UnderAddition Relevance
-> UnderAddition Relevance -> UnderAddition Relevance
mappend = UnderAddition Relevance
-> UnderAddition Relevance -> UnderAddition Relevance
forall a. Semigroup a => a -> a -> a
(<>)

instance POSemigroup (UnderAddition Relevance) where
instance POMonoid (UnderAddition Relevance) where

-- | Combine inferred 'Relevance'.
--   The unit is 'Irrelevant'.
addRelevance :: Relevance -> Relevance -> Relevance
addRelevance :: Relevance -> Relevance -> Relevance
addRelevance = Relevance -> Relevance -> Relevance
forall a. Ord a => a -> a -> a
min

-- | 'Relevance' forms a monoid under addition, and even a semiring.
zeroRelevance :: Relevance
zeroRelevance :: Relevance
zeroRelevance = Relevance
Irrelevant

-- | Identity element under composition
unitRelevance :: Relevance
unitRelevance :: Relevance
unitRelevance = Relevance
Relevant

-- | Absorptive element under addition.
topRelevance :: Relevance
topRelevance :: Relevance
topRelevance = Relevance
Relevant

-- | Default Relevance is the identity element under composition
defaultRelevance :: Relevance
defaultRelevance :: Relevance
defaultRelevance = Relevance
unitRelevance

-- | Irrelevant function arguments may appear non-strictly in the codomain type.
irrToNonStrict :: Relevance -> Relevance
irrToNonStrict :: Relevance -> Relevance
irrToNonStrict Relevance
Irrelevant = Relevance
NonStrict
irrToNonStrict Relevance
rel        = Relevance
rel

-- | Applied when working on types (unless --experimental-irrelevance).
nonStrictToRel :: Relevance -> Relevance
nonStrictToRel :: Relevance -> Relevance
nonStrictToRel Relevance
NonStrict = Relevance
Relevant
nonStrictToRel Relevance
rel       = Relevance
rel

nonStrictToIrr :: Relevance -> Relevance
nonStrictToIrr :: Relevance -> Relevance
nonStrictToIrr Relevance
NonStrict = Relevance
Irrelevant
nonStrictToIrr Relevance
rel       = Relevance
rel

---------------------------------------------------------------------------
-- * Annotations
---------------------------------------------------------------------------

-- | We have a tuple of annotations, which might not be fully orthogonal.
data Annotation = Annotation
  { Annotation -> Lock
annLock :: Lock
    -- ^ Fitch-style dependent right adjoints.
    --   See Modal Dependent Type Theory and Dependent Right Adjoints, arXiv:1804.05236.
  } deriving (Annotation -> Annotation -> Bool
(Annotation -> Annotation -> Bool)
-> (Annotation -> Annotation -> Bool) -> Eq Annotation
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: Annotation -> Annotation -> Bool
== :: Annotation -> Annotation -> Bool
$c/= :: Annotation -> Annotation -> Bool
/= :: Annotation -> Annotation -> Bool
Eq, Eq Annotation
Eq Annotation =>
(Annotation -> Annotation -> Ordering)
-> (Annotation -> Annotation -> Bool)
-> (Annotation -> Annotation -> Bool)
-> (Annotation -> Annotation -> Bool)
-> (Annotation -> Annotation -> Bool)
-> (Annotation -> Annotation -> Annotation)
-> (Annotation -> Annotation -> Annotation)
-> Ord Annotation
Annotation -> Annotation -> Bool
Annotation -> Annotation -> Ordering
Annotation -> Annotation -> Annotation
forall a.
Eq a =>
(a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
$ccompare :: Annotation -> Annotation -> Ordering
compare :: Annotation -> Annotation -> Ordering
$c< :: Annotation -> Annotation -> Bool
< :: Annotation -> Annotation -> Bool
$c<= :: Annotation -> Annotation -> Bool
<= :: Annotation -> Annotation -> Bool
$c> :: Annotation -> Annotation -> Bool
> :: Annotation -> Annotation -> Bool
$c>= :: Annotation -> Annotation -> Bool
>= :: Annotation -> Annotation -> Bool
$cmax :: Annotation -> Annotation -> Annotation
max :: Annotation -> Annotation -> Annotation
$cmin :: Annotation -> Annotation -> Annotation
min :: Annotation -> Annotation -> Annotation
Ord, Int -> Annotation -> ShowS
[Annotation] -> ShowS
Annotation -> ArgName
(Int -> Annotation -> ShowS)
-> (Annotation -> ArgName)
-> ([Annotation] -> ShowS)
-> Show Annotation
forall a.
(Int -> a -> ShowS) -> (a -> ArgName) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> Annotation -> ShowS
showsPrec :: Int -> Annotation -> ShowS
$cshow :: Annotation -> ArgName
show :: Annotation -> ArgName
$cshowList :: [Annotation] -> ShowS
showList :: [Annotation] -> ShowS
Show, (forall x. Annotation -> Rep Annotation x)
-> (forall x. Rep Annotation x -> Annotation) -> Generic Annotation
forall x. Rep Annotation x -> Annotation
forall x. Annotation -> Rep Annotation x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cfrom :: forall x. Annotation -> Rep Annotation x
from :: forall x. Annotation -> Rep Annotation x
$cto :: forall x. Rep Annotation x -> Annotation
to :: forall x. Rep Annotation x -> Annotation
Generic)

instance HasRange Annotation where
  getRange :: Annotation -> Range
getRange Annotation
_ = Range
forall a. Range' a
noRange

instance KillRange Annotation where
  killRange :: Annotation -> Annotation
killRange = Annotation -> Annotation
forall a. a -> a
id

defaultAnnotation :: Annotation
defaultAnnotation :: Annotation
defaultAnnotation = Lock -> Annotation
Annotation Lock
defaultLock

instance NFData Annotation where
  rnf :: Annotation -> ()
rnf (Annotation Lock
l) = Lock -> ()
forall a. NFData a => a -> ()
rnf Lock
l

class LensAnnotation a where

  getAnnotation :: a -> Annotation

  setAnnotation :: Annotation -> a -> a

  mapAnnotation :: (Annotation -> Annotation) -> a -> a
  mapAnnotation Annotation -> Annotation
f a
a = Annotation -> a -> a
forall a. LensAnnotation a => Annotation -> a -> a
setAnnotation (Annotation -> Annotation
f (Annotation -> Annotation) -> Annotation -> Annotation
forall a b. (a -> b) -> a -> b
$ a -> Annotation
forall a. LensAnnotation a => a -> Annotation
getAnnotation a
a) a
a

  default getAnnotation :: LensArgInfo a => a -> Annotation
  getAnnotation = ArgInfo -> Annotation
argInfoAnnotation (ArgInfo -> Annotation) -> (a -> ArgInfo) -> a -> Annotation
forall b c a. (b -> c) -> (a -> b) -> a -> c
. a -> ArgInfo
forall a. LensArgInfo a => a -> ArgInfo
getArgInfo

  default setAnnotation :: LensArgInfo a => Annotation -> a -> a
  setAnnotation Annotation
a = (ArgInfo -> ArgInfo) -> a -> a
forall a. LensArgInfo a => (ArgInfo -> ArgInfo) -> a -> a
mapArgInfo ((ArgInfo -> ArgInfo) -> a -> a) -> (ArgInfo -> ArgInfo) -> a -> a
forall a b. (a -> b) -> a -> b
$ \ ArgInfo
ai -> ArgInfo
ai { argInfoAnnotation = a }

instance LensAnnotation Annotation where
  getAnnotation :: Annotation -> Annotation
getAnnotation = Annotation -> Annotation
forall a. a -> a
id
  setAnnotation :: Annotation -> Annotation -> Annotation
setAnnotation = Annotation -> Annotation -> Annotation
forall a b. a -> b -> a
const
  mapAnnotation :: (Annotation -> Annotation) -> Annotation -> Annotation
mapAnnotation = (Annotation -> Annotation) -> Annotation -> Annotation
forall a. a -> a
id

instance LensAnnotation (Arg t) where
  getAnnotation :: Arg t -> Annotation
getAnnotation = ArgInfo -> Annotation
forall a. LensAnnotation a => a -> Annotation
getAnnotation (ArgInfo -> Annotation)
-> (Arg t -> ArgInfo) -> Arg t -> Annotation
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Arg t -> ArgInfo
forall a. LensArgInfo a => a -> ArgInfo
getArgInfo
  setAnnotation :: Annotation -> Arg t -> Arg t
setAnnotation = (ArgInfo -> ArgInfo) -> Arg t -> Arg t
forall a. LensArgInfo a => (ArgInfo -> ArgInfo) -> a -> a
mapArgInfo ((ArgInfo -> ArgInfo) -> Arg t -> Arg t)
-> (Annotation -> ArgInfo -> ArgInfo)
-> Annotation
-> Arg t
-> Arg t
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Annotation -> ArgInfo -> ArgInfo
forall a. LensAnnotation a => Annotation -> a -> a
setAnnotation


---------------------------------------------------------------------------
-- * Locks
---------------------------------------------------------------------------

data LockOrigin
  = LockOLock -- ^ The user wrote @lock.
  | LockOTick -- ^ The user wrote @tick.
  deriving (Int -> LockOrigin -> ShowS
[LockOrigin] -> ShowS
LockOrigin -> ArgName
(Int -> LockOrigin -> ShowS)
-> (LockOrigin -> ArgName)
-> ([LockOrigin] -> ShowS)
-> Show LockOrigin
forall a.
(Int -> a -> ShowS) -> (a -> ArgName) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> LockOrigin -> ShowS
showsPrec :: Int -> LockOrigin -> ShowS
$cshow :: LockOrigin -> ArgName
show :: LockOrigin -> ArgName
$cshowList :: [LockOrigin] -> ShowS
showList :: [LockOrigin] -> ShowS
Show, (forall x. LockOrigin -> Rep LockOrigin x)
-> (forall x. Rep LockOrigin x -> LockOrigin) -> Generic LockOrigin
forall x. Rep LockOrigin x -> LockOrigin
forall x. LockOrigin -> Rep LockOrigin x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cfrom :: forall x. LockOrigin -> Rep LockOrigin x
from :: forall x. LockOrigin -> Rep LockOrigin x
$cto :: forall x. Rep LockOrigin x -> LockOrigin
to :: forall x. Rep LockOrigin x -> LockOrigin
Generic, LockOrigin -> LockOrigin -> Bool
(LockOrigin -> LockOrigin -> Bool)
-> (LockOrigin -> LockOrigin -> Bool) -> Eq LockOrigin
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: LockOrigin -> LockOrigin -> Bool
== :: LockOrigin -> LockOrigin -> Bool
$c/= :: LockOrigin -> LockOrigin -> Bool
/= :: LockOrigin -> LockOrigin -> Bool
Eq, Int -> LockOrigin
LockOrigin -> Int
LockOrigin -> [LockOrigin]
LockOrigin -> LockOrigin
LockOrigin -> LockOrigin -> [LockOrigin]
LockOrigin -> LockOrigin -> LockOrigin -> [LockOrigin]
(LockOrigin -> LockOrigin)
-> (LockOrigin -> LockOrigin)
-> (Int -> LockOrigin)
-> (LockOrigin -> Int)
-> (LockOrigin -> [LockOrigin])
-> (LockOrigin -> LockOrigin -> [LockOrigin])
-> (LockOrigin -> LockOrigin -> [LockOrigin])
-> (LockOrigin -> LockOrigin -> LockOrigin -> [LockOrigin])
-> Enum LockOrigin
forall a.
(a -> a)
-> (a -> a)
-> (Int -> a)
-> (a -> Int)
-> (a -> [a])
-> (a -> a -> [a])
-> (a -> a -> [a])
-> (a -> a -> a -> [a])
-> Enum a
$csucc :: LockOrigin -> LockOrigin
succ :: LockOrigin -> LockOrigin
$cpred :: LockOrigin -> LockOrigin
pred :: LockOrigin -> LockOrigin
$ctoEnum :: Int -> LockOrigin
toEnum :: Int -> LockOrigin
$cfromEnum :: LockOrigin -> Int
fromEnum :: LockOrigin -> Int
$cenumFrom :: LockOrigin -> [LockOrigin]
enumFrom :: LockOrigin -> [LockOrigin]
$cenumFromThen :: LockOrigin -> LockOrigin -> [LockOrigin]
enumFromThen :: LockOrigin -> LockOrigin -> [LockOrigin]
$cenumFromTo :: LockOrigin -> LockOrigin -> [LockOrigin]
enumFromTo :: LockOrigin -> LockOrigin -> [LockOrigin]
$cenumFromThenTo :: LockOrigin -> LockOrigin -> LockOrigin -> [LockOrigin]
enumFromThenTo :: LockOrigin -> LockOrigin -> LockOrigin -> [LockOrigin]
Enum, LockOrigin
LockOrigin -> LockOrigin -> Bounded LockOrigin
forall a. a -> a -> Bounded a
$cminBound :: LockOrigin
minBound :: LockOrigin
$cmaxBound :: LockOrigin
maxBound :: LockOrigin
Bounded, Eq LockOrigin
Eq LockOrigin =>
(LockOrigin -> LockOrigin -> Ordering)
-> (LockOrigin -> LockOrigin -> Bool)
-> (LockOrigin -> LockOrigin -> Bool)
-> (LockOrigin -> LockOrigin -> Bool)
-> (LockOrigin -> LockOrigin -> Bool)
-> (LockOrigin -> LockOrigin -> LockOrigin)
-> (LockOrigin -> LockOrigin -> LockOrigin)
-> Ord LockOrigin
LockOrigin -> LockOrigin -> Bool
LockOrigin -> LockOrigin -> Ordering
LockOrigin -> LockOrigin -> LockOrigin
forall a.
Eq a =>
(a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
$ccompare :: LockOrigin -> LockOrigin -> Ordering
compare :: LockOrigin -> LockOrigin -> Ordering
$c< :: LockOrigin -> LockOrigin -> Bool
< :: LockOrigin -> LockOrigin -> Bool
$c<= :: LockOrigin -> LockOrigin -> Bool
<= :: LockOrigin -> LockOrigin -> Bool
$c> :: LockOrigin -> LockOrigin -> Bool
> :: LockOrigin -> LockOrigin -> Bool
$c>= :: LockOrigin -> LockOrigin -> Bool
>= :: LockOrigin -> LockOrigin -> Bool
$cmax :: LockOrigin -> LockOrigin -> LockOrigin
max :: LockOrigin -> LockOrigin -> LockOrigin
$cmin :: LockOrigin -> LockOrigin -> LockOrigin
min :: LockOrigin -> LockOrigin -> LockOrigin
Ord)

data Lock
  = IsNotLock
  | IsLock LockOrigin
  -- ^ In the future there might be different kinds of them.
  --   For now we assume lock weakening.
  deriving (Int -> Lock -> ShowS
[Lock] -> ShowS
Lock -> ArgName
(Int -> Lock -> ShowS)
-> (Lock -> ArgName) -> ([Lock] -> ShowS) -> Show Lock
forall a.
(Int -> a -> ShowS) -> (a -> ArgName) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> Lock -> ShowS
showsPrec :: Int -> Lock -> ShowS
$cshow :: Lock -> ArgName
show :: Lock -> ArgName
$cshowList :: [Lock] -> ShowS
showList :: [Lock] -> ShowS
Show, (forall x. Lock -> Rep Lock x)
-> (forall x. Rep Lock x -> Lock) -> Generic Lock
forall x. Rep Lock x -> Lock
forall x. Lock -> Rep Lock x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cfrom :: forall x. Lock -> Rep Lock x
from :: forall x. Lock -> Rep Lock x
$cto :: forall x. Rep Lock x -> Lock
to :: forall x. Rep Lock x -> Lock
Generic, Lock -> Lock -> Bool
(Lock -> Lock -> Bool) -> (Lock -> Lock -> Bool) -> Eq Lock
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: Lock -> Lock -> Bool
== :: Lock -> Lock -> Bool
$c/= :: Lock -> Lock -> Bool
/= :: Lock -> Lock -> Bool
Eq, Eq Lock
Eq Lock =>
(Lock -> Lock -> Ordering)
-> (Lock -> Lock -> Bool)
-> (Lock -> Lock -> Bool)
-> (Lock -> Lock -> Bool)
-> (Lock -> Lock -> Bool)
-> (Lock -> Lock -> Lock)
-> (Lock -> Lock -> Lock)
-> Ord Lock
Lock -> Lock -> Bool
Lock -> Lock -> Ordering
Lock -> Lock -> Lock
forall a.
Eq a =>
(a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
$ccompare :: Lock -> Lock -> Ordering
compare :: Lock -> Lock -> Ordering
$c< :: Lock -> Lock -> Bool
< :: Lock -> Lock -> Bool
$c<= :: Lock -> Lock -> Bool
<= :: Lock -> Lock -> Bool
$c> :: Lock -> Lock -> Bool
> :: Lock -> Lock -> Bool
$c>= :: Lock -> Lock -> Bool
>= :: Lock -> Lock -> Bool
$cmax :: Lock -> Lock -> Lock
max :: Lock -> Lock -> Lock
$cmin :: Lock -> Lock -> Lock
min :: Lock -> Lock -> Lock
Ord)

defaultLock :: Lock
defaultLock :: Lock
defaultLock = Lock
IsNotLock

instance NFData Lock where
  rnf :: Lock -> ()
rnf Lock
IsNotLock          = ()
  rnf (IsLock LockOrigin
LockOLock) = ()
  rnf (IsLock LockOrigin
LockOTick) = ()

class LensLock a where

  getLock :: a -> Lock

  setLock :: Lock -> a -> a
  setLock = (Lock -> Lock) -> a -> a
forall a. LensLock a => (Lock -> Lock) -> a -> a
mapLock ((Lock -> Lock) -> a -> a)
-> (Lock -> Lock -> Lock) -> Lock -> a -> a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Lock -> Lock -> Lock
forall a b. a -> b -> a
const

  mapLock :: (Lock -> Lock) -> a -> a
  mapLock Lock -> Lock
f a
a = Lock -> a -> a
forall a. LensLock a => Lock -> a -> a
setLock (Lock -> Lock
f (Lock -> Lock) -> Lock -> Lock
forall a b. (a -> b) -> a -> b
$ a -> Lock
forall a. LensLock a => a -> Lock
getLock a
a) a
a

instance LensLock Lock where
  getLock :: Lock -> Lock
getLock = Lock -> Lock
forall a. a -> a
id
  setLock :: Lock -> Lock -> Lock
setLock = Lock -> Lock -> Lock
forall a b. a -> b -> a
const
  mapLock :: (Lock -> Lock) -> Lock -> Lock
mapLock = (Lock -> Lock) -> Lock -> Lock
forall a. a -> a
id

instance LensLock ArgInfo where
  getLock :: ArgInfo -> Lock
getLock = Annotation -> Lock
annLock (Annotation -> Lock) -> (ArgInfo -> Annotation) -> ArgInfo -> Lock
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ArgInfo -> Annotation
argInfoAnnotation
  setLock :: Lock -> ArgInfo -> ArgInfo
setLock Lock
l ArgInfo
info = ArgInfo
info { argInfoAnnotation = (argInfoAnnotation info){ annLock = l } }

instance LensLock (Arg t) where
  getLock :: Arg t -> Lock
getLock = ArgInfo -> Lock
forall a. LensLock a => a -> Lock
getLock (ArgInfo -> Lock) -> (Arg t -> ArgInfo) -> Arg t -> Lock
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Arg t -> ArgInfo
forall a. LensArgInfo a => a -> ArgInfo
getArgInfo
  setLock :: Lock -> Arg t -> Arg t
setLock = (ArgInfo -> ArgInfo) -> Arg t -> Arg t
forall a. LensArgInfo a => (ArgInfo -> ArgInfo) -> a -> a
mapArgInfo ((ArgInfo -> ArgInfo) -> Arg t -> Arg t)
-> (Lock -> ArgInfo -> ArgInfo) -> Lock -> Arg t -> Arg t
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Lock -> ArgInfo -> ArgInfo
forall a. LensLock a => Lock -> a -> a
setLock

---------------------------------------------------------------------------
-- * Cohesion
---------------------------------------------------------------------------

-- | Cohesion modalities
--   see "Brouwer's fixed-point theorem in real-cohesive homotopy type theory" (arXiv:1509.07584)
--   types are now given an additional topological layer which the modalities interact with.
data Cohesion
  = Flat        -- ^ same points, discrete topology, idempotent comonad, box-like.
  | Continuous  -- ^ identity modality.
  -- | Sharp    -- ^ same points, codiscrete topology, idempotent monad, diamond-like.
  | Squash      -- ^ single point space, artificially added for Flat left-composition.
    deriving (Int -> Cohesion -> ShowS
[Cohesion] -> ShowS
Cohesion -> ArgName
(Int -> Cohesion -> ShowS)
-> (Cohesion -> ArgName) -> ([Cohesion] -> ShowS) -> Show Cohesion
forall a.
(Int -> a -> ShowS) -> (a -> ArgName) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> Cohesion -> ShowS
showsPrec :: Int -> Cohesion -> ShowS
$cshow :: Cohesion -> ArgName
show :: Cohesion -> ArgName
$cshowList :: [Cohesion] -> ShowS
showList :: [Cohesion] -> ShowS
Show, Cohesion -> Cohesion -> Bool
(Cohesion -> Cohesion -> Bool)
-> (Cohesion -> Cohesion -> Bool) -> Eq Cohesion
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: Cohesion -> Cohesion -> Bool
== :: Cohesion -> Cohesion -> Bool
$c/= :: Cohesion -> Cohesion -> Bool
/= :: Cohesion -> Cohesion -> Bool
Eq, Int -> Cohesion
Cohesion -> Int
Cohesion -> [Cohesion]
Cohesion -> Cohesion
Cohesion -> Cohesion -> [Cohesion]
Cohesion -> Cohesion -> Cohesion -> [Cohesion]
(Cohesion -> Cohesion)
-> (Cohesion -> Cohesion)
-> (Int -> Cohesion)
-> (Cohesion -> Int)
-> (Cohesion -> [Cohesion])
-> (Cohesion -> Cohesion -> [Cohesion])
-> (Cohesion -> Cohesion -> [Cohesion])
-> (Cohesion -> Cohesion -> Cohesion -> [Cohesion])
-> Enum Cohesion
forall a.
(a -> a)
-> (a -> a)
-> (Int -> a)
-> (a -> Int)
-> (a -> [a])
-> (a -> a -> [a])
-> (a -> a -> [a])
-> (a -> a -> a -> [a])
-> Enum a
$csucc :: Cohesion -> Cohesion
succ :: Cohesion -> Cohesion
$cpred :: Cohesion -> Cohesion
pred :: Cohesion -> Cohesion
$ctoEnum :: Int -> Cohesion
toEnum :: Int -> Cohesion
$cfromEnum :: Cohesion -> Int
fromEnum :: Cohesion -> Int
$cenumFrom :: Cohesion -> [Cohesion]
enumFrom :: Cohesion -> [Cohesion]
$cenumFromThen :: Cohesion -> Cohesion -> [Cohesion]
enumFromThen :: Cohesion -> Cohesion -> [Cohesion]
$cenumFromTo :: Cohesion -> Cohesion -> [Cohesion]
enumFromTo :: Cohesion -> Cohesion -> [Cohesion]
$cenumFromThenTo :: Cohesion -> Cohesion -> Cohesion -> [Cohesion]
enumFromThenTo :: Cohesion -> Cohesion -> Cohesion -> [Cohesion]
Enum, Cohesion
Cohesion -> Cohesion -> Bounded Cohesion
forall a. a -> a -> Bounded a
$cminBound :: Cohesion
minBound :: Cohesion
$cmaxBound :: Cohesion
maxBound :: Cohesion
Bounded, (forall x. Cohesion -> Rep Cohesion x)
-> (forall x. Rep Cohesion x -> Cohesion) -> Generic Cohesion
forall x. Rep Cohesion x -> Cohesion
forall x. Cohesion -> Rep Cohesion x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cfrom :: forall x. Cohesion -> Rep Cohesion x
from :: forall x. Cohesion -> Rep Cohesion x
$cto :: forall x. Rep Cohesion x -> Cohesion
to :: forall x. Rep Cohesion x -> Cohesion
Generic)

allCohesions :: [Cohesion]
allCohesions :: [Cohesion]
allCohesions = [Cohesion
forall a. Bounded a => a
minBound..Cohesion
forall a. Bounded a => a
maxBound]

instance HasRange Cohesion where
  getRange :: Cohesion -> Range
getRange Cohesion
_ = Range
forall a. Range' a
noRange

instance SetRange Cohesion where
  setRange :: Range -> Cohesion -> Cohesion
setRange Range
_ = Cohesion -> Cohesion
forall a. a -> a
id

instance KillRange Cohesion where
  killRange :: Cohesion -> Cohesion
killRange Cohesion
rel = Cohesion
rel -- no range to kill

instance NFData Cohesion where
  rnf :: Cohesion -> ()
rnf Cohesion
Flat       = ()
  rnf Cohesion
Continuous = ()
  rnf Cohesion
Squash     = ()

-- | A lens to access the 'Cohesion' attribute in data structures.
--   Minimal implementation: @getCohesion@ and @mapCohesion@ or @LensModality@.
class LensCohesion a where

  getCohesion :: a -> Cohesion

  setCohesion :: Cohesion -> a -> a
  setCohesion Cohesion
h = (Cohesion -> Cohesion) -> a -> a
forall a. LensCohesion a => (Cohesion -> Cohesion) -> a -> a
mapCohesion (Cohesion -> Cohesion -> Cohesion
forall a b. a -> b -> a
const Cohesion
h)

  mapCohesion :: (Cohesion -> Cohesion) -> a -> a

  default getCohesion :: LensModality a => a -> Cohesion
  getCohesion = Modality -> Cohesion
modCohesion (Modality -> Cohesion) -> (a -> Modality) -> a -> Cohesion
forall b c a. (b -> c) -> (a -> b) -> a -> c
. a -> Modality
forall a. LensModality a => a -> Modality
getModality

  default mapCohesion :: LensModality a => (Cohesion -> Cohesion) -> a -> a
  mapCohesion Cohesion -> Cohesion
f = (Modality -> Modality) -> a -> a
forall a. LensModality a => (Modality -> Modality) -> a -> a
mapModality ((Modality -> Modality) -> a -> a)
-> (Modality -> Modality) -> a -> a
forall a b. (a -> b) -> a -> b
$ \ Modality
ai -> Modality
ai { modCohesion = f $ modCohesion ai }

instance LensCohesion Cohesion where
  getCohesion :: Cohesion -> Cohesion
getCohesion = Cohesion -> Cohesion
forall a. a -> a
id
  setCohesion :: Cohesion -> Cohesion -> Cohesion
setCohesion = Cohesion -> Cohesion -> Cohesion
forall a b. a -> b -> a
const
  mapCohesion :: (Cohesion -> Cohesion) -> Cohesion -> Cohesion
mapCohesion = (Cohesion -> Cohesion) -> Cohesion -> Cohesion
forall a. a -> a
id

-- | Information ordering.
-- @Flat  \`moreCohesion\`
--  Continuous \`moreCohesion\`
--  Sharp \`moreCohesion\`
--  Squash@
moreCohesion :: Cohesion -> Cohesion -> Bool
moreCohesion :: Cohesion -> Cohesion -> Bool
moreCohesion = Cohesion -> Cohesion -> Bool
forall a. Ord a => a -> a -> Bool
(<=)

-- | Equality ignoring origin.
sameCohesion :: Cohesion -> Cohesion -> Bool
sameCohesion :: Cohesion -> Cohesion -> Bool
sameCohesion = Cohesion -> Cohesion -> Bool
forall a. Eq a => a -> a -> Bool
(==)

-- | Order is given by implication: flatter is smaller.
instance Ord Cohesion where
  compare :: Cohesion -> Cohesion -> Ordering
compare = ((Cohesion, Cohesion) -> Ordering)
-> Cohesion -> Cohesion -> Ordering
forall a b c. ((a, b) -> c) -> a -> b -> c
curry (((Cohesion, Cohesion) -> Ordering)
 -> Cohesion -> Cohesion -> Ordering)
-> ((Cohesion, Cohesion) -> Ordering)
-> Cohesion
-> Cohesion
-> Ordering
forall a b. (a -> b) -> a -> b
$ \case
    (Cohesion
r, Cohesion
r') | Cohesion
r Cohesion -> Cohesion -> Bool
forall a. Eq a => a -> a -> Bool
== Cohesion
r' -> Ordering
EQ
    -- top
    (Cohesion
_, Cohesion
Squash) -> Ordering
LT
    (Cohesion
Squash, Cohesion
_) -> Ordering
GT
    -- bottom
    (Cohesion
Flat, Cohesion
_) -> Ordering
LT
    (Cohesion
_, Cohesion
Flat) -> Ordering
GT
    -- redundant case
    (Cohesion
Continuous,Cohesion
Continuous) -> Ordering
EQ

-- | Flatter is smaller.
instance PartialOrd Cohesion where
  comparable :: Comparable Cohesion
comparable = Comparable Cohesion
forall a. Ord a => Comparable a
comparableOrd

-- | @usableCohesion rel == False@ iff we cannot use a variable of @rel@.
usableCohesion :: LensCohesion a => a -> Bool
usableCohesion :: forall a. LensCohesion a => a -> Bool
usableCohesion a
a = a -> Cohesion
forall a. LensCohesion a => a -> Cohesion
getCohesion a
a Cohesion -> Cohesion -> Bool
`moreCohesion` Cohesion
Continuous

-- | 'Cohesion' composition.
--   'Squash' is dominant, 'Continuous' is neutral.
composeCohesion :: Cohesion -> Cohesion -> Cohesion
composeCohesion :: Cohesion -> Cohesion -> Cohesion
composeCohesion Cohesion
r Cohesion
r' =
  case (Cohesion
r, Cohesion
r') of
    (Cohesion
Squash, Cohesion
_) -> Cohesion
Squash
    (Cohesion
_, Cohesion
Squash) -> Cohesion
Squash
    (Cohesion
Flat, Cohesion
_)  -> Cohesion
Flat
    (Cohesion
_, Cohesion
Flat)  -> Cohesion
Flat
    (Cohesion
Continuous, Cohesion
Continuous) -> Cohesion
Continuous

-- | Compose with cohesion flag from the left.
--   This function is e.g. used to update the cohesion information
--   on pattern variables @a@ after a match against something of cohesion @rel@.
applyCohesion :: LensCohesion a => Cohesion -> a -> a
applyCohesion :: forall a. LensCohesion a => Cohesion -> a -> a
applyCohesion Cohesion
rel = (Cohesion -> Cohesion) -> a -> a
forall a. LensCohesion a => (Cohesion -> Cohesion) -> a -> a
mapCohesion (Cohesion
rel Cohesion -> Cohesion -> Cohesion
`composeCohesion`)

-- | @inverseComposeCohesion r x@ returns the least @y@
--   such that forall @x@, @y@ we have
--   @x \`moreCohesion\` (r \`composeCohesion\` y)@
--   iff
--   @(r \`inverseComposeCohesion\` x) \`moreCohesion\` y@ (Galois connection).
--   The above law fails for @r = Squash@.
inverseComposeCohesion :: Cohesion -> Cohesion -> Cohesion
inverseComposeCohesion :: Cohesion -> Cohesion -> Cohesion
inverseComposeCohesion Cohesion
r Cohesion
x =
  case (Cohesion
r, Cohesion
x) of
    (Cohesion
Continuous  , Cohesion
x) -> Cohesion
x          -- going to continous arg.: nothing changes
                                    -- because Continuous is comp.-neutral
    (Cohesion
Squash, Cohesion
x)       -> Cohesion
Flat       -- in squash position everything is usable
    (Cohesion
Flat , Cohesion
Flat)     -> Cohesion
Flat       -- otherwise: Flat things remain Flat
    (Cohesion
Flat , Cohesion
_)        -> Cohesion
Squash     -- but everything else becomes unusable.

-- | Left division by a 'Cohesion'.
--   Used e.g. to modify context when going into a @rel@ argument.
inverseApplyCohesion :: LensCohesion a => Cohesion -> a -> a
inverseApplyCohesion :: forall a. LensCohesion a => Cohesion -> a -> a
inverseApplyCohesion Cohesion
rel = (Cohesion -> Cohesion) -> a -> a
forall a. LensCohesion a => (Cohesion -> Cohesion) -> a -> a
mapCohesion (Cohesion
rel Cohesion -> Cohesion -> Cohesion
`inverseComposeCohesion`)

-- | 'Cohesion' forms a semigroup under composition.
instance Semigroup (UnderComposition Cohesion) where
  <> :: UnderComposition Cohesion
-> UnderComposition Cohesion -> UnderComposition Cohesion
(<>) = (Cohesion -> Cohesion -> Cohesion)
-> UnderComposition Cohesion
-> UnderComposition Cohesion
-> UnderComposition Cohesion
forall a b c.
(a -> b -> c)
-> UnderComposition a -> UnderComposition b -> UnderComposition c
forall (f :: * -> *) a b c.
Applicative f =>
(a -> b -> c) -> f a -> f b -> f c
liftA2 Cohesion -> Cohesion -> Cohesion
composeCohesion

-- | 'Continous' is the multiplicative unit.
instance Monoid (UnderComposition Cohesion) where
  mempty :: UnderComposition Cohesion
mempty  = Cohesion -> UnderComposition Cohesion
forall a. a -> UnderComposition a
forall (f :: * -> *) a. Applicative f => a -> f a
pure Cohesion
unitCohesion
  mappend :: UnderComposition Cohesion
-> UnderComposition Cohesion -> UnderComposition Cohesion
mappend = UnderComposition Cohesion
-> UnderComposition Cohesion -> UnderComposition Cohesion
forall a. Semigroup a => a -> a -> a
(<>)

instance POSemigroup (UnderComposition Cohesion) where
instance POMonoid (UnderComposition Cohesion) where

instance LeftClosedPOMonoid (UnderComposition Cohesion) where
  inverseCompose :: UnderComposition Cohesion
-> UnderComposition Cohesion -> UnderComposition Cohesion
inverseCompose = (Cohesion -> Cohesion -> Cohesion)
-> UnderComposition Cohesion
-> UnderComposition Cohesion
-> UnderComposition Cohesion
forall a b c.
(a -> b -> c)
-> UnderComposition a -> UnderComposition b -> UnderComposition c
forall (f :: * -> *) a b c.
Applicative f =>
(a -> b -> c) -> f a -> f b -> f c
liftA2 Cohesion -> Cohesion -> Cohesion
inverseComposeCohesion

-- | 'Cohesion' forms a semigroup under addition.
instance Semigroup (UnderAddition Cohesion) where
  <> :: UnderAddition Cohesion
-> UnderAddition Cohesion -> UnderAddition Cohesion
(<>) = (Cohesion -> Cohesion -> Cohesion)
-> UnderAddition Cohesion
-> UnderAddition Cohesion
-> UnderAddition Cohesion
forall a b c.
(a -> b -> c)
-> UnderAddition a -> UnderAddition b -> UnderAddition c
forall (f :: * -> *) a b c.
Applicative f =>
(a -> b -> c) -> f a -> f b -> f c
liftA2 Cohesion -> Cohesion -> Cohesion
addCohesion

-- | 'Squash' is the additive unit.
instance Monoid (UnderAddition Cohesion) where
  mempty :: UnderAddition Cohesion
mempty  = Cohesion -> UnderAddition Cohesion
forall a. a -> UnderAddition a
forall (f :: * -> *) a. Applicative f => a -> f a
pure Cohesion
zeroCohesion
  mappend :: UnderAddition Cohesion
-> UnderAddition Cohesion -> UnderAddition Cohesion
mappend = UnderAddition Cohesion
-> UnderAddition Cohesion -> UnderAddition Cohesion
forall a. Semigroup a => a -> a -> a
(<>)

instance POSemigroup (UnderAddition Cohesion) where
instance POMonoid (UnderAddition Cohesion) where

-- | Combine inferred 'Cohesion'.
--   The unit is 'Squash'.
addCohesion :: Cohesion -> Cohesion -> Cohesion
addCohesion :: Cohesion -> Cohesion -> Cohesion
addCohesion = Cohesion -> Cohesion -> Cohesion
forall a. Ord a => a -> a -> a
min

-- | 'Cohesion' forms a monoid under addition, and even a semiring.
zeroCohesion :: Cohesion
zeroCohesion :: Cohesion
zeroCohesion = Cohesion
Squash

-- | Identity under composition
unitCohesion :: Cohesion
unitCohesion :: Cohesion
unitCohesion = Cohesion
Continuous

-- | Absorptive element under addition.
topCohesion :: Cohesion
topCohesion :: Cohesion
topCohesion = Cohesion
Flat

-- | Default Cohesion is the identity element under composition
defaultCohesion :: Cohesion
defaultCohesion :: Cohesion
defaultCohesion = Cohesion
unitCohesion

---------------------------------------------------------------------------
-- * Origin of arguments (user-written, inserted or reflected)
---------------------------------------------------------------------------

-- | Origin of arguments.
data Origin
  = UserWritten  -- ^ From the source file / user input.  (Preserve!)
  | Inserted     -- ^ E.g. inserted hidden arguments.
  | Reflected    -- ^ Produced by the reflection machinery.
  | CaseSplit    -- ^ Produced by an interactive case split.
  | Substitution -- ^ Named application produced to represent a substitution. E.g. "?0 (x = n)" instead of "?0 n"
  | ExpandedPun  -- ^ An expanded hidden argument pun.
  deriving (Int -> Origin -> ShowS
[Origin] -> ShowS
Origin -> ArgName
(Int -> Origin -> ShowS)
-> (Origin -> ArgName) -> ([Origin] -> ShowS) -> Show Origin
forall a.
(Int -> a -> ShowS) -> (a -> ArgName) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> Origin -> ShowS
showsPrec :: Int -> Origin -> ShowS
$cshow :: Origin -> ArgName
show :: Origin -> ArgName
$cshowList :: [Origin] -> ShowS
showList :: [Origin] -> ShowS
Show, Origin -> Origin -> Bool
(Origin -> Origin -> Bool)
-> (Origin -> Origin -> Bool) -> Eq Origin
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: Origin -> Origin -> Bool
== :: Origin -> Origin -> Bool
$c/= :: Origin -> Origin -> Bool
/= :: Origin -> Origin -> Bool
Eq, Eq Origin
Eq Origin =>
(Origin -> Origin -> Ordering)
-> (Origin -> Origin -> Bool)
-> (Origin -> Origin -> Bool)
-> (Origin -> Origin -> Bool)
-> (Origin -> Origin -> Bool)
-> (Origin -> Origin -> Origin)
-> (Origin -> Origin -> Origin)
-> Ord Origin
Origin -> Origin -> Bool
Origin -> Origin -> Ordering
Origin -> Origin -> Origin
forall a.
Eq a =>
(a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
$ccompare :: Origin -> Origin -> Ordering
compare :: Origin -> Origin -> Ordering
$c< :: Origin -> Origin -> Bool
< :: Origin -> Origin -> Bool
$c<= :: Origin -> Origin -> Bool
<= :: Origin -> Origin -> Bool
$c> :: Origin -> Origin -> Bool
> :: Origin -> Origin -> Bool
$c>= :: Origin -> Origin -> Bool
>= :: Origin -> Origin -> Bool
$cmax :: Origin -> Origin -> Origin
max :: Origin -> Origin -> Origin
$cmin :: Origin -> Origin -> Origin
min :: Origin -> Origin -> Origin
Ord)

instance HasRange Origin where
  getRange :: Origin -> Range
getRange Origin
_ = Range
forall a. Range' a
noRange

instance KillRange Origin where
  killRange :: Origin -> Origin
killRange = Origin -> Origin
forall a. a -> a
id

instance NFData Origin where
  rnf :: Origin -> ()
rnf Origin
UserWritten = ()
  rnf Origin
Inserted = ()
  rnf Origin
Reflected = ()
  rnf Origin
CaseSplit = ()
  rnf Origin
Substitution = ()
  rnf Origin
ExpandedPun = ()

-- | Decorating something with 'Origin' information.
data WithOrigin a = WithOrigin
  { forall a. WithOrigin a -> Origin
woOrigin :: !Origin
  , forall a. WithOrigin a -> a
woThing  :: a
  }
  deriving (WithOrigin a -> WithOrigin a -> Bool
(WithOrigin a -> WithOrigin a -> Bool)
-> (WithOrigin a -> WithOrigin a -> Bool) -> Eq (WithOrigin a)
forall a. Eq a => WithOrigin a -> WithOrigin a -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: forall a. Eq a => WithOrigin a -> WithOrigin a -> Bool
== :: WithOrigin a -> WithOrigin a -> Bool
$c/= :: forall a. Eq a => WithOrigin a -> WithOrigin a -> Bool
/= :: WithOrigin a -> WithOrigin a -> Bool
Eq, Eq (WithOrigin a)
Eq (WithOrigin a) =>
(WithOrigin a -> WithOrigin a -> Ordering)
-> (WithOrigin a -> WithOrigin a -> Bool)
-> (WithOrigin a -> WithOrigin a -> Bool)
-> (WithOrigin a -> WithOrigin a -> Bool)
-> (WithOrigin a -> WithOrigin a -> Bool)
-> (WithOrigin a -> WithOrigin a -> WithOrigin a)
-> (WithOrigin a -> WithOrigin a -> WithOrigin a)
-> Ord (WithOrigin a)
WithOrigin a -> WithOrigin a -> Bool
WithOrigin a -> WithOrigin a -> Ordering
WithOrigin a -> WithOrigin a -> WithOrigin a
forall a.
Eq a =>
(a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
forall a. Ord a => Eq (WithOrigin a)
forall a. Ord a => WithOrigin a -> WithOrigin a -> Bool
forall a. Ord a => WithOrigin a -> WithOrigin a -> Ordering
forall a. Ord a => WithOrigin a -> WithOrigin a -> WithOrigin a
$ccompare :: forall a. Ord a => WithOrigin a -> WithOrigin a -> Ordering
compare :: WithOrigin a -> WithOrigin a -> Ordering
$c< :: forall a. Ord a => WithOrigin a -> WithOrigin a -> Bool
< :: WithOrigin a -> WithOrigin a -> Bool
$c<= :: forall a. Ord a => WithOrigin a -> WithOrigin a -> Bool
<= :: WithOrigin a -> WithOrigin a -> Bool
$c> :: forall a. Ord a => WithOrigin a -> WithOrigin a -> Bool
> :: WithOrigin a -> WithOrigin a -> Bool
$c>= :: forall a. Ord a => WithOrigin a -> WithOrigin a -> Bool
>= :: WithOrigin a -> WithOrigin a -> Bool
$cmax :: forall a. Ord a => WithOrigin a -> WithOrigin a -> WithOrigin a
max :: WithOrigin a -> WithOrigin a -> WithOrigin a
$cmin :: forall a. Ord a => WithOrigin a -> WithOrigin a -> WithOrigin a
min :: WithOrigin a -> WithOrigin a -> WithOrigin a
Ord, Int -> WithOrigin a -> ShowS
[WithOrigin a] -> ShowS
WithOrigin a -> ArgName
(Int -> WithOrigin a -> ShowS)
-> (WithOrigin a -> ArgName)
-> ([WithOrigin a] -> ShowS)
-> Show (WithOrigin a)
forall a. Show a => Int -> WithOrigin a -> ShowS
forall a. Show a => [WithOrigin a] -> ShowS
forall a. Show a => WithOrigin a -> ArgName
forall a.
(Int -> a -> ShowS) -> (a -> ArgName) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: forall a. Show a => Int -> WithOrigin a -> ShowS
showsPrec :: Int -> WithOrigin a -> ShowS
$cshow :: forall a. Show a => WithOrigin a -> ArgName
show :: WithOrigin a -> ArgName
$cshowList :: forall a. Show a => [WithOrigin a] -> ShowS
showList :: [WithOrigin a] -> ShowS
Show, (forall a b. (a -> b) -> WithOrigin a -> WithOrigin b)
-> (forall a b. a -> WithOrigin b -> WithOrigin a)
-> Functor WithOrigin
forall a b. a -> WithOrigin b -> WithOrigin a
forall a b. (a -> b) -> WithOrigin a -> WithOrigin b
forall (f :: * -> *).
(forall a b. (a -> b) -> f a -> f b)
-> (forall a b. a -> f b -> f a) -> Functor f
$cfmap :: forall a b. (a -> b) -> WithOrigin a -> WithOrigin b
fmap :: forall a b. (a -> b) -> WithOrigin a -> WithOrigin b
$c<$ :: forall a b. a -> WithOrigin b -> WithOrigin a
<$ :: forall a b. a -> WithOrigin b -> WithOrigin a
Functor, (forall m. Monoid m => WithOrigin m -> m)
-> (forall m a. Monoid m => (a -> m) -> WithOrigin a -> m)
-> (forall m a. Monoid m => (a -> m) -> WithOrigin a -> m)
-> (forall a b. (a -> b -> b) -> b -> WithOrigin a -> b)
-> (forall a b. (a -> b -> b) -> b -> WithOrigin a -> b)
-> (forall b a. (b -> a -> b) -> b -> WithOrigin a -> b)
-> (forall b a. (b -> a -> b) -> b -> WithOrigin a -> b)
-> (forall a. (a -> a -> a) -> WithOrigin a -> a)
-> (forall a. (a -> a -> a) -> WithOrigin a -> a)
-> (forall a. WithOrigin a -> [a])
-> (forall a. WithOrigin a -> Bool)
-> (forall a. WithOrigin a -> Int)
-> (forall a. Eq a => a -> WithOrigin a -> Bool)
-> (forall a. Ord a => WithOrigin a -> a)
-> (forall a. Ord a => WithOrigin a -> a)
-> (forall a. Num a => WithOrigin a -> a)
-> (forall a. Num a => WithOrigin a -> a)
-> Foldable WithOrigin
forall a. Eq a => a -> WithOrigin a -> Bool
forall a. Num a => WithOrigin a -> a
forall a. Ord a => WithOrigin a -> a
forall m. Monoid m => WithOrigin m -> m
forall a. WithOrigin a -> Bool
forall a. WithOrigin a -> Int
forall a. WithOrigin a -> [a]
forall a. (a -> a -> a) -> WithOrigin a -> a
forall m a. Monoid m => (a -> m) -> WithOrigin a -> m
forall b a. (b -> a -> b) -> b -> WithOrigin a -> b
forall a b. (a -> b -> b) -> b -> WithOrigin a -> b
forall (t :: * -> *).
(forall m. Monoid m => t m -> m)
-> (forall m a. Monoid m => (a -> m) -> t a -> m)
-> (forall m a. Monoid m => (a -> m) -> t a -> m)
-> (forall a b. (a -> b -> b) -> b -> t a -> b)
-> (forall a b. (a -> b -> b) -> b -> t a -> b)
-> (forall b a. (b -> a -> b) -> b -> t a -> b)
-> (forall b a. (b -> a -> b) -> b -> t a -> b)
-> (forall a. (a -> a -> a) -> t a -> a)
-> (forall a. (a -> a -> a) -> t a -> a)
-> (forall a. t a -> [a])
-> (forall a. t a -> Bool)
-> (forall a. t a -> Int)
-> (forall a. Eq a => a -> t a -> Bool)
-> (forall a. Ord a => t a -> a)
-> (forall a. Ord a => t a -> a)
-> (forall a. Num a => t a -> a)
-> (forall a. Num a => t a -> a)
-> Foldable t
$cfold :: forall m. Monoid m => WithOrigin m -> m
fold :: forall m. Monoid m => WithOrigin m -> m
$cfoldMap :: forall m a. Monoid m => (a -> m) -> WithOrigin a -> m
foldMap :: forall m a. Monoid m => (a -> m) -> WithOrigin a -> m
$cfoldMap' :: forall m a. Monoid m => (a -> m) -> WithOrigin a -> m
foldMap' :: forall m a. Monoid m => (a -> m) -> WithOrigin a -> m
$cfoldr :: forall a b. (a -> b -> b) -> b -> WithOrigin a -> b
foldr :: forall a b. (a -> b -> b) -> b -> WithOrigin a -> b
$cfoldr' :: forall a b. (a -> b -> b) -> b -> WithOrigin a -> b
foldr' :: forall a b. (a -> b -> b) -> b -> WithOrigin a -> b
$cfoldl :: forall b a. (b -> a -> b) -> b -> WithOrigin a -> b
foldl :: forall b a. (b -> a -> b) -> b -> WithOrigin a -> b
$cfoldl' :: forall b a. (b -> a -> b) -> b -> WithOrigin a -> b
foldl' :: forall b a. (b -> a -> b) -> b -> WithOrigin a -> b
$cfoldr1 :: forall a. (a -> a -> a) -> WithOrigin a -> a
foldr1 :: forall a. (a -> a -> a) -> WithOrigin a -> a
$cfoldl1 :: forall a. (a -> a -> a) -> WithOrigin a -> a
foldl1 :: forall a. (a -> a -> a) -> WithOrigin a -> a
$ctoList :: forall a. WithOrigin a -> [a]
toList :: forall a. WithOrigin a -> [a]
$cnull :: forall a. WithOrigin a -> Bool
null :: forall a. WithOrigin a -> Bool
$clength :: forall a. WithOrigin a -> Int
length :: forall a. WithOrigin a -> Int
$celem :: forall a. Eq a => a -> WithOrigin a -> Bool
elem :: forall a. Eq a => a -> WithOrigin a -> Bool
$cmaximum :: forall a. Ord a => WithOrigin a -> a
maximum :: forall a. Ord a => WithOrigin a -> a
$cminimum :: forall a. Ord a => WithOrigin a -> a
minimum :: forall a. Ord a => WithOrigin a -> a
$csum :: forall a. Num a => WithOrigin a -> a
sum :: forall a. Num a => WithOrigin a -> a
$cproduct :: forall a. Num a => WithOrigin a -> a
product :: forall a. Num a => WithOrigin a -> a
Foldable, Functor WithOrigin
Foldable WithOrigin
(Functor WithOrigin, Foldable WithOrigin) =>
(forall (f :: * -> *) a b.
 Applicative f =>
 (a -> f b) -> WithOrigin a -> f (WithOrigin b))
-> (forall (f :: * -> *) a.
    Applicative f =>
    WithOrigin (f a) -> f (WithOrigin a))
-> (forall (m :: * -> *) a b.
    Monad m =>
    (a -> m b) -> WithOrigin a -> m (WithOrigin b))
-> (forall (m :: * -> *) a.
    Monad m =>
    WithOrigin (m a) -> m (WithOrigin a))
-> Traversable WithOrigin
forall (t :: * -> *).
(Functor t, Foldable t) =>
(forall (f :: * -> *) a b.
 Applicative f =>
 (a -> f b) -> t a -> f (t b))
-> (forall (f :: * -> *) a. Applicative f => t (f a) -> f (t a))
-> (forall (m :: * -> *) a b.
    Monad m =>
    (a -> m b) -> t a -> m (t b))
-> (forall (m :: * -> *) a. Monad m => t (m a) -> m (t a))
-> Traversable t
forall (m :: * -> *) a.
Monad m =>
WithOrigin (m a) -> m (WithOrigin a)
forall (f :: * -> *) a.
Applicative f =>
WithOrigin (f a) -> f (WithOrigin a)
forall (m :: * -> *) a b.
Monad m =>
(a -> m b) -> WithOrigin a -> m (WithOrigin b)
forall (f :: * -> *) a b.
Applicative f =>
(a -> f b) -> WithOrigin a -> f (WithOrigin b)
$ctraverse :: forall (f :: * -> *) a b.
Applicative f =>
(a -> f b) -> WithOrigin a -> f (WithOrigin b)
traverse :: forall (f :: * -> *) a b.
Applicative f =>
(a -> f b) -> WithOrigin a -> f (WithOrigin b)
$csequenceA :: forall (f :: * -> *) a.
Applicative f =>
WithOrigin (f a) -> f (WithOrigin a)
sequenceA :: forall (f :: * -> *) a.
Applicative f =>
WithOrigin (f a) -> f (WithOrigin a)
$cmapM :: forall (m :: * -> *) a b.
Monad m =>
(a -> m b) -> WithOrigin a -> m (WithOrigin b)
mapM :: forall (m :: * -> *) a b.
Monad m =>
(a -> m b) -> WithOrigin a -> m (WithOrigin b)
$csequence :: forall (m :: * -> *) a.
Monad m =>
WithOrigin (m a) -> m (WithOrigin a)
sequence :: forall (m :: * -> *) a.
Monad m =>
WithOrigin (m a) -> m (WithOrigin a)
Traversable)

instance Decoration WithOrigin where
  traverseF :: forall (m :: * -> *) a b.
Functor m =>
(a -> m b) -> WithOrigin a -> m (WithOrigin b)
traverseF a -> m b
f (WithOrigin Origin
h a
a) = Origin -> b -> WithOrigin b
forall a. Origin -> a -> WithOrigin a
WithOrigin Origin
h (b -> WithOrigin b) -> m b -> m (WithOrigin b)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> a -> m b
f a
a

instance Pretty a => Pretty (WithOrigin a) where
  prettyPrec :: Int -> WithOrigin a -> Doc
prettyPrec Int
p = Int -> a -> Doc
forall a. Pretty a => Int -> a -> Doc
prettyPrec Int
p (a -> Doc) -> (WithOrigin a -> a) -> WithOrigin a -> Doc
forall b c a. (b -> c) -> (a -> b) -> a -> c
. WithOrigin a -> a
forall a. WithOrigin a -> a
woThing

instance HasRange a => HasRange (WithOrigin a) where
  getRange :: WithOrigin a -> Range
getRange = a -> Range
forall a. HasRange a => a -> Range
getRange (a -> Range) -> (WithOrigin a -> a) -> WithOrigin a -> Range
forall b c a. (b -> c) -> (a -> b) -> a -> c
. WithOrigin a -> a
forall (t :: * -> *) a. Decoration t => t a -> a
dget

instance SetRange a => SetRange (WithOrigin a) where
  setRange :: Range -> WithOrigin a -> WithOrigin a
setRange = (a -> a) -> WithOrigin a -> WithOrigin a
forall a b. (a -> b) -> WithOrigin a -> WithOrigin b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap ((a -> a) -> WithOrigin a -> WithOrigin a)
-> (Range -> a -> a) -> Range -> WithOrigin a -> WithOrigin a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Range -> a -> a
forall a. SetRange a => Range -> a -> a
setRange

instance KillRange a => KillRange (WithOrigin a) where
  killRange :: KillRangeT (WithOrigin a)
killRange = (a -> a) -> KillRangeT (WithOrigin a)
forall a b. (a -> b) -> WithOrigin a -> WithOrigin b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap a -> a
forall a. KillRange a => KillRangeT a
killRange

instance NFData a => NFData (WithOrigin a) where
  rnf :: WithOrigin a -> ()
rnf (WithOrigin Origin
_ a
a) = a -> ()
forall a. NFData a => a -> ()
rnf a
a

-- | A lens to access the 'Origin' attribute in data structures.
--   Minimal implementation: @getOrigin@ and @mapOrigin@ or @LensArgInfo@.

class LensOrigin a where

  getOrigin :: a -> Origin

  setOrigin :: Origin -> a -> a
  setOrigin Origin
o = (Origin -> Origin) -> a -> a
forall a. LensOrigin a => (Origin -> Origin) -> a -> a
mapOrigin (Origin -> Origin -> Origin
forall a b. a -> b -> a
const Origin
o)

  mapOrigin :: (Origin -> Origin) -> a -> a

  default getOrigin :: LensArgInfo a => a -> Origin
  getOrigin = ArgInfo -> Origin
argInfoOrigin (ArgInfo -> Origin) -> (a -> ArgInfo) -> a -> Origin
forall b c a. (b -> c) -> (a -> b) -> a -> c
. a -> ArgInfo
forall a. LensArgInfo a => a -> ArgInfo
getArgInfo

  default mapOrigin :: LensArgInfo a => (Origin -> Origin) -> a -> a
  mapOrigin Origin -> Origin
f = (ArgInfo -> ArgInfo) -> a -> a
forall a. LensArgInfo a => (ArgInfo -> ArgInfo) -> a -> a
mapArgInfo ((ArgInfo -> ArgInfo) -> a -> a) -> (ArgInfo -> ArgInfo) -> a -> a
forall a b. (a -> b) -> a -> b
$ \ ArgInfo
ai -> ArgInfo
ai { argInfoOrigin = f $ argInfoOrigin ai }

instance LensOrigin Origin where
  getOrigin :: Origin -> Origin
getOrigin = Origin -> Origin
forall a. a -> a
id
  setOrigin :: Origin -> Origin -> Origin
setOrigin = Origin -> Origin -> Origin
forall a b. a -> b -> a
const
  mapOrigin :: (Origin -> Origin) -> Origin -> Origin
mapOrigin = (Origin -> Origin) -> Origin -> Origin
forall a. a -> a
id

instance LensOrigin (WithOrigin a) where
  getOrigin :: WithOrigin a -> Origin
getOrigin   (WithOrigin Origin
h a
_) = Origin
h
  setOrigin :: Origin -> WithOrigin a -> WithOrigin a
setOrigin Origin
h (WithOrigin Origin
_ a
a) = Origin -> a -> WithOrigin a
forall a. Origin -> a -> WithOrigin a
WithOrigin Origin
h a
a
  mapOrigin :: (Origin -> Origin) -> WithOrigin a -> WithOrigin a
mapOrigin Origin -> Origin
f (WithOrigin Origin
h a
a) = Origin -> a -> WithOrigin a
forall a. Origin -> a -> WithOrigin a
WithOrigin (Origin -> Origin
f Origin
h) a
a

-----------------------------------------------------------------------------
-- * Free variable annotations
-----------------------------------------------------------------------------

data FreeVariables = UnknownFVs | KnownFVs IntSet
  deriving (FreeVariables -> FreeVariables -> Bool
(FreeVariables -> FreeVariables -> Bool)
-> (FreeVariables -> FreeVariables -> Bool) -> Eq FreeVariables
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: FreeVariables -> FreeVariables -> Bool
== :: FreeVariables -> FreeVariables -> Bool
$c/= :: FreeVariables -> FreeVariables -> Bool
/= :: FreeVariables -> FreeVariables -> Bool
Eq, Eq FreeVariables
Eq FreeVariables =>
(FreeVariables -> FreeVariables -> Ordering)
-> (FreeVariables -> FreeVariables -> Bool)
-> (FreeVariables -> FreeVariables -> Bool)
-> (FreeVariables -> FreeVariables -> Bool)
-> (FreeVariables -> FreeVariables -> Bool)
-> (FreeVariables -> FreeVariables -> FreeVariables)
-> (FreeVariables -> FreeVariables -> FreeVariables)
-> Ord FreeVariables
FreeVariables -> FreeVariables -> Bool
FreeVariables -> FreeVariables -> Ordering
FreeVariables -> FreeVariables -> FreeVariables
forall a.
Eq a =>
(a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
$ccompare :: FreeVariables -> FreeVariables -> Ordering
compare :: FreeVariables -> FreeVariables -> Ordering
$c< :: FreeVariables -> FreeVariables -> Bool
< :: FreeVariables -> FreeVariables -> Bool
$c<= :: FreeVariables -> FreeVariables -> Bool
<= :: FreeVariables -> FreeVariables -> Bool
$c> :: FreeVariables -> FreeVariables -> Bool
> :: FreeVariables -> FreeVariables -> Bool
$c>= :: FreeVariables -> FreeVariables -> Bool
>= :: FreeVariables -> FreeVariables -> Bool
$cmax :: FreeVariables -> FreeVariables -> FreeVariables
max :: FreeVariables -> FreeVariables -> FreeVariables
$cmin :: FreeVariables -> FreeVariables -> FreeVariables
min :: FreeVariables -> FreeVariables -> FreeVariables
Ord, Int -> FreeVariables -> ShowS
[FreeVariables] -> ShowS
FreeVariables -> ArgName
(Int -> FreeVariables -> ShowS)
-> (FreeVariables -> ArgName)
-> ([FreeVariables] -> ShowS)
-> Show FreeVariables
forall a.
(Int -> a -> ShowS) -> (a -> ArgName) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> FreeVariables -> ShowS
showsPrec :: Int -> FreeVariables -> ShowS
$cshow :: FreeVariables -> ArgName
show :: FreeVariables -> ArgName
$cshowList :: [FreeVariables] -> ShowS
showList :: [FreeVariables] -> ShowS
Show)

instance Semigroup FreeVariables where
  FreeVariables
UnknownFVs   <> :: FreeVariables -> FreeVariables -> FreeVariables
<> FreeVariables
_            = FreeVariables
UnknownFVs
  FreeVariables
_            <> FreeVariables
UnknownFVs   = FreeVariables
UnknownFVs
  KnownFVs IntSet
vs1 <> KnownFVs IntSet
vs2 = IntSet -> FreeVariables
KnownFVs (IntSet -> IntSet -> IntSet
IntSet.union IntSet
vs1 IntSet
vs2)

instance Monoid FreeVariables where
  mempty :: FreeVariables
mempty  = IntSet -> FreeVariables
KnownFVs IntSet
IntSet.empty
  mappend :: FreeVariables -> FreeVariables -> FreeVariables
mappend = FreeVariables -> FreeVariables -> FreeVariables
forall a. Semigroup a => a -> a -> a
(<>)

instance KillRange FreeVariables where
  killRange :: FreeVariables -> FreeVariables
killRange = FreeVariables -> FreeVariables
forall a. a -> a
id

instance NFData FreeVariables where
  rnf :: FreeVariables -> ()
rnf FreeVariables
UnknownFVs    = ()
  rnf (KnownFVs IntSet
fv) = IntSet -> ()
forall a. NFData a => a -> ()
rnf IntSet
fv

unknownFreeVariables :: FreeVariables
unknownFreeVariables :: FreeVariables
unknownFreeVariables = FreeVariables
UnknownFVs

noFreeVariables :: FreeVariables
noFreeVariables :: FreeVariables
noFreeVariables = FreeVariables
forall a. Monoid a => a
mempty

oneFreeVariable :: Int -> FreeVariables
oneFreeVariable :: Int -> FreeVariables
oneFreeVariable = IntSet -> FreeVariables
KnownFVs (IntSet -> FreeVariables)
-> (Int -> IntSet) -> Int -> FreeVariables
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int -> IntSet
IntSet.singleton

freeVariablesFromList :: [Int] -> FreeVariables
freeVariablesFromList :: [Int] -> FreeVariables
freeVariablesFromList = [FreeVariables] -> FreeVariables
forall a. Monoid a => [a] -> a
mconcat ([FreeVariables] -> FreeVariables)
-> ([Int] -> [FreeVariables]) -> [Int] -> FreeVariables
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Int -> FreeVariables) -> [Int] -> [FreeVariables]
forall a b. (a -> b) -> [a] -> [b]
map Int -> FreeVariables
oneFreeVariable

-- | A lens to access the 'FreeVariables' attribute in data structures.
--   Minimal implementation: @getFreeVariables@ and @mapFreeVariables@ or @LensArgInfo@.
class LensFreeVariables a where

  getFreeVariables :: a -> FreeVariables

  setFreeVariables :: FreeVariables -> a -> a
  setFreeVariables FreeVariables
o = (FreeVariables -> FreeVariables) -> a -> a
forall a.
LensFreeVariables a =>
(FreeVariables -> FreeVariables) -> a -> a
mapFreeVariables (FreeVariables -> FreeVariables -> FreeVariables
forall a b. a -> b -> a
const FreeVariables
o)

  mapFreeVariables :: (FreeVariables -> FreeVariables) -> a -> a

  default getFreeVariables :: LensArgInfo a => a -> FreeVariables
  getFreeVariables = ArgInfo -> FreeVariables
argInfoFreeVariables (ArgInfo -> FreeVariables) -> (a -> ArgInfo) -> a -> FreeVariables
forall b c a. (b -> c) -> (a -> b) -> a -> c
. a -> ArgInfo
forall a. LensArgInfo a => a -> ArgInfo
getArgInfo

  default mapFreeVariables :: LensArgInfo a => (FreeVariables -> FreeVariables) -> a -> a
  mapFreeVariables FreeVariables -> FreeVariables
f = (ArgInfo -> ArgInfo) -> a -> a
forall a. LensArgInfo a => (ArgInfo -> ArgInfo) -> a -> a
mapArgInfo ((ArgInfo -> ArgInfo) -> a -> a) -> (ArgInfo -> ArgInfo) -> a -> a
forall a b. (a -> b) -> a -> b
$ \ ArgInfo
ai -> ArgInfo
ai { argInfoFreeVariables = f $ argInfoFreeVariables ai }

instance LensFreeVariables FreeVariables where
  getFreeVariables :: FreeVariables -> FreeVariables
getFreeVariables = FreeVariables -> FreeVariables
forall a. a -> a
id
  setFreeVariables :: FreeVariables -> FreeVariables -> FreeVariables
setFreeVariables = FreeVariables -> FreeVariables -> FreeVariables
forall a b. a -> b -> a
const
  mapFreeVariables :: (FreeVariables -> FreeVariables) -> FreeVariables -> FreeVariables
mapFreeVariables = (FreeVariables -> FreeVariables) -> FreeVariables -> FreeVariables
forall a. a -> a
id

hasNoFreeVariables :: LensFreeVariables a => a -> Bool
hasNoFreeVariables :: forall a. LensFreeVariables a => a -> Bool
hasNoFreeVariables a
x =
  case a -> FreeVariables
forall a. LensFreeVariables a => a -> FreeVariables
getFreeVariables a
x of
    FreeVariables
UnknownFVs  -> Bool
False
    KnownFVs IntSet
fv -> IntSet -> Bool
IntSet.null IntSet
fv

---------------------------------------------------------------------------
-- * Argument decoration
---------------------------------------------------------------------------

-- | A function argument can be hidden and/or irrelevant.

data ArgInfo = ArgInfo
  { ArgInfo -> Hiding
argInfoHiding        :: Hiding
  , ArgInfo -> Modality
argInfoModality      :: Modality
  , ArgInfo -> Origin
argInfoOrigin        :: Origin
  , ArgInfo -> FreeVariables
argInfoFreeVariables :: FreeVariables
  , ArgInfo -> Annotation
argInfoAnnotation    :: Annotation
    -- ^ Sometimes we want a different kind of binder/pi-type, without it
    --   supporting any of the @Modality@ interface.
  } deriving (ArgInfo -> ArgInfo -> Bool
(ArgInfo -> ArgInfo -> Bool)
-> (ArgInfo -> ArgInfo -> Bool) -> Eq ArgInfo
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: ArgInfo -> ArgInfo -> Bool
== :: ArgInfo -> ArgInfo -> Bool
$c/= :: ArgInfo -> ArgInfo -> Bool
/= :: ArgInfo -> ArgInfo -> Bool
Eq, Eq ArgInfo
Eq ArgInfo =>
(ArgInfo -> ArgInfo -> Ordering)
-> (ArgInfo -> ArgInfo -> Bool)
-> (ArgInfo -> ArgInfo -> Bool)
-> (ArgInfo -> ArgInfo -> Bool)
-> (ArgInfo -> ArgInfo -> Bool)
-> (ArgInfo -> ArgInfo -> ArgInfo)
-> (ArgInfo -> ArgInfo -> ArgInfo)
-> Ord ArgInfo
ArgInfo -> ArgInfo -> Bool
ArgInfo -> ArgInfo -> Ordering
ArgInfo -> ArgInfo -> ArgInfo
forall a.
Eq a =>
(a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
$ccompare :: ArgInfo -> ArgInfo -> Ordering
compare :: ArgInfo -> ArgInfo -> Ordering
$c< :: ArgInfo -> ArgInfo -> Bool
< :: ArgInfo -> ArgInfo -> Bool
$c<= :: ArgInfo -> ArgInfo -> Bool
<= :: ArgInfo -> ArgInfo -> Bool
$c> :: ArgInfo -> ArgInfo -> Bool
> :: ArgInfo -> ArgInfo -> Bool
$c>= :: ArgInfo -> ArgInfo -> Bool
>= :: ArgInfo -> ArgInfo -> Bool
$cmax :: ArgInfo -> ArgInfo -> ArgInfo
max :: ArgInfo -> ArgInfo -> ArgInfo
$cmin :: ArgInfo -> ArgInfo -> ArgInfo
min :: ArgInfo -> ArgInfo -> ArgInfo
Ord, Int -> ArgInfo -> ShowS
[ArgInfo] -> ShowS
ArgInfo -> ArgName
(Int -> ArgInfo -> ShowS)
-> (ArgInfo -> ArgName) -> ([ArgInfo] -> ShowS) -> Show ArgInfo
forall a.
(Int -> a -> ShowS) -> (a -> ArgName) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> ArgInfo -> ShowS
showsPrec :: Int -> ArgInfo -> ShowS
$cshow :: ArgInfo -> ArgName
show :: ArgInfo -> ArgName
$cshowList :: [ArgInfo] -> ShowS
showList :: [ArgInfo] -> ShowS
Show)

instance HasRange ArgInfo where
  getRange :: ArgInfo -> Range
getRange (ArgInfo Hiding
h Modality
m Origin
o FreeVariables
_fv Annotation
a) = (Hiding, Modality, Origin, Annotation) -> Range
forall a. HasRange a => a -> Range
getRange (Hiding
h, Modality
m, Origin
o, Annotation
a)

instance KillRange ArgInfo where
  killRange :: ArgInfo -> ArgInfo
killRange (ArgInfo Hiding
h Modality
m Origin
o FreeVariables
fv Annotation
a) = (Hiding
 -> Modality -> Origin -> FreeVariables -> Annotation -> ArgInfo)
-> Hiding
-> Modality
-> Origin
-> FreeVariables
-> Annotation
-> ArgInfo
forall t (b :: Bool).
(KILLRANGE t b, IsBase t ~ b, All KillRange (Domains t)) =>
t -> t
killRangeN Hiding
-> Modality -> Origin -> FreeVariables -> Annotation -> ArgInfo
ArgInfo Hiding
h Modality
m Origin
o FreeVariables
fv Annotation
a

class LensArgInfo a where
  getArgInfo :: a -> ArgInfo
  setArgInfo :: ArgInfo -> a -> a
  setArgInfo ArgInfo
ai = (ArgInfo -> ArgInfo) -> a -> a
forall a. LensArgInfo a => (ArgInfo -> ArgInfo) -> a -> a
mapArgInfo (ArgInfo -> ArgInfo -> ArgInfo
forall a b. a -> b -> a
const ArgInfo
ai)
  mapArgInfo :: (ArgInfo -> ArgInfo) -> a -> a
  mapArgInfo ArgInfo -> ArgInfo
f a
a = ArgInfo -> a -> a
forall a. LensArgInfo a => ArgInfo -> a -> a
setArgInfo (ArgInfo -> ArgInfo
f (ArgInfo -> ArgInfo) -> ArgInfo -> ArgInfo
forall a b. (a -> b) -> a -> b
$ a -> ArgInfo
forall a. LensArgInfo a => a -> ArgInfo
getArgInfo a
a) a
a

instance LensArgInfo ArgInfo where
  getArgInfo :: ArgInfo -> ArgInfo
getArgInfo = ArgInfo -> ArgInfo
forall a. a -> a
id
  setArgInfo :: ArgInfo -> ArgInfo -> ArgInfo
setArgInfo = ArgInfo -> ArgInfo -> ArgInfo
forall a b. a -> b -> a
const
  mapArgInfo :: (ArgInfo -> ArgInfo) -> ArgInfo -> ArgInfo
mapArgInfo = (ArgInfo -> ArgInfo) -> ArgInfo -> ArgInfo
forall a. a -> a
id

instance NFData ArgInfo where
  rnf :: ArgInfo -> ()
rnf (ArgInfo Hiding
a Modality
b Origin
c FreeVariables
d Annotation
e) = Hiding -> ()
forall a. NFData a => a -> ()
rnf Hiding
a () -> () -> ()
forall a b. a -> b -> b
`seq` Modality -> ()
forall a. NFData a => a -> ()
rnf Modality
b () -> () -> ()
forall a b. a -> b -> b
`seq` Origin -> ()
forall a. NFData a => a -> ()
rnf Origin
c () -> () -> ()
forall a b. a -> b -> b
`seq` FreeVariables -> ()
forall a. NFData a => a -> ()
rnf FreeVariables
d () -> () -> ()
forall a b. a -> b -> b
`seq` Annotation -> ()
forall a. NFData a => a -> ()
rnf Annotation
e

instance LensHiding ArgInfo where
  getHiding :: ArgInfo -> Hiding
getHiding = ArgInfo -> Hiding
argInfoHiding
  setHiding :: Hiding -> ArgInfo -> ArgInfo
setHiding Hiding
h ArgInfo
ai = ArgInfo
ai { argInfoHiding = h }
  mapHiding :: (Hiding -> Hiding) -> ArgInfo -> ArgInfo
mapHiding Hiding -> Hiding
f ArgInfo
ai = ArgInfo
ai { argInfoHiding = f (argInfoHiding ai) }

instance LensModality ArgInfo where
  getModality :: ArgInfo -> Modality
getModality = ArgInfo -> Modality
argInfoModality
  setModality :: Modality -> ArgInfo -> ArgInfo
setModality Modality
m ArgInfo
ai = ArgInfo
ai { argInfoModality = m }
  mapModality :: (Modality -> Modality) -> ArgInfo -> ArgInfo
mapModality Modality -> Modality
f ArgInfo
ai = ArgInfo
ai { argInfoModality = f (argInfoModality ai) }

instance LensOrigin ArgInfo where
  getOrigin :: ArgInfo -> Origin
getOrigin = ArgInfo -> Origin
argInfoOrigin
  setOrigin :: Origin -> ArgInfo -> ArgInfo
setOrigin Origin
o ArgInfo
ai = ArgInfo
ai { argInfoOrigin = o }
  mapOrigin :: (Origin -> Origin) -> ArgInfo -> ArgInfo
mapOrigin Origin -> Origin
f ArgInfo
ai = ArgInfo
ai { argInfoOrigin = f (argInfoOrigin ai) }

instance LensFreeVariables ArgInfo where
  getFreeVariables :: ArgInfo -> FreeVariables
getFreeVariables = ArgInfo -> FreeVariables
argInfoFreeVariables
  setFreeVariables :: FreeVariables -> ArgInfo -> ArgInfo
setFreeVariables FreeVariables
o ArgInfo
ai = ArgInfo
ai { argInfoFreeVariables = o }
  mapFreeVariables :: (FreeVariables -> FreeVariables) -> ArgInfo -> ArgInfo
mapFreeVariables FreeVariables -> FreeVariables
f ArgInfo
ai = ArgInfo
ai { argInfoFreeVariables = f (argInfoFreeVariables ai) }

instance LensAnnotation ArgInfo where
  getAnnotation :: ArgInfo -> Annotation
getAnnotation = ArgInfo -> Annotation
argInfoAnnotation
  setAnnotation :: Annotation -> ArgInfo -> ArgInfo
setAnnotation Annotation
m ArgInfo
ai = ArgInfo
ai { argInfoAnnotation = m }
  mapAnnotation :: (Annotation -> Annotation) -> ArgInfo -> ArgInfo
mapAnnotation Annotation -> Annotation
f ArgInfo
ai = ArgInfo
ai { argInfoAnnotation = f (argInfoAnnotation ai) }

-- inherited instances

instance LensRelevance ArgInfo where
  getRelevance :: ArgInfo -> Relevance
getRelevance = ArgInfo -> Relevance
forall a. LensModality a => LensGet a Relevance
getRelevanceMod
  setRelevance :: Relevance -> ArgInfo -> ArgInfo
setRelevance = Relevance -> ArgInfo -> ArgInfo
forall a. LensModality a => LensSet a Relevance
setRelevanceMod
  mapRelevance :: (Relevance -> Relevance) -> ArgInfo -> ArgInfo
mapRelevance = (Relevance -> Relevance) -> ArgInfo -> ArgInfo
forall a. LensModality a => LensMap a Relevance
mapRelevanceMod

instance LensQuantity ArgInfo where
  getQuantity :: ArgInfo -> Quantity
getQuantity = ArgInfo -> Quantity
forall a. LensModality a => LensGet a Quantity
getQuantityMod
  setQuantity :: Quantity -> ArgInfo -> ArgInfo
setQuantity = Quantity -> ArgInfo -> ArgInfo
forall a. LensModality a => LensSet a Quantity
setQuantityMod
  mapQuantity :: (Quantity -> Quantity) -> ArgInfo -> ArgInfo
mapQuantity = (Quantity -> Quantity) -> ArgInfo -> ArgInfo
forall a. LensModality a => LensMap a Quantity
mapQuantityMod

instance LensCohesion ArgInfo where
  getCohesion :: ArgInfo -> Cohesion
getCohesion = ArgInfo -> Cohesion
forall a. LensModality a => LensGet a Cohesion
getCohesionMod
  setCohesion :: Cohesion -> ArgInfo -> ArgInfo
setCohesion = Cohesion -> ArgInfo -> ArgInfo
forall a. LensModality a => LensSet a Cohesion
setCohesionMod
  mapCohesion :: (Cohesion -> Cohesion) -> ArgInfo -> ArgInfo
mapCohesion = (Cohesion -> Cohesion) -> ArgInfo -> ArgInfo
forall a. LensModality a => LensMap a Cohesion
mapCohesionMod

defaultArgInfo :: ArgInfo
defaultArgInfo :: ArgInfo
defaultArgInfo =  ArgInfo
  { argInfoHiding :: Hiding
argInfoHiding        = Hiding
NotHidden
  , argInfoModality :: Modality
argInfoModality      = Modality
defaultModality
  , argInfoOrigin :: Origin
argInfoOrigin        = Origin
UserWritten
  , argInfoFreeVariables :: FreeVariables
argInfoFreeVariables = FreeVariables
UnknownFVs
  , argInfoAnnotation :: Annotation
argInfoAnnotation    = Annotation
defaultAnnotation
  }

-- Accessing through ArgInfo

-- default accessors for Hiding

getHidingArgInfo :: LensArgInfo a => LensGet a Hiding
getHidingArgInfo :: forall a. LensArgInfo a => LensGet a Hiding
getHidingArgInfo = ArgInfo -> Hiding
forall a. LensHiding a => a -> Hiding
getHiding (ArgInfo -> Hiding) -> (a -> ArgInfo) -> a -> Hiding
forall b c a. (b -> c) -> (a -> b) -> a -> c
. a -> ArgInfo
forall a. LensArgInfo a => a -> ArgInfo
getArgInfo

setHidingArgInfo :: LensArgInfo a => LensSet a Hiding
setHidingArgInfo :: forall a. LensArgInfo a => LensSet a Hiding
setHidingArgInfo = (ArgInfo -> ArgInfo) -> a -> a
forall a. LensArgInfo a => (ArgInfo -> ArgInfo) -> a -> a
mapArgInfo ((ArgInfo -> ArgInfo) -> a -> a)
-> (Hiding -> ArgInfo -> ArgInfo) -> Hiding -> a -> a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Hiding -> ArgInfo -> ArgInfo
forall a. LensHiding a => Hiding -> a -> a
setHiding

mapHidingArgInfo :: LensArgInfo a => LensMap a Hiding
mapHidingArgInfo :: forall a. LensArgInfo a => LensMap a Hiding
mapHidingArgInfo = (ArgInfo -> ArgInfo) -> a -> a
forall a. LensArgInfo a => (ArgInfo -> ArgInfo) -> a -> a
mapArgInfo ((ArgInfo -> ArgInfo) -> a -> a)
-> ((Hiding -> Hiding) -> ArgInfo -> ArgInfo)
-> (Hiding -> Hiding)
-> a
-> a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Hiding -> Hiding) -> ArgInfo -> ArgInfo
forall a. LensHiding a => (Hiding -> Hiding) -> a -> a
mapHiding

-- default accessors for Modality

getModalityArgInfo :: LensArgInfo a => LensGet a Modality
getModalityArgInfo :: forall a. LensArgInfo a => LensGet a Modality
getModalityArgInfo = ArgInfo -> Modality
forall a. LensModality a => a -> Modality
getModality (ArgInfo -> Modality) -> (a -> ArgInfo) -> a -> Modality
forall b c a. (b -> c) -> (a -> b) -> a -> c
. a -> ArgInfo
forall a. LensArgInfo a => a -> ArgInfo
getArgInfo

setModalityArgInfo :: LensArgInfo a => LensSet a Modality
setModalityArgInfo :: forall a. LensArgInfo a => LensSet a Modality
setModalityArgInfo = (ArgInfo -> ArgInfo) -> a -> a
forall a. LensArgInfo a => (ArgInfo -> ArgInfo) -> a -> a
mapArgInfo ((ArgInfo -> ArgInfo) -> a -> a)
-> (Modality -> ArgInfo -> ArgInfo) -> Modality -> a -> a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Modality -> ArgInfo -> ArgInfo
forall a. LensModality a => Modality -> a -> a
setModality

mapModalityArgInfo :: LensArgInfo a => LensMap a Modality
mapModalityArgInfo :: forall a. LensArgInfo a => LensMap a Modality
mapModalityArgInfo = (ArgInfo -> ArgInfo) -> a -> a
forall a. LensArgInfo a => (ArgInfo -> ArgInfo) -> a -> a
mapArgInfo ((ArgInfo -> ArgInfo) -> a -> a)
-> ((Modality -> Modality) -> ArgInfo -> ArgInfo)
-> (Modality -> Modality)
-> a
-> a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Modality -> Modality) -> ArgInfo -> ArgInfo
forall a. LensModality a => (Modality -> Modality) -> a -> a
mapModality

-- default accessors for Origin

getOriginArgInfo :: LensArgInfo a => LensGet a Origin
getOriginArgInfo :: forall a. LensArgInfo a => LensGet a Origin
getOriginArgInfo = ArgInfo -> Origin
forall a. LensOrigin a => a -> Origin
getOrigin (ArgInfo -> Origin) -> (a -> ArgInfo) -> a -> Origin
forall b c a. (b -> c) -> (a -> b) -> a -> c
. a -> ArgInfo
forall a. LensArgInfo a => a -> ArgInfo
getArgInfo

setOriginArgInfo :: LensArgInfo a => LensSet a Origin
setOriginArgInfo :: forall a. LensArgInfo a => LensSet a Origin
setOriginArgInfo = (ArgInfo -> ArgInfo) -> a -> a
forall a. LensArgInfo a => (ArgInfo -> ArgInfo) -> a -> a
mapArgInfo ((ArgInfo -> ArgInfo) -> a -> a)
-> (Origin -> ArgInfo -> ArgInfo) -> Origin -> a -> a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Origin -> ArgInfo -> ArgInfo
forall a. LensOrigin a => Origin -> a -> a
setOrigin

mapOriginArgInfo :: LensArgInfo a => LensMap a Origin
mapOriginArgInfo :: forall a. LensArgInfo a => LensMap a Origin
mapOriginArgInfo = (ArgInfo -> ArgInfo) -> a -> a
forall a. LensArgInfo a => (ArgInfo -> ArgInfo) -> a -> a
mapArgInfo ((ArgInfo -> ArgInfo) -> a -> a)
-> ((Origin -> Origin) -> ArgInfo -> ArgInfo)
-> (Origin -> Origin)
-> a
-> a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Origin -> Origin) -> ArgInfo -> ArgInfo
forall a. LensOrigin a => (Origin -> Origin) -> a -> a
mapOrigin

-- default accessors for FreeVariables

getFreeVariablesArgInfo :: LensArgInfo a => LensGet a FreeVariables
getFreeVariablesArgInfo :: forall a. LensArgInfo a => LensGet a FreeVariables
getFreeVariablesArgInfo = ArgInfo -> FreeVariables
forall a. LensFreeVariables a => a -> FreeVariables
getFreeVariables (ArgInfo -> FreeVariables) -> (a -> ArgInfo) -> a -> FreeVariables
forall b c a. (b -> c) -> (a -> b) -> a -> c
. a -> ArgInfo
forall a. LensArgInfo a => a -> ArgInfo
getArgInfo

setFreeVariablesArgInfo :: LensArgInfo a => LensSet a FreeVariables
setFreeVariablesArgInfo :: forall a. LensArgInfo a => LensSet a FreeVariables
setFreeVariablesArgInfo = (ArgInfo -> ArgInfo) -> a -> a
forall a. LensArgInfo a => (ArgInfo -> ArgInfo) -> a -> a
mapArgInfo ((ArgInfo -> ArgInfo) -> a -> a)
-> (FreeVariables -> ArgInfo -> ArgInfo) -> FreeVariables -> a -> a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. FreeVariables -> ArgInfo -> ArgInfo
forall a. LensFreeVariables a => FreeVariables -> a -> a
setFreeVariables

mapFreeVariablesArgInfo :: LensArgInfo a => LensMap a FreeVariables
mapFreeVariablesArgInfo :: forall a. LensArgInfo a => LensMap a FreeVariables
mapFreeVariablesArgInfo = (ArgInfo -> ArgInfo) -> a -> a
forall a. LensArgInfo a => (ArgInfo -> ArgInfo) -> a -> a
mapArgInfo ((ArgInfo -> ArgInfo) -> a -> a)
-> ((FreeVariables -> FreeVariables) -> ArgInfo -> ArgInfo)
-> (FreeVariables -> FreeVariables)
-> a
-> a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (FreeVariables -> FreeVariables) -> ArgInfo -> ArgInfo
forall a.
LensFreeVariables a =>
(FreeVariables -> FreeVariables) -> a -> a
mapFreeVariables

-- inserted hidden arguments

isInsertedHidden :: (LensHiding a, LensOrigin a) => a -> Bool
isInsertedHidden :: forall a. (LensHiding a, LensOrigin a) => a -> Bool
isInsertedHidden a
a = a -> Hiding
forall a. LensHiding a => a -> Hiding
getHiding a
a Hiding -> Hiding -> Bool
forall a. Eq a => a -> a -> Bool
== Hiding
Hidden Bool -> Bool -> Bool
&& a -> Origin
forall a. LensOrigin a => a -> Origin
getOrigin a
a Origin -> Origin -> Bool
forall a. Eq a => a -> a -> Bool
== Origin
Inserted

---------------------------------------------------------------------------
-- * Arguments
---------------------------------------------------------------------------

data Arg e  = Arg
  { forall e. Arg e -> ArgInfo
argInfo :: ArgInfo
  , forall e. Arg e -> e
unArg :: e
  } deriving (Arg e -> Arg e -> Bool
(Arg e -> Arg e -> Bool) -> (Arg e -> Arg e -> Bool) -> Eq (Arg e)
forall e. Eq e => Arg e -> Arg e -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: forall e. Eq e => Arg e -> Arg e -> Bool
== :: Arg e -> Arg e -> Bool
$c/= :: forall e. Eq e => Arg e -> Arg e -> Bool
/= :: Arg e -> Arg e -> Bool
Eq, Eq (Arg e)
Eq (Arg e) =>
(Arg e -> Arg e -> Ordering)
-> (Arg e -> Arg e -> Bool)
-> (Arg e -> Arg e -> Bool)
-> (Arg e -> Arg e -> Bool)
-> (Arg e -> Arg e -> Bool)
-> (Arg e -> Arg e -> Arg e)
-> (Arg e -> Arg e -> Arg e)
-> Ord (Arg e)
Arg e -> Arg e -> Bool
Arg e -> Arg e -> Ordering
Arg e -> Arg e -> Arg e
forall a.
Eq a =>
(a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
forall e. Ord e => Eq (Arg e)
forall e. Ord e => Arg e -> Arg e -> Bool
forall e. Ord e => Arg e -> Arg e -> Ordering
forall e. Ord e => Arg e -> Arg e -> Arg e
$ccompare :: forall e. Ord e => Arg e -> Arg e -> Ordering
compare :: Arg e -> Arg e -> Ordering
$c< :: forall e. Ord e => Arg e -> Arg e -> Bool
< :: Arg e -> Arg e -> Bool
$c<= :: forall e. Ord e => Arg e -> Arg e -> Bool
<= :: Arg e -> Arg e -> Bool
$c> :: forall e. Ord e => Arg e -> Arg e -> Bool
> :: Arg e -> Arg e -> Bool
$c>= :: forall e. Ord e => Arg e -> Arg e -> Bool
>= :: Arg e -> Arg e -> Bool
$cmax :: forall e. Ord e => Arg e -> Arg e -> Arg e
max :: Arg e -> Arg e -> Arg e
$cmin :: forall e. Ord e => Arg e -> Arg e -> Arg e
min :: Arg e -> Arg e -> Arg e
Ord, Int -> Arg e -> ShowS
[Arg e] -> ShowS
Arg e -> ArgName
(Int -> Arg e -> ShowS)
-> (Arg e -> ArgName) -> ([Arg e] -> ShowS) -> Show (Arg e)
forall e. Show e => Int -> Arg e -> ShowS
forall e. Show e => [Arg e] -> ShowS
forall e. Show e => Arg e -> ArgName
forall a.
(Int -> a -> ShowS) -> (a -> ArgName) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: forall e. Show e => Int -> Arg e -> ShowS
showsPrec :: Int -> Arg e -> ShowS
$cshow :: forall e. Show e => Arg e -> ArgName
show :: Arg e -> ArgName
$cshowList :: forall e. Show e => [Arg e] -> ShowS
showList :: [Arg e] -> ShowS
Show, (forall a b. (a -> b) -> Arg a -> Arg b)
-> (forall a b. a -> Arg b -> Arg a) -> Functor Arg
forall a b. a -> Arg b -> Arg a
forall a b. (a -> b) -> Arg a -> Arg b
forall (f :: * -> *).
(forall a b. (a -> b) -> f a -> f b)
-> (forall a b. a -> f b -> f a) -> Functor f
$cfmap :: forall a b. (a -> b) -> Arg a -> Arg b
fmap :: forall a b. (a -> b) -> Arg a -> Arg b
$c<$ :: forall a b. a -> Arg b -> Arg a
<$ :: forall a b. a -> Arg b -> Arg a
Functor, (forall m. Monoid m => Arg m -> m)
-> (forall m a. Monoid m => (a -> m) -> Arg a -> m)
-> (forall m a. Monoid m => (a -> m) -> Arg a -> m)
-> (forall a b. (a -> b -> b) -> b -> Arg a -> b)
-> (forall a b. (a -> b -> b) -> b -> Arg a -> b)
-> (forall b a. (b -> a -> b) -> b -> Arg a -> b)
-> (forall b a. (b -> a -> b) -> b -> Arg a -> b)
-> (forall a. (a -> a -> a) -> Arg a -> a)
-> (forall a. (a -> a -> a) -> Arg a -> a)
-> (forall a. Arg a -> [a])
-> (forall a. Arg a -> Bool)
-> (forall a. Arg a -> Int)
-> (forall a. Eq a => a -> Arg a -> Bool)
-> (forall a. Ord a => Arg a -> a)
-> (forall a. Ord a => Arg a -> a)
-> (forall a. Num a => Arg a -> a)
-> (forall a. Num a => Arg a -> a)
-> Foldable Arg
forall a. Eq a => a -> Arg a -> Bool
forall a. Num a => Arg a -> a
forall a. Ord a => Arg a -> a
forall m. Monoid m => Arg m -> m
forall a. Arg a -> Bool
forall a. Arg a -> Int
forall a. Arg a -> [a]
forall a. (a -> a -> a) -> Arg a -> a
forall m a. Monoid m => (a -> m) -> Arg a -> m
forall b a. (b -> a -> b) -> b -> Arg a -> b
forall a b. (a -> b -> b) -> b -> Arg a -> b
forall (t :: * -> *).
(forall m. Monoid m => t m -> m)
-> (forall m a. Monoid m => (a -> m) -> t a -> m)
-> (forall m a. Monoid m => (a -> m) -> t a -> m)
-> (forall a b. (a -> b -> b) -> b -> t a -> b)
-> (forall a b. (a -> b -> b) -> b -> t a -> b)
-> (forall b a. (b -> a -> b) -> b -> t a -> b)
-> (forall b a. (b -> a -> b) -> b -> t a -> b)
-> (forall a. (a -> a -> a) -> t a -> a)
-> (forall a. (a -> a -> a) -> t a -> a)
-> (forall a. t a -> [a])
-> (forall a. t a -> Bool)
-> (forall a. t a -> Int)
-> (forall a. Eq a => a -> t a -> Bool)
-> (forall a. Ord a => t a -> a)
-> (forall a. Ord a => t a -> a)
-> (forall a. Num a => t a -> a)
-> (forall a. Num a => t a -> a)
-> Foldable t
$cfold :: forall m. Monoid m => Arg m -> m
fold :: forall m. Monoid m => Arg m -> m
$cfoldMap :: forall m a. Monoid m => (a -> m) -> Arg a -> m
foldMap :: forall m a. Monoid m => (a -> m) -> Arg a -> m
$cfoldMap' :: forall m a. Monoid m => (a -> m) -> Arg a -> m
foldMap' :: forall m a. Monoid m => (a -> m) -> Arg a -> m
$cfoldr :: forall a b. (a -> b -> b) -> b -> Arg a -> b
foldr :: forall a b. (a -> b -> b) -> b -> Arg a -> b
$cfoldr' :: forall a b. (a -> b -> b) -> b -> Arg a -> b
foldr' :: forall a b. (a -> b -> b) -> b -> Arg a -> b
$cfoldl :: forall b a. (b -> a -> b) -> b -> Arg a -> b
foldl :: forall b a. (b -> a -> b) -> b -> Arg a -> b
$cfoldl' :: forall b a. (b -> a -> b) -> b -> Arg a -> b
foldl' :: forall b a. (b -> a -> b) -> b -> Arg a -> b
$cfoldr1 :: forall a. (a -> a -> a) -> Arg a -> a
foldr1 :: forall a. (a -> a -> a) -> Arg a -> a
$cfoldl1 :: forall a. (a -> a -> a) -> Arg a -> a
foldl1 :: forall a. (a -> a -> a) -> Arg a -> a
$ctoList :: forall a. Arg a -> [a]
toList :: forall a. Arg a -> [a]
$cnull :: forall a. Arg a -> Bool
null :: forall a. Arg a -> Bool
$clength :: forall a. Arg a -> Int
length :: forall a. Arg a -> Int
$celem :: forall a. Eq a => a -> Arg a -> Bool
elem :: forall a. Eq a => a -> Arg a -> Bool
$cmaximum :: forall a. Ord a => Arg a -> a
maximum :: forall a. Ord a => Arg a -> a
$cminimum :: forall a. Ord a => Arg a -> a
minimum :: forall a. Ord a => Arg a -> a
$csum :: forall a. Num a => Arg a -> a
sum :: forall a. Num a => Arg a -> a
$cproduct :: forall a. Num a => Arg a -> a
product :: forall a. Num a => Arg a -> a
Foldable, Functor Arg
Foldable Arg
(Functor Arg, Foldable Arg) =>
(forall (f :: * -> *) a b.
 Applicative f =>
 (a -> f b) -> Arg a -> f (Arg b))
-> (forall (f :: * -> *) a.
    Applicative f =>
    Arg (f a) -> f (Arg a))
-> (forall (m :: * -> *) a b.
    Monad m =>
    (a -> m b) -> Arg a -> m (Arg b))
-> (forall (m :: * -> *) a. Monad m => Arg (m a) -> m (Arg a))
-> Traversable Arg
forall (t :: * -> *).
(Functor t, Foldable t) =>
(forall (f :: * -> *) a b.
 Applicative f =>
 (a -> f b) -> t a -> f (t b))
-> (forall (f :: * -> *) a. Applicative f => t (f a) -> f (t a))
-> (forall (m :: * -> *) a b.
    Monad m =>
    (a -> m b) -> t a -> m (t b))
-> (forall (m :: * -> *) a. Monad m => t (m a) -> m (t a))
-> Traversable t
forall (m :: * -> *) a. Monad m => Arg (m a) -> m (Arg a)
forall (f :: * -> *) a. Applicative f => Arg (f a) -> f (Arg a)
forall (m :: * -> *) a b.
Monad m =>
(a -> m b) -> Arg a -> m (Arg b)
forall (f :: * -> *) a b.
Applicative f =>
(a -> f b) -> Arg a -> f (Arg b)
$ctraverse :: forall (f :: * -> *) a b.
Applicative f =>
(a -> f b) -> Arg a -> f (Arg b)
traverse :: forall (f :: * -> *) a b.
Applicative f =>
(a -> f b) -> Arg a -> f (Arg b)
$csequenceA :: forall (f :: * -> *) a. Applicative f => Arg (f a) -> f (Arg a)
sequenceA :: forall (f :: * -> *) a. Applicative f => Arg (f a) -> f (Arg a)
$cmapM :: forall (m :: * -> *) a b.
Monad m =>
(a -> m b) -> Arg a -> m (Arg b)
mapM :: forall (m :: * -> *) a b.
Monad m =>
(a -> m b) -> Arg a -> m (Arg b)
$csequence :: forall (m :: * -> *) a. Monad m => Arg (m a) -> m (Arg a)
sequence :: forall (m :: * -> *) a. Monad m => Arg (m a) -> m (Arg a)
Traversable)

instance Decoration Arg where
  traverseF :: forall (m :: * -> *) a b.
Functor m =>
(a -> m b) -> Arg a -> m (Arg b)
traverseF a -> m b
f (Arg ArgInfo
ai a
a) = ArgInfo -> b -> Arg b
forall e. ArgInfo -> e -> Arg e
Arg ArgInfo
ai (b -> Arg b) -> m b -> m (Arg b)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> a -> m b
f a
a

instance HasRange a => HasRange (Arg a) where
    getRange :: Arg a -> Range
getRange = a -> Range
forall a. HasRange a => a -> Range
getRange (a -> Range) -> (Arg a -> a) -> Arg a -> Range
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Arg a -> a
forall e. Arg e -> e
unArg

instance SetRange a => SetRange (Arg a) where
  setRange :: Range -> Arg a -> Arg a
setRange Range
r = (a -> a) -> Arg a -> Arg a
forall a b. (a -> b) -> Arg a -> Arg b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap ((a -> a) -> Arg a -> Arg a) -> (a -> a) -> Arg a -> Arg a
forall a b. (a -> b) -> a -> b
$ Range -> a -> a
forall a. SetRange a => Range -> a -> a
setRange Range
r

instance KillRange a => KillRange (Arg a) where
  killRange :: KillRangeT (Arg a)
killRange (Arg ArgInfo
info a
a) = (ArgInfo -> a -> Arg a) -> ArgInfo -> a -> Arg a
forall t (b :: Bool).
(KILLRANGE t b, IsBase t ~ b, All KillRange (Domains t)) =>
t -> t
killRangeN ArgInfo -> a -> Arg a
forall e. ArgInfo -> e -> Arg e
Arg ArgInfo
info a
a

-- Andreas, 2019-07-05, issue #3889
-- A dedicated equality for with-abstraction now exists,
-- thus, we can use intensional equality for Arg.
--
-- -- | Ignores 'Quantity', 'Relevance', 'Origin', and 'FreeVariables'.
-- --   Ignores content of argument if 'Irrelevant'.
-- --
-- instance Eq a => Eq (Arg a) where
--   Arg (ArgInfo h1 m1 _ _) x1 == Arg (ArgInfo h2 m2 _ _) x2 =
--     h1 == h2 && (isIrrelevant m1 || isIrrelevant m2 || x1 == x2)
--     -- Andreas, 2017-10-04, issue #2775, ignore irrelevant arguments during with-abstraction.
--     -- This is a hack, we should not use '(==)' in with-abstraction
--     -- and more generally not use it on Syntax.
--     -- Andrea: except for caching.

-- instance Show a => Show (Arg a) where
--     show (Arg (ArgInfo h (Modality r q) o fv) a) = showFVs fv $ showQ q $ showR r $ showO o $ showH h $ show a
--       where
--         showH Hidden       s = "{" ++ s ++ "}"
--         showH NotHidden    s = "(" ++ s ++ ")"
--         showH (Instance o) s = showOv o ++ "{{" ++ s ++ "}}"
--           where showOv YesOverlap = "overlap "
--                 showOv NoOverlap  = ""
--         showR r s = case r of
--           Irrelevant   -> "." ++ s
--           NonStrict    -> "?" ++ s
--           Relevant     -> "r" ++ s -- Andreas: I want to see it explicitly
--         showQ q s = case q of
--           Quantity0   -> "0" ++ s
--           Quantity1   -> "1" ++ s
--           Quantityω   -> "ω" ++ s
--         showO o s = case o of
--           UserWritten -> "u" ++ s
--           Inserted    -> "i" ++ s
--           Reflected   -> "g" ++ s -- generated by reflection
--           CaseSplit   -> "c" ++ s -- generated by case split
--           Substitution -> "s" ++ s
--         showFVs UnknownFVs    s = s
--         showFVs (KnownFVs fv) s = "fv" ++ show (IntSet.toList fv) ++ s

-- -- defined in Concrete.Pretty
-- instance Pretty a => Pretty (Arg a) where
--     pretty (Arg (ArgInfo h (Modality r q) o fv) a) = prettyFVs fv $ prettyQ q $ prettyR r $ prettyO o $ prettyH h $ pretty a
--       where
--         prettyH Hidden       s = "{" <> s <> "}"
--         prettyH NotHidden    s = "(" <> s <> ")"
--         prettyH (Instance o) s = prettyOv o <> "{{" <> s <> "}}"
--           where prettyOv YesOverlap = "overlap "
--                 prettyOv NoOverlap  = ""
--         prettyR r s = case r of
--           Irrelevant   -> "." <> s
--           NonStrict    -> "?" <> s
--           Relevant     -> "r" <> s -- Andreas: I want to see it explicitly
--         prettyQ q s = case q of
--           Quantity0   -> "0" <> s
--           Quantity1   -> "1" <> s
--           Quantityω   -> "ω" <> s
--         prettyO o s = case o of
--           UserWritten -> "u" <> s
--           Inserted    -> "i" <> s
--           Reflected   -> "g" <> s -- generated by reflection
--           CaseSplit   -> "c" <> s -- generated by case split
--           Substitution -> "s" <> s
--         prettyFVs UnknownFVs    s = s
--         prettyFVs (KnownFVs fv) s = "fv" <> pretty (IntSet.toList fv) <> s

instance NFData e => NFData (Arg e) where
  rnf :: Arg e -> ()
rnf (Arg ArgInfo
a e
b) = ArgInfo -> ()
forall a. NFData a => a -> ()
rnf ArgInfo
a () -> () -> ()
forall a b. a -> b -> b
`seq` e -> ()
forall a. NFData a => a -> ()
rnf e
b

instance LensArgInfo (Arg a) where
  getArgInfo :: Arg a -> ArgInfo
getArgInfo        = Arg a -> ArgInfo
forall e. Arg e -> ArgInfo
argInfo
  setArgInfo :: ArgInfo -> Arg a -> Arg a
setArgInfo ArgInfo
ai Arg a
arg = Arg a
arg { argInfo = ai }
  mapArgInfo :: (ArgInfo -> ArgInfo) -> Arg a -> Arg a
mapArgInfo ArgInfo -> ArgInfo
f Arg a
arg  = Arg a
arg { argInfo = f $ argInfo arg }

-- The other lenses are defined through LensArgInfo

instance LensHiding (Arg e) where
  getHiding :: Arg e -> Hiding
getHiding = Arg e -> Hiding
forall a. LensArgInfo a => LensGet a Hiding
getHidingArgInfo
  setHiding :: Hiding -> Arg e -> Arg e
setHiding = Hiding -> Arg e -> Arg e
forall a. LensArgInfo a => LensSet a Hiding
setHidingArgInfo
  mapHiding :: (Hiding -> Hiding) -> Arg e -> Arg e
mapHiding = (Hiding -> Hiding) -> Arg e -> Arg e
forall a. LensArgInfo a => LensMap a Hiding
mapHidingArgInfo

instance LensModality (Arg e) where
  getModality :: Arg e -> Modality
getModality = Arg e -> Modality
forall a. LensArgInfo a => LensGet a Modality
getModalityArgInfo
  setModality :: Modality -> Arg e -> Arg e
setModality = Modality -> Arg e -> Arg e
forall a. LensArgInfo a => LensSet a Modality
setModalityArgInfo
  mapModality :: (Modality -> Modality) -> Arg e -> Arg e
mapModality = (Modality -> Modality) -> Arg e -> Arg e
forall a. LensArgInfo a => LensMap a Modality
mapModalityArgInfo

instance LensOrigin (Arg e) where
  getOrigin :: Arg e -> Origin
getOrigin = Arg e -> Origin
forall a. LensArgInfo a => LensGet a Origin
getOriginArgInfo
  setOrigin :: Origin -> Arg e -> Arg e
setOrigin = Origin -> Arg e -> Arg e
forall a. LensArgInfo a => LensSet a Origin
setOriginArgInfo
  mapOrigin :: (Origin -> Origin) -> Arg e -> Arg e
mapOrigin = (Origin -> Origin) -> Arg e -> Arg e
forall a. LensArgInfo a => LensMap a Origin
mapOriginArgInfo

instance LensFreeVariables (Arg e) where
  getFreeVariables :: Arg e -> FreeVariables
getFreeVariables = Arg e -> FreeVariables
forall a. LensArgInfo a => LensGet a FreeVariables
getFreeVariablesArgInfo
  setFreeVariables :: FreeVariables -> Arg e -> Arg e
setFreeVariables = FreeVariables -> Arg e -> Arg e
forall a. LensArgInfo a => LensSet a FreeVariables
setFreeVariablesArgInfo
  mapFreeVariables :: (FreeVariables -> FreeVariables) -> Arg e -> Arg e
mapFreeVariables = (FreeVariables -> FreeVariables) -> Arg e -> Arg e
forall a. LensArgInfo a => LensMap a FreeVariables
mapFreeVariablesArgInfo

-- Since we have LensModality, we get relevance and quantity by default

instance LensRelevance (Arg e) where
  getRelevance :: Arg e -> Relevance
getRelevance = Arg e -> Relevance
forall a. LensModality a => LensGet a Relevance
getRelevanceMod
  setRelevance :: Relevance -> Arg e -> Arg e
setRelevance = Relevance -> Arg e -> Arg e
forall a. LensModality a => LensSet a Relevance
setRelevanceMod
  mapRelevance :: (Relevance -> Relevance) -> Arg e -> Arg e
mapRelevance = (Relevance -> Relevance) -> Arg e -> Arg e
forall a. LensModality a => LensMap a Relevance
mapRelevanceMod

instance LensQuantity (Arg e) where
  getQuantity :: Arg e -> Quantity
getQuantity = Arg e -> Quantity
forall a. LensModality a => LensGet a Quantity
getQuantityMod
  setQuantity :: Quantity -> Arg e -> Arg e
setQuantity = Quantity -> Arg e -> Arg e
forall a. LensModality a => LensSet a Quantity
setQuantityMod
  mapQuantity :: (Quantity -> Quantity) -> Arg e -> Arg e
mapQuantity = (Quantity -> Quantity) -> Arg e -> Arg e
forall a. LensModality a => LensMap a Quantity
mapQuantityMod

instance LensCohesion (Arg e) where
  getCohesion :: Arg e -> Cohesion
getCohesion = Arg e -> Cohesion
forall a. LensModality a => LensGet a Cohesion
getCohesionMod
  setCohesion :: Cohesion -> Arg e -> Arg e
setCohesion = Cohesion -> Arg e -> Arg e
forall a. LensModality a => LensSet a Cohesion
setCohesionMod
  mapCohesion :: (Cohesion -> Cohesion) -> Arg e -> Arg e
mapCohesion = (Cohesion -> Cohesion) -> Arg e -> Arg e
forall a. LensModality a => LensMap a Cohesion
mapCohesionMod

defaultArg :: a -> Arg a
defaultArg :: forall a. a -> Arg a
defaultArg = ArgInfo -> a -> Arg a
forall e. ArgInfo -> e -> Arg e
Arg ArgInfo
defaultArgInfo

-- | @xs \`withArgsFrom\` args@ translates @xs@ into a list of 'Arg's,
-- using the elements in @args@ to fill in the non-'unArg' fields.
--
-- Precondition: The two lists should have equal length.

withArgsFrom :: [a] -> [Arg b] -> [Arg a]
[a]
xs withArgsFrom :: forall a b. [a] -> [Arg b] -> [Arg a]
`withArgsFrom` [Arg b]
args =
  (a -> Arg b -> Arg a) -> [a] -> [Arg b] -> [Arg a]
forall a b c. (a -> b -> c) -> [a] -> [b] -> [c]
zipWith (\a
x Arg b
arg -> (b -> a) -> Arg b -> Arg a
forall a b. (a -> b) -> Arg a -> Arg b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (a -> b -> a
forall a b. a -> b -> a
const a
x) Arg b
arg) [a]
xs [Arg b]
args

withNamedArgsFrom :: [a] -> [NamedArg b] -> [NamedArg a]
[a]
xs withNamedArgsFrom :: forall a b. [a] -> [NamedArg b] -> [NamedArg a]
`withNamedArgsFrom` [NamedArg b]
args =
  (a -> NamedArg b -> NamedArg a)
-> [a] -> [NamedArg b] -> [NamedArg a]
forall a b c. (a -> b -> c) -> [a] -> [b] -> [c]
zipWith (\a
x -> (Named NamedName b -> Named_ a) -> NamedArg b -> NamedArg a
forall a b. (a -> b) -> Arg a -> Arg b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (a
x a -> Named NamedName b -> Named_ a
forall a b. a -> Named NamedName b -> Named NamedName a
forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$)) [a]
xs [NamedArg b]
args

---------------------------------------------------------------------------
-- * Names
---------------------------------------------------------------------------

class Eq a => Underscore a where
  underscore   :: a
  isUnderscore :: a -> Bool
  isUnderscore = (a -> a -> Bool
forall a. Eq a => a -> a -> Bool
== a
forall a. Underscore a => a
underscore)

instance Underscore String where
  underscore :: ArgName
underscore = ArgName
"_"

instance Underscore ByteString where
  underscore :: ByteString
underscore = ArgName -> ByteString
ByteString.pack ArgName
forall a. Underscore a => a
underscore

instance Underscore Doc where
  underscore :: Doc
underscore = ArgName -> Doc
forall a. ArgName -> Doc a
text ArgName
forall a. Underscore a => a
underscore

---------------------------------------------------------------------------
-- * Named arguments
---------------------------------------------------------------------------

-- | Something potentially carrying a name.
data Named name a =
    Named { forall name a. Named name a -> Maybe name
nameOf     :: Maybe name
          , forall name a. Named name a -> a
namedThing :: a
          }
    deriving (Named name a -> Named name a -> Bool
(Named name a -> Named name a -> Bool)
-> (Named name a -> Named name a -> Bool) -> Eq (Named name a)
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
forall name a.
(Eq name, Eq a) =>
Named name a -> Named name a -> Bool
$c== :: forall name a.
(Eq name, Eq a) =>
Named name a -> Named name a -> Bool
== :: Named name a -> Named name a -> Bool
$c/= :: forall name a.
(Eq name, Eq a) =>
Named name a -> Named name a -> Bool
/= :: Named name a -> Named name a -> Bool
Eq, Eq (Named name a)
Eq (Named name a) =>
(Named name a -> Named name a -> Ordering)
-> (Named name a -> Named name a -> Bool)
-> (Named name a -> Named name a -> Bool)
-> (Named name a -> Named name a -> Bool)
-> (Named name a -> Named name a -> Bool)
-> (Named name a -> Named name a -> Named name a)
-> (Named name a -> Named name a -> Named name a)
-> Ord (Named name a)
Named name a -> Named name a -> Bool
Named name a -> Named name a -> Ordering
Named name a -> Named name a -> Named name a
forall a.
Eq a =>
(a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
forall name a. (Ord name, Ord a) => Eq (Named name a)
forall name a.
(Ord name, Ord a) =>
Named name a -> Named name a -> Bool
forall name a.
(Ord name, Ord a) =>
Named name a -> Named name a -> Ordering
forall name a.
(Ord name, Ord a) =>
Named name a -> Named name a -> Named name a
$ccompare :: forall name a.
(Ord name, Ord a) =>
Named name a -> Named name a -> Ordering
compare :: Named name a -> Named name a -> Ordering
$c< :: forall name a.
(Ord name, Ord a) =>
Named name a -> Named name a -> Bool
< :: Named name a -> Named name a -> Bool
$c<= :: forall name a.
(Ord name, Ord a) =>
Named name a -> Named name a -> Bool
<= :: Named name a -> Named name a -> Bool
$c> :: forall name a.
(Ord name, Ord a) =>
Named name a -> Named name a -> Bool
> :: Named name a -> Named name a -> Bool
$c>= :: forall name a.
(Ord name, Ord a) =>
Named name a -> Named name a -> Bool
>= :: Named name a -> Named name a -> Bool
$cmax :: forall name a.
(Ord name, Ord a) =>
Named name a -> Named name a -> Named name a
max :: Named name a -> Named name a -> Named name a
$cmin :: forall name a.
(Ord name, Ord a) =>
Named name a -> Named name a -> Named name a
min :: Named name a -> Named name a -> Named name a
Ord, Int -> Named name a -> ShowS
[Named name a] -> ShowS
Named name a -> ArgName
(Int -> Named name a -> ShowS)
-> (Named name a -> ArgName)
-> ([Named name a] -> ShowS)
-> Show (Named name a)
forall a.
(Int -> a -> ShowS) -> (a -> ArgName) -> ([a] -> ShowS) -> Show a
forall name a. (Show name, Show a) => Int -> Named name a -> ShowS
forall name a. (Show name, Show a) => [Named name a] -> ShowS
forall name a. (Show name, Show a) => Named name a -> ArgName
$cshowsPrec :: forall name a. (Show name, Show a) => Int -> Named name a -> ShowS
showsPrec :: Int -> Named name a -> ShowS
$cshow :: forall name a. (Show name, Show a) => Named name a -> ArgName
show :: Named name a -> ArgName
$cshowList :: forall name a. (Show name, Show a) => [Named name a] -> ShowS
showList :: [Named name a] -> ShowS
Show, (forall a b. (a -> b) -> Named name a -> Named name b)
-> (forall a b. a -> Named name b -> Named name a)
-> Functor (Named name)
forall a b. a -> Named name b -> Named name a
forall a b. (a -> b) -> Named name a -> Named name b
forall name a b. a -> Named name b -> Named name a
forall name a b. (a -> b) -> Named name a -> Named name b
forall (f :: * -> *).
(forall a b. (a -> b) -> f a -> f b)
-> (forall a b. a -> f b -> f a) -> Functor f
$cfmap :: forall name a b. (a -> b) -> Named name a -> Named name b
fmap :: forall a b. (a -> b) -> Named name a -> Named name b
$c<$ :: forall name a b. a -> Named name b -> Named name a
<$ :: forall a b. a -> Named name b -> Named name a
Functor, (forall m. Monoid m => Named name m -> m)
-> (forall m a. Monoid m => (a -> m) -> Named name a -> m)
-> (forall m a. Monoid m => (a -> m) -> Named name a -> m)
-> (forall a b. (a -> b -> b) -> b -> Named name a -> b)
-> (forall a b. (a -> b -> b) -> b -> Named name a -> b)
-> (forall b a. (b -> a -> b) -> b -> Named name a -> b)
-> (forall b a. (b -> a -> b) -> b -> Named name a -> b)
-> (forall a. (a -> a -> a) -> Named name a -> a)
-> (forall a. (a -> a -> a) -> Named name a -> a)
-> (forall a. Named name a -> [a])
-> (forall a. Named name a -> Bool)
-> (forall a. Named name a -> Int)
-> (forall a. Eq a => a -> Named name a -> Bool)
-> (forall a. Ord a => Named name a -> a)
-> (forall a. Ord a => Named name a -> a)
-> (forall a. Num a => Named name a -> a)
-> (forall a. Num a => Named name a -> a)
-> Foldable (Named name)
forall a. Eq a => a -> Named name a -> Bool
forall a. Num a => Named name a -> a
forall a. Ord a => Named name a -> a
forall m. Monoid m => Named name m -> m
forall a. Named name a -> Bool
forall a. Named name a -> Int
forall a. Named name a -> [a]
forall a. (a -> a -> a) -> Named name a -> a
forall name a. Eq a => a -> Named name a -> Bool
forall name a. Num a => Named name a -> a
forall name a. Ord a => Named name a -> a
forall m a. Monoid m => (a -> m) -> Named name a -> m
forall name m. Monoid m => Named name m -> m
forall name a. Named name a -> Bool
forall name a. Named name a -> Int
forall name a. Named name a -> [a]
forall b a. (b -> a -> b) -> b -> Named name a -> b
forall a b. (a -> b -> b) -> b -> Named name a -> b
forall name a. (a -> a -> a) -> Named name a -> a
forall name m a. Monoid m => (a -> m) -> Named name a -> m
forall name b a. (b -> a -> b) -> b -> Named name a -> b
forall name a b. (a -> b -> b) -> b -> Named name a -> b
forall (t :: * -> *).
(forall m. Monoid m => t m -> m)
-> (forall m a. Monoid m => (a -> m) -> t a -> m)
-> (forall m a. Monoid m => (a -> m) -> t a -> m)
-> (forall a b. (a -> b -> b) -> b -> t a -> b)
-> (forall a b. (a -> b -> b) -> b -> t a -> b)
-> (forall b a. (b -> a -> b) -> b -> t a -> b)
-> (forall b a. (b -> a -> b) -> b -> t a -> b)
-> (forall a. (a -> a -> a) -> t a -> a)
-> (forall a. (a -> a -> a) -> t a -> a)
-> (forall a. t a -> [a])
-> (forall a. t a -> Bool)
-> (forall a. t a -> Int)
-> (forall a. Eq a => a -> t a -> Bool)
-> (forall a. Ord a => t a -> a)
-> (forall a. Ord a => t a -> a)
-> (forall a. Num a => t a -> a)
-> (forall a. Num a => t a -> a)
-> Foldable t
$cfold :: forall name m. Monoid m => Named name m -> m
fold :: forall m. Monoid m => Named name m -> m
$cfoldMap :: forall name m a. Monoid m => (a -> m) -> Named name a -> m
foldMap :: forall m a. Monoid m => (a -> m) -> Named name a -> m
$cfoldMap' :: forall name m a. Monoid m => (a -> m) -> Named name a -> m
foldMap' :: forall m a. Monoid m => (a -> m) -> Named name a -> m
$cfoldr :: forall name a b. (a -> b -> b) -> b -> Named name a -> b
foldr :: forall a b. (a -> b -> b) -> b -> Named name a -> b
$cfoldr' :: forall name a b. (a -> b -> b) -> b -> Named name a -> b
foldr' :: forall a b. (a -> b -> b) -> b -> Named name a -> b
$cfoldl :: forall name b a. (b -> a -> b) -> b -> Named name a -> b
foldl :: forall b a. (b -> a -> b) -> b -> Named name a -> b
$cfoldl' :: forall name b a. (b -> a -> b) -> b -> Named name a -> b
foldl' :: forall b a. (b -> a -> b) -> b -> Named name a -> b
$cfoldr1 :: forall name a. (a -> a -> a) -> Named name a -> a
foldr1 :: forall a. (a -> a -> a) -> Named name a -> a
$cfoldl1 :: forall name a. (a -> a -> a) -> Named name a -> a
foldl1 :: forall a. (a -> a -> a) -> Named name a -> a
$ctoList :: forall name a. Named name a -> [a]
toList :: forall a. Named name a -> [a]
$cnull :: forall name a. Named name a -> Bool
null :: forall a. Named name a -> Bool
$clength :: forall name a. Named name a -> Int
length :: forall a. Named name a -> Int
$celem :: forall name a. Eq a => a -> Named name a -> Bool
elem :: forall a. Eq a => a -> Named name a -> Bool
$cmaximum :: forall name a. Ord a => Named name a -> a
maximum :: forall a. Ord a => Named name a -> a
$cminimum :: forall name a. Ord a => Named name a -> a
minimum :: forall a. Ord a => Named name a -> a
$csum :: forall name a. Num a => Named name a -> a
sum :: forall a. Num a => Named name a -> a
$cproduct :: forall name a. Num a => Named name a -> a
product :: forall a. Num a => Named name a -> a
Foldable, Functor (Named name)
Foldable (Named name)
(Functor (Named name), Foldable (Named name)) =>
(forall (f :: * -> *) a b.
 Applicative f =>
 (a -> f b) -> Named name a -> f (Named name b))
-> (forall (f :: * -> *) a.
    Applicative f =>
    Named name (f a) -> f (Named name a))
-> (forall (m :: * -> *) a b.
    Monad m =>
    (a -> m b) -> Named name a -> m (Named name b))
-> (forall (m :: * -> *) a.
    Monad m =>
    Named name (m a) -> m (Named name a))
-> Traversable (Named name)
forall name. Functor (Named name)
forall name. Foldable (Named name)
forall name (m :: * -> *) a.
Monad m =>
Named name (m a) -> m (Named name a)
forall name (f :: * -> *) a.
Applicative f =>
Named name (f a) -> f (Named name a)
forall name (m :: * -> *) a b.
Monad m =>
(a -> m b) -> Named name a -> m (Named name b)
forall name (f :: * -> *) a b.
Applicative f =>
(a -> f b) -> Named name a -> f (Named name b)
forall (t :: * -> *).
(Functor t, Foldable t) =>
(forall (f :: * -> *) a b.
 Applicative f =>
 (a -> f b) -> t a -> f (t b))
-> (forall (f :: * -> *) a. Applicative f => t (f a) -> f (t a))
-> (forall (m :: * -> *) a b.
    Monad m =>
    (a -> m b) -> t a -> m (t b))
-> (forall (m :: * -> *) a. Monad m => t (m a) -> m (t a))
-> Traversable t
forall (m :: * -> *) a.
Monad m =>
Named name (m a) -> m (Named name a)
forall (f :: * -> *) a.
Applicative f =>
Named name (f a) -> f (Named name a)
forall (m :: * -> *) a b.
Monad m =>
(a -> m b) -> Named name a -> m (Named name b)
forall (f :: * -> *) a b.
Applicative f =>
(a -> f b) -> Named name a -> f (Named name b)
$ctraverse :: forall name (f :: * -> *) a b.
Applicative f =>
(a -> f b) -> Named name a -> f (Named name b)
traverse :: forall (f :: * -> *) a b.
Applicative f =>
(a -> f b) -> Named name a -> f (Named name b)
$csequenceA :: forall name (f :: * -> *) a.
Applicative f =>
Named name (f a) -> f (Named name a)
sequenceA :: forall (f :: * -> *) a.
Applicative f =>
Named name (f a) -> f (Named name a)
$cmapM :: forall name (m :: * -> *) a b.
Monad m =>
(a -> m b) -> Named name a -> m (Named name b)
mapM :: forall (m :: * -> *) a b.
Monad m =>
(a -> m b) -> Named name a -> m (Named name b)
$csequence :: forall name (m :: * -> *) a.
Monad m =>
Named name (m a) -> m (Named name a)
sequence :: forall (m :: * -> *) a.
Monad m =>
Named name (m a) -> m (Named name a)
Traversable)

-- | Standard naming.
type Named_ = Named NamedName

-- | Standard argument names.
type NamedName = WithOrigin (Ranged ArgName)

-- | Equality of argument names of things modulo 'Range' and 'Origin'.
sameName :: NamedName -> NamedName -> Bool
sameName :: NamedName -> NamedName -> Bool
sameName = ArgName -> ArgName -> Bool
forall a. Eq a => a -> a -> Bool
(==) (ArgName -> ArgName -> Bool)
-> (NamedName -> ArgName) -> NamedName -> NamedName -> Bool
forall b c a. (b -> b -> c) -> (a -> b) -> a -> a -> c
`on` (Ranged ArgName -> ArgName
forall a. Ranged a -> a
rangedThing (Ranged ArgName -> ArgName)
-> (NamedName -> Ranged ArgName) -> NamedName -> ArgName
forall b c a. (b -> c) -> (a -> b) -> a -> c
. NamedName -> Ranged ArgName
forall a. WithOrigin a -> a
woThing)

unnamed :: a -> Named name a
unnamed :: forall a name. a -> Named name a
unnamed = Maybe name -> a -> Named name a
forall name a. Maybe name -> a -> Named name a
Named Maybe name
forall a. Maybe a
Nothing

isUnnamed :: Named name a -> Maybe a
isUnnamed :: forall name a. Named name a -> Maybe a
isUnnamed = \case
  Named Maybe name
Nothing a
a -> a -> Maybe a
forall a. a -> Maybe a
Just a
a
  Named Just{}  a
a -> Maybe a
forall a. Maybe a
Nothing

named :: name -> a -> Named name a
named :: forall name a. name -> a -> Named name a
named = Maybe name -> a -> Named name a
forall name a. Maybe name -> a -> Named name a
Named (Maybe name -> a -> Named name a)
-> (name -> Maybe name) -> name -> a -> Named name a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. name -> Maybe name
forall a. a -> Maybe a
Just

userNamed :: Ranged ArgName -> a -> Named_ a
userNamed :: forall a. Ranged ArgName -> a -> Named_ a
userNamed = Maybe NamedName -> a -> Named NamedName a
forall name a. Maybe name -> a -> Named name a
Named (Maybe NamedName -> a -> Named NamedName a)
-> (Ranged ArgName -> Maybe NamedName)
-> Ranged ArgName
-> a
-> Named NamedName a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. NamedName -> Maybe NamedName
forall a. a -> Maybe a
Just (NamedName -> Maybe NamedName)
-> (Ranged ArgName -> NamedName)
-> Ranged ArgName
-> Maybe NamedName
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Origin -> Ranged ArgName -> NamedName
forall a. Origin -> a -> WithOrigin a
WithOrigin Origin
UserWritten

-- | Accessor/editor for the 'nameOf' component.
class LensNamed a where
  -- | The type of the name
  type NameOf a
  lensNamed :: Lens' a (Maybe (NameOf a))

  -- Lenses lift through decorations:
  default lensNamed :: (Decoration f, LensNamed b, NameOf b ~ NameOf a, f b ~ a) => Lens' a (Maybe (NameOf a))
  lensNamed = (b -> f b) -> a -> f a
(b -> f b) -> f b -> f (f b)
forall (t :: * -> *) (m :: * -> *) a b.
(Decoration t, Functor m) =>
(a -> m b) -> t a -> m (t b)
forall (m :: * -> *) a b. Functor m => (a -> m b) -> f a -> m (f b)
traverseF ((b -> f b) -> a -> f a)
-> ((Maybe (NameOf (f b)) -> f (Maybe (NameOf (f b)))) -> b -> f b)
-> (Maybe (NameOf (f b)) -> f (Maybe (NameOf (f b))))
-> a
-> f a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Maybe (NameOf b) -> f (Maybe (NameOf b))) -> b -> f b
(Maybe (NameOf (f b)) -> f (Maybe (NameOf (f b)))) -> b -> f b
forall a. LensNamed a => Lens' a (Maybe (NameOf a))
Lens' b (Maybe (NameOf b))
lensNamed

instance LensNamed a => LensNamed (Arg a) where
  type NameOf (Arg a) = NameOf a

instance LensNamed (Maybe a) where
  type NameOf (Maybe a) = a
  lensNamed :: Lens' (Maybe a) (Maybe (NameOf (Maybe a)))
lensNamed = (Maybe a -> f (Maybe a)) -> Maybe a -> f (Maybe a)
(Maybe (NameOf (Maybe a)) -> f (Maybe (NameOf (Maybe a))))
-> Maybe a -> f (Maybe a)
forall a. a -> a
id

instance LensNamed (Named name a) where
  type NameOf (Named name a) = name

  lensNamed :: Lens' (Named name a) (Maybe (NameOf (Named name a)))
lensNamed Maybe (NameOf (Named name a)) -> f (Maybe (NameOf (Named name a)))
f (Named Maybe name
mn a
a) = Maybe (NameOf (Named name a)) -> f (Maybe (NameOf (Named name a)))
f Maybe name
Maybe (NameOf (Named name a))
mn f (Maybe name) -> (Maybe name -> Named name a) -> f (Named name a)
forall (m :: * -> *) a b. Functor m => m a -> (a -> b) -> m b
<&> \ Maybe name
mn' -> Maybe name -> a -> Named name a
forall name a. Maybe name -> a -> Named name a
Named Maybe name
mn' a
a

getNameOf :: LensNamed a => a -> Maybe (NameOf a)
getNameOf :: forall a. LensNamed a => a -> Maybe (NameOf a)
getNameOf a
a = a
a a -> Lens' a (Maybe (NameOf a)) -> Maybe (NameOf a)
forall o i. o -> Lens' o i -> i
^. (Maybe (NameOf a) -> f (Maybe (NameOf a))) -> a -> f a
forall a. LensNamed a => Lens' a (Maybe (NameOf a))
Lens' a (Maybe (NameOf a))
lensNamed

setNameOf :: LensNamed a => Maybe (NameOf a) -> a -> a
setNameOf :: forall a. LensNamed a => Maybe (NameOf a) -> a -> a
setNameOf = Lens' a (Maybe (NameOf a)) -> Maybe (NameOf a) -> a -> a
forall o i. Lens' o i -> LensSet o i
set (Maybe (NameOf a) -> f (Maybe (NameOf a))) -> a -> f a
forall a. LensNamed a => Lens' a (Maybe (NameOf a))
Lens' a (Maybe (NameOf a))
lensNamed

mapNameOf :: LensNamed a => (Maybe (NameOf a) -> Maybe (NameOf a)) -> a -> a
mapNameOf :: forall a.
LensNamed a =>
(Maybe (NameOf a) -> Maybe (NameOf a)) -> a -> a
mapNameOf = Lens' a (Maybe (NameOf a))
-> (Maybe (NameOf a) -> Maybe (NameOf a)) -> a -> a
forall o i. Lens' o i -> LensMap o i
over (Maybe (NameOf a) -> f (Maybe (NameOf a))) -> a -> f a
forall a. LensNamed a => Lens' a (Maybe (NameOf a))
Lens' a (Maybe (NameOf a))
lensNamed
bareNameOf :: (LensNamed a, NameOf a ~ NamedName) => a -> Maybe ArgName
bareNameOf :: forall a. (LensNamed a, NameOf a ~ NamedName) => a -> Maybe ArgName
bareNameOf a
a = Ranged ArgName -> ArgName
forall a. Ranged a -> a
rangedThing (Ranged ArgName -> ArgName)
-> (NamedName -> Ranged ArgName) -> NamedName -> ArgName
forall b c a. (b -> c) -> (a -> b) -> a -> c
. NamedName -> Ranged ArgName
forall a. WithOrigin a -> a
woThing (NamedName -> ArgName) -> Maybe NamedName -> Maybe ArgName
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> a -> Maybe (NameOf a)
forall a. LensNamed a => a -> Maybe (NameOf a)
getNameOf a
a

bareNameWithDefault :: (LensNamed a, NameOf a ~ NamedName) => ArgName -> a -> ArgName
bareNameWithDefault :: forall a.
(LensNamed a, NameOf a ~ NamedName) =>
ArgName -> a -> ArgName
bareNameWithDefault ArgName
x a
a = ArgName -> (NamedName -> ArgName) -> Maybe NamedName -> ArgName
forall b a. b -> (a -> b) -> Maybe a -> b
maybe ArgName
x (Ranged ArgName -> ArgName
forall a. Ranged a -> a
rangedThing (Ranged ArgName -> ArgName)
-> (NamedName -> Ranged ArgName) -> NamedName -> ArgName
forall b c a. (b -> c) -> (a -> b) -> a -> c
. NamedName -> Ranged ArgName
forall a. WithOrigin a -> a
woThing) (Maybe NamedName -> ArgName) -> Maybe NamedName -> ArgName
forall a b. (a -> b) -> a -> b
$ a -> Maybe (NameOf a)
forall a. LensNamed a => a -> Maybe (NameOf a)
getNameOf a
a

-- | Equality of argument names of things modulo 'Range' and 'Origin'.
namedSame :: (LensNamed a, LensNamed b, NameOf a ~ NamedName, NameOf b ~ NamedName) => a -> b -> Bool
namedSame :: forall a b.
(LensNamed a, LensNamed b, NameOf a ~ NamedName,
 NameOf b ~ NamedName) =>
a -> b -> Bool
namedSame a
a b
b = case (a -> Maybe (NameOf a)
forall a. LensNamed a => a -> Maybe (NameOf a)
getNameOf a
a, b -> Maybe (NameOf b)
forall a. LensNamed a => a -> Maybe (NameOf a)
getNameOf b
b) of
  (Maybe NamedName
Nothing, Maybe NamedName
Nothing) -> Bool
True
  (Just NamedName
x , Just NamedName
y ) -> NamedName -> NamedName -> Bool
sameName NamedName
x NamedName
y
  (Maybe NamedName, Maybe NamedName)
_ -> Bool
False

-- | Does an argument @arg@ fit the shape @dom@ of the next expected argument?
--
--   The hiding has to match, and if the argument has a name, it should match
--   the name of the domain.
--
--   'Nothing' should be '__IMPOSSIBLE__', so use as
--   @@
--     fromMaybe __IMPOSSIBLE__ $ fittingNamedArg arg dom
--   @@
--
fittingNamedArg
  :: ( LensNamed arg, NameOf arg ~ NamedName, LensHiding arg
     , LensNamed dom, NameOf dom ~ NamedName, LensHiding dom )
  => arg -> dom -> Maybe Bool
fittingNamedArg :: forall arg dom.
(LensNamed arg, NameOf arg ~ NamedName, LensHiding arg,
 LensNamed dom, NameOf dom ~ NamedName, LensHiding dom) =>
arg -> dom -> Maybe Bool
fittingNamedArg arg
arg dom
dom
    | Bool -> Bool
not (Bool -> Bool) -> Bool -> Bool
forall a b. (a -> b) -> a -> b
$ arg -> dom -> Bool
forall a b. (LensHiding a, LensHiding b) => a -> b -> Bool
sameHiding arg
arg dom
dom = Maybe Bool
no
    | arg -> Bool
forall a. LensHiding a => a -> Bool
visible arg
arg              = Maybe Bool
yes
    | Bool
otherwise =
        Maybe ArgName
-> Maybe Bool -> (ArgName -> Maybe Bool) -> Maybe Bool
forall a b. Maybe a -> b -> (a -> b) -> b
caseMaybe (arg -> Maybe ArgName
forall a. (LensNamed a, NameOf a ~ NamedName) => a -> Maybe ArgName
bareNameOf arg
arg) Maybe Bool
yes        ((ArgName -> Maybe Bool) -> Maybe Bool)
-> (ArgName -> Maybe Bool) -> Maybe Bool
forall a b. (a -> b) -> a -> b
$ \ ArgName
x ->
        Maybe ArgName
-> Maybe Bool -> (ArgName -> Maybe Bool) -> Maybe Bool
forall a b. Maybe a -> b -> (a -> b) -> b
caseMaybe (dom -> Maybe ArgName
forall a. (LensNamed a, NameOf a ~ NamedName) => a -> Maybe ArgName
bareNameOf dom
dom) Maybe Bool
forall a. Maybe a
impossible ((ArgName -> Maybe Bool) -> Maybe Bool)
-> (ArgName -> Maybe Bool) -> Maybe Bool
forall a b. (a -> b) -> a -> b
$ \ ArgName
y ->
        Bool -> Maybe Bool
forall a. a -> Maybe a
forall (m :: * -> *) a. Monad m => a -> m a
return (Bool -> Maybe Bool) -> Bool -> Maybe Bool
forall a b. (a -> b) -> a -> b
$ ArgName
x ArgName -> ArgName -> Bool
forall a. Eq a => a -> a -> Bool
== ArgName
y
  where
    yes :: Maybe Bool
yes = Bool -> Maybe Bool
forall a. a -> Maybe a
forall (m :: * -> *) a. Monad m => a -> m a
return Bool
True
    no :: Maybe Bool
no  = Bool -> Maybe Bool
forall a. a -> Maybe a
forall (m :: * -> *) a. Monad m => a -> m a
return Bool
False
    impossible :: Maybe a
impossible = Maybe a
forall a. Maybe a
Nothing

-- Standard instances for 'Named':

instance Decoration (Named name) where
  traverseF :: forall (m :: * -> *) a b.
Functor m =>
(a -> m b) -> Named name a -> m (Named name b)
traverseF a -> m b
f (Named Maybe name
n a
a) = Maybe name -> b -> Named name b
forall name a. Maybe name -> a -> Named name a
Named Maybe name
n (b -> Named name b) -> m b -> m (Named name b)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> a -> m b
f a
a

instance HasRange a => HasRange (Named name a) where
    getRange :: Named name a -> Range
getRange = a -> Range
forall a. HasRange a => a -> Range
getRange (a -> Range) -> (Named name a -> a) -> Named name a -> Range
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Named name a -> a
forall name a. Named name a -> a
namedThing

instance SetRange a => SetRange (Named name a) where
  setRange :: Range -> Named name a -> Named name a
setRange Range
r = (a -> a) -> Named name a -> Named name a
forall a b. (a -> b) -> Named name a -> Named name b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap ((a -> a) -> Named name a -> Named name a)
-> (a -> a) -> Named name a -> Named name a
forall a b. (a -> b) -> a -> b
$ Range -> a -> a
forall a. SetRange a => Range -> a -> a
setRange Range
r

instance (KillRange name, KillRange a) => KillRange (Named name a) where
  killRange :: KillRangeT (Named name a)
killRange (Named Maybe name
n a
a) = Maybe name -> a -> Named name a
forall name a. Maybe name -> a -> Named name a
Named (KillRangeT (Maybe name)
forall a. KillRange a => KillRangeT a
killRange Maybe name
n) (KillRangeT a
forall a. KillRange a => KillRangeT a
killRange a
a)

-- instance Show a => Show (Named_ a) where
--     show (Named Nothing a)  = show a
--     show (Named (Just n) a) = rawNameToString (rangedThing n) ++ " = " ++ show a

-- -- Defined in Concrete.Pretty
-- instance Pretty a => Pretty (Named_ a) where
--     pretty (Named Nothing a)  = pretty a
--     pretty (Named (Just n) a) = text (rawNameToString (rangedThing n)) <+> "=" <+> pretty a

instance (NFData name, NFData a) => NFData (Named name a) where
  rnf :: Named name a -> ()
rnf (Named Maybe name
a a
b) = Maybe name -> ()
forall a. NFData a => a -> ()
rnf Maybe name
a () -> () -> ()
forall a b. a -> b -> b
`seq` a -> ()
forall a. NFData a => a -> ()
rnf a
b

-- | Only 'Hidden' arguments can have names.
type NamedArg a = Arg (Named_ a)

-- | Get the content of a 'NamedArg'.
namedArg :: NamedArg a -> a
namedArg :: forall a. NamedArg a -> a
namedArg = Named NamedName a -> a
forall name a. Named name a -> a
namedThing (Named NamedName a -> a)
-> (NamedArg a -> Named NamedName a) -> NamedArg a -> a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. NamedArg a -> Named NamedName a
forall e. Arg e -> e
unArg

defaultNamedArg :: a -> NamedArg a
defaultNamedArg :: forall a. a -> NamedArg a
defaultNamedArg = ArgInfo -> a -> NamedArg a
forall a. ArgInfo -> a -> NamedArg a
unnamedArg ArgInfo
defaultArgInfo

unnamedArg :: ArgInfo -> a -> NamedArg a
unnamedArg :: forall a. ArgInfo -> a -> NamedArg a
unnamedArg ArgInfo
info = ArgInfo -> Named_ a -> Arg (Named_ a)
forall e. ArgInfo -> e -> Arg e
Arg ArgInfo
info (Named_ a -> Arg (Named_ a))
-> (a -> Named_ a) -> a -> Arg (Named_ a)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. a -> Named_ a
forall a name. a -> Named name a
unnamed

-- | The functor instance for 'NamedArg' would be ambiguous,
--   so we give it another name here.
updateNamedArg :: (a -> b) -> NamedArg a -> NamedArg b
updateNamedArg :: forall a b. (a -> b) -> NamedArg a -> NamedArg b
updateNamedArg = (Named_ a -> Named_ b) -> Arg (Named_ a) -> Arg (Named_ b)
forall a b. (a -> b) -> Arg a -> Arg b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap ((Named_ a -> Named_ b) -> Arg (Named_ a) -> Arg (Named_ b))
-> ((a -> b) -> Named_ a -> Named_ b)
-> (a -> b)
-> Arg (Named_ a)
-> Arg (Named_ b)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (a -> b) -> Named_ a -> Named_ b
forall a b. (a -> b) -> Named NamedName a -> Named NamedName b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap

updateNamedArgA :: Applicative f => (a -> f b) -> NamedArg a -> f (NamedArg b)
updateNamedArgA :: forall (f :: * -> *) a b.
Applicative f =>
(a -> f b) -> NamedArg a -> f (NamedArg b)
updateNamedArgA = (Named_ a -> f (Named_ b)) -> Arg (Named_ a) -> f (Arg (Named_ b))
forall (t :: * -> *) (f :: * -> *) a b.
(Traversable t, Applicative f) =>
(a -> f b) -> t a -> f (t b)
forall (f :: * -> *) a b.
Applicative f =>
(a -> f b) -> Arg a -> f (Arg b)
traverse ((Named_ a -> f (Named_ b))
 -> Arg (Named_ a) -> f (Arg (Named_ b)))
-> ((a -> f b) -> Named_ a -> f (Named_ b))
-> (a -> f b)
-> Arg (Named_ a)
-> f (Arg (Named_ b))
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (a -> f b) -> Named_ a -> f (Named_ b)
forall (t :: * -> *) (f :: * -> *) a b.
(Traversable t, Applicative f) =>
(a -> f b) -> t a -> f (t b)
forall (f :: * -> *) a b.
Applicative f =>
(a -> f b) -> Named NamedName a -> f (Named NamedName b)
traverse

-- | @setNamedArg a b = updateNamedArg (const b) a@
setNamedArg :: NamedArg a -> b -> NamedArg b
setNamedArg :: forall a b. NamedArg a -> b -> NamedArg b
setNamedArg NamedArg a
a b
b = (b
b b -> Named NamedName a -> Named NamedName b
forall a b. a -> Named NamedName b -> Named NamedName a
forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$) (Named NamedName a -> Named NamedName b)
-> NamedArg a -> Arg (Named NamedName b)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> NamedArg a
a

-- ** ArgName

-- | Names in binders and arguments.
type ArgName = String

argNameToString :: ArgName -> String
argNameToString :: ShowS
argNameToString = ShowS
forall a. a -> a
id

stringToArgName :: String -> ArgName
stringToArgName :: ShowS
stringToArgName = ShowS
forall a. a -> a
id

appendArgNames :: ArgName -> ArgName -> ArgName
appendArgNames :: ArgName -> ShowS
appendArgNames = ArgName -> ShowS
forall a. [a] -> [a] -> [a]
(++)

---------------------------------------------------------------------------
-- * Range decoration.
---------------------------------------------------------------------------

-- | Thing with range info.
data Ranged a = Ranged
  { forall a. Ranged a -> Range
rangeOf     :: Range
  , forall a. Ranged a -> a
rangedThing :: a
  }
  deriving (Int -> Ranged a -> ShowS
[Ranged a] -> ShowS
Ranged a -> ArgName
(Int -> Ranged a -> ShowS)
-> (Ranged a -> ArgName)
-> ([Ranged a] -> ShowS)
-> Show (Ranged a)
forall a. Show a => Int -> Ranged a -> ShowS
forall a. Show a => [Ranged a] -> ShowS
forall a. Show a => Ranged a -> ArgName
forall a.
(Int -> a -> ShowS) -> (a -> ArgName) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: forall a. Show a => Int -> Ranged a -> ShowS
showsPrec :: Int -> Ranged a -> ShowS
$cshow :: forall a. Show a => Ranged a -> ArgName
show :: Ranged a -> ArgName
$cshowList :: forall a. Show a => [Ranged a] -> ShowS
showList :: [Ranged a] -> ShowS
Show, (forall a b. (a -> b) -> Ranged a -> Ranged b)
-> (forall a b. a -> Ranged b -> Ranged a) -> Functor Ranged
forall a b. a -> Ranged b -> Ranged a
forall a b. (a -> b) -> Ranged a -> Ranged b
forall (f :: * -> *).
(forall a b. (a -> b) -> f a -> f b)
-> (forall a b. a -> f b -> f a) -> Functor f
$cfmap :: forall a b. (a -> b) -> Ranged a -> Ranged b
fmap :: forall a b. (a -> b) -> Ranged a -> Ranged b
$c<$ :: forall a b. a -> Ranged b -> Ranged a
<$ :: forall a b. a -> Ranged b -> Ranged a
Functor, (forall m. Monoid m => Ranged m -> m)
-> (forall m a. Monoid m => (a -> m) -> Ranged a -> m)
-> (forall m a. Monoid m => (a -> m) -> Ranged a -> m)
-> (forall a b. (a -> b -> b) -> b -> Ranged a -> b)
-> (forall a b. (a -> b -> b) -> b -> Ranged a -> b)
-> (forall b a. (b -> a -> b) -> b -> Ranged a -> b)
-> (forall b a. (b -> a -> b) -> b -> Ranged a -> b)
-> (forall a. (a -> a -> a) -> Ranged a -> a)
-> (forall a. (a -> a -> a) -> Ranged a -> a)
-> (forall a. Ranged a -> [a])
-> (forall a. Ranged a -> Bool)
-> (forall a. Ranged a -> Int)
-> (forall a. Eq a => a -> Ranged a -> Bool)
-> (forall a. Ord a => Ranged a -> a)
-> (forall a. Ord a => Ranged a -> a)
-> (forall a. Num a => Ranged a -> a)
-> (forall a. Num a => Ranged a -> a)
-> Foldable Ranged
forall a. Eq a => a -> Ranged a -> Bool
forall a. Num a => Ranged a -> a
forall a. Ord a => Ranged a -> a
forall m. Monoid m => Ranged m -> m
forall a. Ranged a -> Bool
forall a. Ranged a -> Int
forall a. Ranged a -> [a]
forall a. (a -> a -> a) -> Ranged a -> a
forall m a. Monoid m => (a -> m) -> Ranged a -> m
forall b a. (b -> a -> b) -> b -> Ranged a -> b
forall a b. (a -> b -> b) -> b -> Ranged a -> b
forall (t :: * -> *).
(forall m. Monoid m => t m -> m)
-> (forall m a. Monoid m => (a -> m) -> t a -> m)
-> (forall m a. Monoid m => (a -> m) -> t a -> m)
-> (forall a b. (a -> b -> b) -> b -> t a -> b)
-> (forall a b. (a -> b -> b) -> b -> t a -> b)
-> (forall b a. (b -> a -> b) -> b -> t a -> b)
-> (forall b a. (b -> a -> b) -> b -> t a -> b)
-> (forall a. (a -> a -> a) -> t a -> a)
-> (forall a. (a -> a -> a) -> t a -> a)
-> (forall a. t a -> [a])
-> (forall a. t a -> Bool)
-> (forall a. t a -> Int)
-> (forall a. Eq a => a -> t a -> Bool)
-> (forall a. Ord a => t a -> a)
-> (forall a. Ord a => t a -> a)
-> (forall a. Num a => t a -> a)
-> (forall a. Num a => t a -> a)
-> Foldable t
$cfold :: forall m. Monoid m => Ranged m -> m
fold :: forall m. Monoid m => Ranged m -> m
$cfoldMap :: forall m a. Monoid m => (a -> m) -> Ranged a -> m
foldMap :: forall m a. Monoid m => (a -> m) -> Ranged a -> m
$cfoldMap' :: forall m a. Monoid m => (a -> m) -> Ranged a -> m
foldMap' :: forall m a. Monoid m => (a -> m) -> Ranged a -> m
$cfoldr :: forall a b. (a -> b -> b) -> b -> Ranged a -> b
foldr :: forall a b. (a -> b -> b) -> b -> Ranged a -> b
$cfoldr' :: forall a b. (a -> b -> b) -> b -> Ranged a -> b
foldr' :: forall a b. (a -> b -> b) -> b -> Ranged a -> b
$cfoldl :: forall b a. (b -> a -> b) -> b -> Ranged a -> b
foldl :: forall b a. (b -> a -> b) -> b -> Ranged a -> b
$cfoldl' :: forall b a. (b -> a -> b) -> b -> Ranged a -> b
foldl' :: forall b a. (b -> a -> b) -> b -> Ranged a -> b
$cfoldr1 :: forall a. (a -> a -> a) -> Ranged a -> a
foldr1 :: forall a. (a -> a -> a) -> Ranged a -> a
$cfoldl1 :: forall a. (a -> a -> a) -> Ranged a -> a
foldl1 :: forall a. (a -> a -> a) -> Ranged a -> a
$ctoList :: forall a. Ranged a -> [a]
toList :: forall a. Ranged a -> [a]
$cnull :: forall a. Ranged a -> Bool
null :: forall a. Ranged a -> Bool
$clength :: forall a. Ranged a -> Int
length :: forall a. Ranged a -> Int
$celem :: forall a. Eq a => a -> Ranged a -> Bool
elem :: forall a. Eq a => a -> Ranged a -> Bool
$cmaximum :: forall a. Ord a => Ranged a -> a
maximum :: forall a. Ord a => Ranged a -> a
$cminimum :: forall a. Ord a => Ranged a -> a
minimum :: forall a. Ord a => Ranged a -> a
$csum :: forall a. Num a => Ranged a -> a
sum :: forall a. Num a => Ranged a -> a
$cproduct :: forall a. Num a => Ranged a -> a
product :: forall a. Num a => Ranged a -> a
Foldable, Functor Ranged
Foldable Ranged
(Functor Ranged, Foldable Ranged) =>
(forall (f :: * -> *) a b.
 Applicative f =>
 (a -> f b) -> Ranged a -> f (Ranged b))
-> (forall (f :: * -> *) a.
    Applicative f =>
    Ranged (f a) -> f (Ranged a))
-> (forall (m :: * -> *) a b.
    Monad m =>
    (a -> m b) -> Ranged a -> m (Ranged b))
-> (forall (m :: * -> *) a.
    Monad m =>
    Ranged (m a) -> m (Ranged a))
-> Traversable Ranged
forall (t :: * -> *).
(Functor t, Foldable t) =>
(forall (f :: * -> *) a b.
 Applicative f =>
 (a -> f b) -> t a -> f (t b))
-> (forall (f :: * -> *) a. Applicative f => t (f a) -> f (t a))
-> (forall (m :: * -> *) a b.
    Monad m =>
    (a -> m b) -> t a -> m (t b))
-> (forall (m :: * -> *) a. Monad m => t (m a) -> m (t a))
-> Traversable t
forall (m :: * -> *) a. Monad m => Ranged (m a) -> m (Ranged a)
forall (f :: * -> *) a.
Applicative f =>
Ranged (f a) -> f (Ranged a)
forall (m :: * -> *) a b.
Monad m =>
(a -> m b) -> Ranged a -> m (Ranged b)
forall (f :: * -> *) a b.
Applicative f =>
(a -> f b) -> Ranged a -> f (Ranged b)
$ctraverse :: forall (f :: * -> *) a b.
Applicative f =>
(a -> f b) -> Ranged a -> f (Ranged b)
traverse :: forall (f :: * -> *) a b.
Applicative f =>
(a -> f b) -> Ranged a -> f (Ranged b)
$csequenceA :: forall (f :: * -> *) a.
Applicative f =>
Ranged (f a) -> f (Ranged a)
sequenceA :: forall (f :: * -> *) a.
Applicative f =>
Ranged (f a) -> f (Ranged a)
$cmapM :: forall (m :: * -> *) a b.
Monad m =>
(a -> m b) -> Ranged a -> m (Ranged b)
mapM :: forall (m :: * -> *) a b.
Monad m =>
(a -> m b) -> Ranged a -> m (Ranged b)
$csequence :: forall (m :: * -> *) a. Monad m => Ranged (m a) -> m (Ranged a)
sequence :: forall (m :: * -> *) a. Monad m => Ranged (m a) -> m (Ranged a)
Traversable)

-- | Thing with no range info.
unranged :: a -> Ranged a
unranged :: forall a. a -> Ranged a
unranged = Range -> a -> Ranged a
forall a. Range -> a -> Ranged a
Ranged Range
forall a. Range' a
noRange

-- | Ignores range.
instance Pretty a => Pretty (Ranged a) where
  pretty :: Ranged a -> Doc
pretty = a -> Doc
forall a. Pretty a => a -> Doc
pretty (a -> Doc) -> (Ranged a -> a) -> Ranged a -> Doc
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Ranged a -> a
forall a. Ranged a -> a
rangedThing

-- | Ignores range.
instance Eq a => Eq (Ranged a) where
  == :: Ranged a -> Ranged a -> Bool
(==) = a -> a -> Bool
forall a. Eq a => a -> a -> Bool
(==) (a -> a -> Bool) -> (Ranged a -> a) -> Ranged a -> Ranged a -> Bool
forall b c a. (b -> b -> c) -> (a -> b) -> a -> a -> c
`on` Ranged a -> a
forall a. Ranged a -> a
rangedThing

-- | Ignores range.
instance Ord a => Ord (Ranged a) where
  compare :: Ranged a -> Ranged a -> Ordering
compare = a -> a -> Ordering
forall a. Ord a => a -> a -> Ordering
compare (a -> a -> Ordering)
-> (Ranged a -> a) -> Ranged a -> Ranged a -> Ordering
forall b c a. (b -> b -> c) -> (a -> b) -> a -> a -> c
`on` Ranged a -> a
forall a. Ranged a -> a
rangedThing

instance HasRange (Ranged a) where
  getRange :: Ranged a -> Range
getRange = Ranged a -> Range
forall a. Ranged a -> Range
rangeOf

instance KillRange (Ranged a) where
  killRange :: KillRangeT (Ranged a)
killRange (Ranged Range
_ a
x) = Range -> a -> Ranged a
forall a. Range -> a -> Ranged a
Ranged Range
forall a. Range' a
noRange a
x

instance Decoration Ranged where
  traverseF :: forall (m :: * -> *) a b.
Functor m =>
(a -> m b) -> Ranged a -> m (Ranged b)
traverseF a -> m b
f (Ranged Range
r a
x) = Range -> b -> Ranged b
forall a. Range -> a -> Ranged a
Ranged Range
r (b -> Ranged b) -> m b -> m (Ranged b)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> a -> m b
f a
x

-- | Ranges are not forced.

instance NFData a => NFData (Ranged a) where
  rnf :: Ranged a -> ()
rnf (Ranged Range
_ a
a) = a -> ()
forall a. NFData a => a -> ()
rnf a
a

---------------------------------------------------------------------------
-- * Raw names (before parsing into name parts).
---------------------------------------------------------------------------

-- | A @RawName@ is some sort of string.
type RawName = String

rawNameToString :: RawName -> String
rawNameToString :: ShowS
rawNameToString = ShowS
forall a. a -> a
id

stringToRawName :: String -> RawName
stringToRawName :: ShowS
stringToRawName = ShowS
forall a. a -> a
id

-- | String with range info.
type RString = Ranged RawName

---------------------------------------------------------------------------
-- * Further constructor and projection info
---------------------------------------------------------------------------

-- | Where does the 'ConP' or 'Con' come from?
data ConOrigin
  = ConOSystem  -- ^ Inserted by system or expanded from an implicit pattern.
  | ConOCon     -- ^ User wrote a constructor (pattern).
  | ConORec     -- ^ User wrote a record (pattern).
  | ConOSplit   -- ^ Generated by interactive case splitting.
  deriving (Int -> ConOrigin -> ShowS
[ConOrigin] -> ShowS
ConOrigin -> ArgName
(Int -> ConOrigin -> ShowS)
-> (ConOrigin -> ArgName)
-> ([ConOrigin] -> ShowS)
-> Show ConOrigin
forall a.
(Int -> a -> ShowS) -> (a -> ArgName) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> ConOrigin -> ShowS
showsPrec :: Int -> ConOrigin -> ShowS
$cshow :: ConOrigin -> ArgName
show :: ConOrigin -> ArgName
$cshowList :: [ConOrigin] -> ShowS
showList :: [ConOrigin] -> ShowS
Show, ConOrigin -> ConOrigin -> Bool
(ConOrigin -> ConOrigin -> Bool)
-> (ConOrigin -> ConOrigin -> Bool) -> Eq ConOrigin
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: ConOrigin -> ConOrigin -> Bool
== :: ConOrigin -> ConOrigin -> Bool
$c/= :: ConOrigin -> ConOrigin -> Bool
/= :: ConOrigin -> ConOrigin -> Bool
Eq, Eq ConOrigin
Eq ConOrigin =>
(ConOrigin -> ConOrigin -> Ordering)
-> (ConOrigin -> ConOrigin -> Bool)
-> (ConOrigin -> ConOrigin -> Bool)
-> (ConOrigin -> ConOrigin -> Bool)
-> (ConOrigin -> ConOrigin -> Bool)
-> (ConOrigin -> ConOrigin -> ConOrigin)
-> (ConOrigin -> ConOrigin -> ConOrigin)
-> Ord ConOrigin
ConOrigin -> ConOrigin -> Bool
ConOrigin -> ConOrigin -> Ordering
ConOrigin -> ConOrigin -> ConOrigin
forall a.
Eq a =>
(a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
$ccompare :: ConOrigin -> ConOrigin -> Ordering
compare :: ConOrigin -> ConOrigin -> Ordering
$c< :: ConOrigin -> ConOrigin -> Bool
< :: ConOrigin -> ConOrigin -> Bool
$c<= :: ConOrigin -> ConOrigin -> Bool
<= :: ConOrigin -> ConOrigin -> Bool
$c> :: ConOrigin -> ConOrigin -> Bool
> :: ConOrigin -> ConOrigin -> Bool
$c>= :: ConOrigin -> ConOrigin -> Bool
>= :: ConOrigin -> ConOrigin -> Bool
$cmax :: ConOrigin -> ConOrigin -> ConOrigin
max :: ConOrigin -> ConOrigin -> ConOrigin
$cmin :: ConOrigin -> ConOrigin -> ConOrigin
min :: ConOrigin -> ConOrigin -> ConOrigin
Ord, Int -> ConOrigin
ConOrigin -> Int
ConOrigin -> [ConOrigin]
ConOrigin -> ConOrigin
ConOrigin -> ConOrigin -> [ConOrigin]
ConOrigin -> ConOrigin -> ConOrigin -> [ConOrigin]
(ConOrigin -> ConOrigin)
-> (ConOrigin -> ConOrigin)
-> (Int -> ConOrigin)
-> (ConOrigin -> Int)
-> (ConOrigin -> [ConOrigin])
-> (ConOrigin -> ConOrigin -> [ConOrigin])
-> (ConOrigin -> ConOrigin -> [ConOrigin])
-> (ConOrigin -> ConOrigin -> ConOrigin -> [ConOrigin])
-> Enum ConOrigin
forall a.
(a -> a)
-> (a -> a)
-> (Int -> a)
-> (a -> Int)
-> (a -> [a])
-> (a -> a -> [a])
-> (a -> a -> [a])
-> (a -> a -> a -> [a])
-> Enum a
$csucc :: ConOrigin -> ConOrigin
succ :: ConOrigin -> ConOrigin
$cpred :: ConOrigin -> ConOrigin
pred :: ConOrigin -> ConOrigin
$ctoEnum :: Int -> ConOrigin
toEnum :: Int -> ConOrigin
$cfromEnum :: ConOrigin -> Int
fromEnum :: ConOrigin -> Int
$cenumFrom :: ConOrigin -> [ConOrigin]
enumFrom :: ConOrigin -> [ConOrigin]
$cenumFromThen :: ConOrigin -> ConOrigin -> [ConOrigin]
enumFromThen :: ConOrigin -> ConOrigin -> [ConOrigin]
$cenumFromTo :: ConOrigin -> ConOrigin -> [ConOrigin]
enumFromTo :: ConOrigin -> ConOrigin -> [ConOrigin]
$cenumFromThenTo :: ConOrigin -> ConOrigin -> ConOrigin -> [ConOrigin]
enumFromThenTo :: ConOrigin -> ConOrigin -> ConOrigin -> [ConOrigin]
Enum, ConOrigin
ConOrigin -> ConOrigin -> Bounded ConOrigin
forall a. a -> a -> Bounded a
$cminBound :: ConOrigin
minBound :: ConOrigin
$cmaxBound :: ConOrigin
maxBound :: ConOrigin
Bounded, (forall x. ConOrigin -> Rep ConOrigin x)
-> (forall x. Rep ConOrigin x -> ConOrigin) -> Generic ConOrigin
forall x. Rep ConOrigin x -> ConOrigin
forall x. ConOrigin -> Rep ConOrigin x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cfrom :: forall x. ConOrigin -> Rep ConOrigin x
from :: forall x. ConOrigin -> Rep ConOrigin x
$cto :: forall x. Rep ConOrigin x -> ConOrigin
to :: forall x. Rep ConOrigin x -> ConOrigin
Generic)

instance NFData ConOrigin

instance KillRange ConOrigin where
  killRange :: ConOrigin -> ConOrigin
killRange = ConOrigin -> ConOrigin
forall a. a -> a
id

-- | Prefer user-written over system-inserted.
bestConInfo :: ConOrigin -> ConOrigin -> ConOrigin
bestConInfo :: ConOrigin -> ConOrigin -> ConOrigin
bestConInfo ConOrigin
ConOSystem ConOrigin
o = ConOrigin
o
bestConInfo ConOrigin
o ConOrigin
_ = ConOrigin
o

-- | Where does a projection come from?
data ProjOrigin
  = ProjPrefix    -- ^ User wrote a prefix projection.
  | ProjPostfix   -- ^ User wrote a postfix projection.
  | ProjSystem    -- ^ Projection was generated by the system.
  deriving (Int -> ProjOrigin -> ShowS
[ProjOrigin] -> ShowS
ProjOrigin -> ArgName
(Int -> ProjOrigin -> ShowS)
-> (ProjOrigin -> ArgName)
-> ([ProjOrigin] -> ShowS)
-> Show ProjOrigin
forall a.
(Int -> a -> ShowS) -> (a -> ArgName) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> ProjOrigin -> ShowS
showsPrec :: Int -> ProjOrigin -> ShowS
$cshow :: ProjOrigin -> ArgName
show :: ProjOrigin -> ArgName
$cshowList :: [ProjOrigin] -> ShowS
showList :: [ProjOrigin] -> ShowS
Show, ProjOrigin -> ProjOrigin -> Bool
(ProjOrigin -> ProjOrigin -> Bool)
-> (ProjOrigin -> ProjOrigin -> Bool) -> Eq ProjOrigin
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: ProjOrigin -> ProjOrigin -> Bool
== :: ProjOrigin -> ProjOrigin -> Bool
$c/= :: ProjOrigin -> ProjOrigin -> Bool
/= :: ProjOrigin -> ProjOrigin -> Bool
Eq, Eq ProjOrigin
Eq ProjOrigin =>
(ProjOrigin -> ProjOrigin -> Ordering)
-> (ProjOrigin -> ProjOrigin -> Bool)
-> (ProjOrigin -> ProjOrigin -> Bool)
-> (ProjOrigin -> ProjOrigin -> Bool)
-> (ProjOrigin -> ProjOrigin -> Bool)
-> (ProjOrigin -> ProjOrigin -> ProjOrigin)
-> (ProjOrigin -> ProjOrigin -> ProjOrigin)
-> Ord ProjOrigin
ProjOrigin -> ProjOrigin -> Bool
ProjOrigin -> ProjOrigin -> Ordering
ProjOrigin -> ProjOrigin -> ProjOrigin
forall a.
Eq a =>
(a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
$ccompare :: ProjOrigin -> ProjOrigin -> Ordering
compare :: ProjOrigin -> ProjOrigin -> Ordering
$c< :: ProjOrigin -> ProjOrigin -> Bool
< :: ProjOrigin -> ProjOrigin -> Bool
$c<= :: ProjOrigin -> ProjOrigin -> Bool
<= :: ProjOrigin -> ProjOrigin -> Bool
$c> :: ProjOrigin -> ProjOrigin -> Bool
> :: ProjOrigin -> ProjOrigin -> Bool
$c>= :: ProjOrigin -> ProjOrigin -> Bool
>= :: ProjOrigin -> ProjOrigin -> Bool
$cmax :: ProjOrigin -> ProjOrigin -> ProjOrigin
max :: ProjOrigin -> ProjOrigin -> ProjOrigin
$cmin :: ProjOrigin -> ProjOrigin -> ProjOrigin
min :: ProjOrigin -> ProjOrigin -> ProjOrigin
Ord, Int -> ProjOrigin
ProjOrigin -> Int
ProjOrigin -> [ProjOrigin]
ProjOrigin -> ProjOrigin
ProjOrigin -> ProjOrigin -> [ProjOrigin]
ProjOrigin -> ProjOrigin -> ProjOrigin -> [ProjOrigin]
(ProjOrigin -> ProjOrigin)
-> (ProjOrigin -> ProjOrigin)
-> (Int -> ProjOrigin)
-> (ProjOrigin -> Int)
-> (ProjOrigin -> [ProjOrigin])
-> (ProjOrigin -> ProjOrigin -> [ProjOrigin])
-> (ProjOrigin -> ProjOrigin -> [ProjOrigin])
-> (ProjOrigin -> ProjOrigin -> ProjOrigin -> [ProjOrigin])
-> Enum ProjOrigin
forall a.
(a -> a)
-> (a -> a)
-> (Int -> a)
-> (a -> Int)
-> (a -> [a])
-> (a -> a -> [a])
-> (a -> a -> [a])
-> (a -> a -> a -> [a])
-> Enum a
$csucc :: ProjOrigin -> ProjOrigin
succ :: ProjOrigin -> ProjOrigin
$cpred :: ProjOrigin -> ProjOrigin
pred :: ProjOrigin -> ProjOrigin
$ctoEnum :: Int -> ProjOrigin
toEnum :: Int -> ProjOrigin
$cfromEnum :: ProjOrigin -> Int
fromEnum :: ProjOrigin -> Int
$cenumFrom :: ProjOrigin -> [ProjOrigin]
enumFrom :: ProjOrigin -> [ProjOrigin]
$cenumFromThen :: ProjOrigin -> ProjOrigin -> [ProjOrigin]
enumFromThen :: ProjOrigin -> ProjOrigin -> [ProjOrigin]
$cenumFromTo :: ProjOrigin -> ProjOrigin -> [ProjOrigin]
enumFromTo :: ProjOrigin -> ProjOrigin -> [ProjOrigin]
$cenumFromThenTo :: ProjOrigin -> ProjOrigin -> ProjOrigin -> [ProjOrigin]
enumFromThenTo :: ProjOrigin -> ProjOrigin -> ProjOrigin -> [ProjOrigin]
Enum, ProjOrigin
ProjOrigin -> ProjOrigin -> Bounded ProjOrigin
forall a. a -> a -> Bounded a
$cminBound :: ProjOrigin
minBound :: ProjOrigin
$cmaxBound :: ProjOrigin
maxBound :: ProjOrigin
Bounded, (forall x. ProjOrigin -> Rep ProjOrigin x)
-> (forall x. Rep ProjOrigin x -> ProjOrigin) -> Generic ProjOrigin
forall x. Rep ProjOrigin x -> ProjOrigin
forall x. ProjOrigin -> Rep ProjOrigin x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cfrom :: forall x. ProjOrigin -> Rep ProjOrigin x
from :: forall x. ProjOrigin -> Rep ProjOrigin x
$cto :: forall x. Rep ProjOrigin x -> ProjOrigin
to :: forall x. Rep ProjOrigin x -> ProjOrigin
Generic)

instance NFData ProjOrigin

instance KillRange ProjOrigin where
  killRange :: ProjOrigin -> ProjOrigin
killRange = ProjOrigin -> ProjOrigin
forall a. a -> a
id

---------------------------------------------------------------------------
-- * Infixity, access, abstract, etc.
---------------------------------------------------------------------------

-- | Functions can be defined in both infix and prefix style. See
--   'Agda.Syntax.Concrete.LHS'.
data IsInfix = InfixDef | PrefixDef
    deriving (Int -> IsInfix -> ShowS
[IsInfix] -> ShowS
IsInfix -> ArgName
(Int -> IsInfix -> ShowS)
-> (IsInfix -> ArgName) -> ([IsInfix] -> ShowS) -> Show IsInfix
forall a.
(Int -> a -> ShowS) -> (a -> ArgName) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> IsInfix -> ShowS
showsPrec :: Int -> IsInfix -> ShowS
$cshow :: IsInfix -> ArgName
show :: IsInfix -> ArgName
$cshowList :: [IsInfix] -> ShowS
showList :: [IsInfix] -> ShowS
Show, IsInfix -> IsInfix -> Bool
(IsInfix -> IsInfix -> Bool)
-> (IsInfix -> IsInfix -> Bool) -> Eq IsInfix
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: IsInfix -> IsInfix -> Bool
== :: IsInfix -> IsInfix -> Bool
$c/= :: IsInfix -> IsInfix -> Bool
/= :: IsInfix -> IsInfix -> Bool
Eq, Eq IsInfix
Eq IsInfix =>
(IsInfix -> IsInfix -> Ordering)
-> (IsInfix -> IsInfix -> Bool)
-> (IsInfix -> IsInfix -> Bool)
-> (IsInfix -> IsInfix -> Bool)
-> (IsInfix -> IsInfix -> Bool)
-> (IsInfix -> IsInfix -> IsInfix)
-> (IsInfix -> IsInfix -> IsInfix)
-> Ord IsInfix
IsInfix -> IsInfix -> Bool
IsInfix -> IsInfix -> Ordering
IsInfix -> IsInfix -> IsInfix
forall a.
Eq a =>
(a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
$ccompare :: IsInfix -> IsInfix -> Ordering
compare :: IsInfix -> IsInfix -> Ordering
$c< :: IsInfix -> IsInfix -> Bool
< :: IsInfix -> IsInfix -> Bool
$c<= :: IsInfix -> IsInfix -> Bool
<= :: IsInfix -> IsInfix -> Bool
$c> :: IsInfix -> IsInfix -> Bool
> :: IsInfix -> IsInfix -> Bool
$c>= :: IsInfix -> IsInfix -> Bool
>= :: IsInfix -> IsInfix -> Bool
$cmax :: IsInfix -> IsInfix -> IsInfix
max :: IsInfix -> IsInfix -> IsInfix
$cmin :: IsInfix -> IsInfix -> IsInfix
min :: IsInfix -> IsInfix -> IsInfix
Ord)

-- ** private blocks, public imports

-- | Access modifier.
data Access
  = PrivateAccess Origin
      -- ^ Store the 'Origin' of the private block that lead to this qualifier.
      --   This is needed for more faithful printing of declarations.
  | PublicAccess
    deriving (Int -> Access -> ShowS
[Access] -> ShowS
Access -> ArgName
(Int -> Access -> ShowS)
-> (Access -> ArgName) -> ([Access] -> ShowS) -> Show Access
forall a.
(Int -> a -> ShowS) -> (a -> ArgName) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> Access -> ShowS
showsPrec :: Int -> Access -> ShowS
$cshow :: Access -> ArgName
show :: Access -> ArgName
$cshowList :: [Access] -> ShowS
showList :: [Access] -> ShowS
Show, Access -> Access -> Bool
(Access -> Access -> Bool)
-> (Access -> Access -> Bool) -> Eq Access
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: Access -> Access -> Bool
== :: Access -> Access -> Bool
$c/= :: Access -> Access -> Bool
/= :: Access -> Access -> Bool
Eq, Eq Access
Eq Access =>
(Access -> Access -> Ordering)
-> (Access -> Access -> Bool)
-> (Access -> Access -> Bool)
-> (Access -> Access -> Bool)
-> (Access -> Access -> Bool)
-> (Access -> Access -> Access)
-> (Access -> Access -> Access)
-> Ord Access
Access -> Access -> Bool
Access -> Access -> Ordering
Access -> Access -> Access
forall a.
Eq a =>
(a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
$ccompare :: Access -> Access -> Ordering
compare :: Access -> Access -> Ordering
$c< :: Access -> Access -> Bool
< :: Access -> Access -> Bool
$c<= :: Access -> Access -> Bool
<= :: Access -> Access -> Bool
$c> :: Access -> Access -> Bool
> :: Access -> Access -> Bool
$c>= :: Access -> Access -> Bool
>= :: Access -> Access -> Bool
$cmax :: Access -> Access -> Access
max :: Access -> Access -> Access
$cmin :: Access -> Access -> Access
min :: Access -> Access -> Access
Ord)

instance Pretty Access where
  pretty :: Access -> Doc
pretty = ArgName -> Doc
forall a. ArgName -> Doc a
text (ArgName -> Doc) -> (Access -> ArgName) -> Access -> Doc
forall b c a. (b -> c) -> (a -> b) -> a -> c
. \case
    PrivateAccess Origin
_ -> ArgName
"private"
    Access
PublicAccess    -> ArgName
"public"

instance NFData Access where
  rnf :: Access -> ()
rnf Access
_ = ()

instance HasRange Access where
  getRange :: Access -> Range
getRange Access
_ = Range
forall a. Range' a
noRange

instance KillRange Access where
  killRange :: Access -> Access
killRange = Access -> Access
forall a. a -> a
id

-- ** abstract blocks

-- | Abstract or concrete.
data IsAbstract = AbstractDef | ConcreteDef
    deriving (Int -> IsAbstract -> ShowS
[IsAbstract] -> ShowS
IsAbstract -> ArgName
(Int -> IsAbstract -> ShowS)
-> (IsAbstract -> ArgName)
-> ([IsAbstract] -> ShowS)
-> Show IsAbstract
forall a.
(Int -> a -> ShowS) -> (a -> ArgName) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> IsAbstract -> ShowS
showsPrec :: Int -> IsAbstract -> ShowS
$cshow :: IsAbstract -> ArgName
show :: IsAbstract -> ArgName
$cshowList :: [IsAbstract] -> ShowS
showList :: [IsAbstract] -> ShowS
Show, IsAbstract -> IsAbstract -> Bool
(IsAbstract -> IsAbstract -> Bool)
-> (IsAbstract -> IsAbstract -> Bool) -> Eq IsAbstract
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: IsAbstract -> IsAbstract -> Bool
== :: IsAbstract -> IsAbstract -> Bool
$c/= :: IsAbstract -> IsAbstract -> Bool
/= :: IsAbstract -> IsAbstract -> Bool
Eq, Eq IsAbstract
Eq IsAbstract =>
(IsAbstract -> IsAbstract -> Ordering)
-> (IsAbstract -> IsAbstract -> Bool)
-> (IsAbstract -> IsAbstract -> Bool)
-> (IsAbstract -> IsAbstract -> Bool)
-> (IsAbstract -> IsAbstract -> Bool)
-> (IsAbstract -> IsAbstract -> IsAbstract)
-> (IsAbstract -> IsAbstract -> IsAbstract)
-> Ord IsAbstract
IsAbstract -> IsAbstract -> Bool
IsAbstract -> IsAbstract -> Ordering
IsAbstract -> IsAbstract -> IsAbstract
forall a.
Eq a =>
(a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
$ccompare :: IsAbstract -> IsAbstract -> Ordering
compare :: IsAbstract -> IsAbstract -> Ordering
$c< :: IsAbstract -> IsAbstract -> Bool
< :: IsAbstract -> IsAbstract -> Bool
$c<= :: IsAbstract -> IsAbstract -> Bool
<= :: IsAbstract -> IsAbstract -> Bool
$c> :: IsAbstract -> IsAbstract -> Bool
> :: IsAbstract -> IsAbstract -> Bool
$c>= :: IsAbstract -> IsAbstract -> Bool
>= :: IsAbstract -> IsAbstract -> Bool
$cmax :: IsAbstract -> IsAbstract -> IsAbstract
max :: IsAbstract -> IsAbstract -> IsAbstract
$cmin :: IsAbstract -> IsAbstract -> IsAbstract
min :: IsAbstract -> IsAbstract -> IsAbstract
Ord, (forall x. IsAbstract -> Rep IsAbstract x)
-> (forall x. Rep IsAbstract x -> IsAbstract) -> Generic IsAbstract
forall x. Rep IsAbstract x -> IsAbstract
forall x. IsAbstract -> Rep IsAbstract x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cfrom :: forall x. IsAbstract -> Rep IsAbstract x
from :: forall x. IsAbstract -> Rep IsAbstract x
$cto :: forall x. Rep IsAbstract x -> IsAbstract
to :: forall x. Rep IsAbstract x -> IsAbstract
Generic)

-- | Semigroup computes if any of several is an 'AbstractDef'.
instance Semigroup IsAbstract where
  IsAbstract
AbstractDef <> :: IsAbstract -> IsAbstract -> IsAbstract
<> IsAbstract
_ = IsAbstract
AbstractDef
  IsAbstract
ConcreteDef <> IsAbstract
a = IsAbstract
a

-- | Default is 'ConcreteDef'.
instance Monoid IsAbstract where
  mempty :: IsAbstract
mempty  = IsAbstract
ConcreteDef
  mappend :: IsAbstract -> IsAbstract -> IsAbstract
mappend = IsAbstract -> IsAbstract -> IsAbstract
forall a. Semigroup a => a -> a -> a
(<>)

instance KillRange IsAbstract where
  killRange :: IsAbstract -> IsAbstract
killRange = IsAbstract -> IsAbstract
forall a. a -> a
id

instance NFData IsAbstract

class LensIsAbstract a where
  lensIsAbstract :: Lens' a IsAbstract

instance LensIsAbstract IsAbstract where
  lensIsAbstract :: Lens' IsAbstract IsAbstract
lensIsAbstract = (IsAbstract -> f IsAbstract) -> IsAbstract -> f IsAbstract
forall a. a -> a
id

-- | Is any element of a collection an 'AbstractDef'.
class AnyIsAbstract a where
  anyIsAbstract :: a -> IsAbstract

  default anyIsAbstract :: (Foldable t, AnyIsAbstract b, t b ~ a) => a -> IsAbstract
  anyIsAbstract = (b -> IsAbstract) -> t b -> IsAbstract
forall m a. Monoid m => (a -> m) -> t a -> m
forall (t :: * -> *) m a.
(Foldable t, Monoid m) =>
(a -> m) -> t a -> m
Fold.foldMap b -> IsAbstract
forall a. AnyIsAbstract a => a -> IsAbstract
anyIsAbstract

instance AnyIsAbstract IsAbstract where
  anyIsAbstract :: IsAbstract -> IsAbstract
anyIsAbstract = IsAbstract -> IsAbstract
forall a. a -> a
id

instance AnyIsAbstract a => AnyIsAbstract [a] where
instance AnyIsAbstract a => AnyIsAbstract (Maybe a) where

-- ** instance blocks

-- | Is this definition eligible for instance search?
data IsInstance
  = InstanceDef Range  -- ^ Range of the @instance@ keyword.
  | NotInstanceDef
    deriving (Int -> IsInstance -> ShowS
[IsInstance] -> ShowS
IsInstance -> ArgName
(Int -> IsInstance -> ShowS)
-> (IsInstance -> ArgName)
-> ([IsInstance] -> ShowS)
-> Show IsInstance
forall a.
(Int -> a -> ShowS) -> (a -> ArgName) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> IsInstance -> ShowS
showsPrec :: Int -> IsInstance -> ShowS
$cshow :: IsInstance -> ArgName
show :: IsInstance -> ArgName
$cshowList :: [IsInstance] -> ShowS
showList :: [IsInstance] -> ShowS
Show, IsInstance -> IsInstance -> Bool
(IsInstance -> IsInstance -> Bool)
-> (IsInstance -> IsInstance -> Bool) -> Eq IsInstance
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: IsInstance -> IsInstance -> Bool
== :: IsInstance -> IsInstance -> Bool
$c/= :: IsInstance -> IsInstance -> Bool
/= :: IsInstance -> IsInstance -> Bool
Eq, Eq IsInstance
Eq IsInstance =>
(IsInstance -> IsInstance -> Ordering)
-> (IsInstance -> IsInstance -> Bool)
-> (IsInstance -> IsInstance -> Bool)
-> (IsInstance -> IsInstance -> Bool)
-> (IsInstance -> IsInstance -> Bool)
-> (IsInstance -> IsInstance -> IsInstance)
-> (IsInstance -> IsInstance -> IsInstance)
-> Ord IsInstance
IsInstance -> IsInstance -> Bool
IsInstance -> IsInstance -> Ordering
IsInstance -> IsInstance -> IsInstance
forall a.
Eq a =>
(a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
$ccompare :: IsInstance -> IsInstance -> Ordering
compare :: IsInstance -> IsInstance -> Ordering
$c< :: IsInstance -> IsInstance -> Bool
< :: IsInstance -> IsInstance -> Bool
$c<= :: IsInstance -> IsInstance -> Bool
<= :: IsInstance -> IsInstance -> Bool
$c> :: IsInstance -> IsInstance -> Bool
> :: IsInstance -> IsInstance -> Bool
$c>= :: IsInstance -> IsInstance -> Bool
>= :: IsInstance -> IsInstance -> Bool
$cmax :: IsInstance -> IsInstance -> IsInstance
max :: IsInstance -> IsInstance -> IsInstance
$cmin :: IsInstance -> IsInstance -> IsInstance
min :: IsInstance -> IsInstance -> IsInstance
Ord)

instance KillRange IsInstance where
  killRange :: IsInstance -> IsInstance
killRange = \case
    InstanceDef Range
_    -> Range -> IsInstance
InstanceDef Range
forall a. Range' a
noRange
    i :: IsInstance
i@IsInstance
NotInstanceDef -> IsInstance
i

instance HasRange IsInstance where
  getRange :: IsInstance -> Range
getRange = \case
    InstanceDef Range
r  -> Range
r
    IsInstance
NotInstanceDef -> Range
forall a. Range' a
noRange

instance NFData IsInstance where
  rnf :: IsInstance -> ()
rnf (InstanceDef Range
_) = ()
  rnf IsInstance
NotInstanceDef  = ()

-- ** macro blocks

-- | Is this a macro definition?
data IsMacro = MacroDef | NotMacroDef
  deriving (Int -> IsMacro -> ShowS
[IsMacro] -> ShowS
IsMacro -> ArgName
(Int -> IsMacro -> ShowS)
-> (IsMacro -> ArgName) -> ([IsMacro] -> ShowS) -> Show IsMacro
forall a.
(Int -> a -> ShowS) -> (a -> ArgName) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> IsMacro -> ShowS
showsPrec :: Int -> IsMacro -> ShowS
$cshow :: IsMacro -> ArgName
show :: IsMacro -> ArgName
$cshowList :: [IsMacro] -> ShowS
showList :: [IsMacro] -> ShowS
Show, IsMacro -> IsMacro -> Bool
(IsMacro -> IsMacro -> Bool)
-> (IsMacro -> IsMacro -> Bool) -> Eq IsMacro
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: IsMacro -> IsMacro -> Bool
== :: IsMacro -> IsMacro -> Bool
$c/= :: IsMacro -> IsMacro -> Bool
/= :: IsMacro -> IsMacro -> Bool
Eq, Eq IsMacro
Eq IsMacro =>
(IsMacro -> IsMacro -> Ordering)
-> (IsMacro -> IsMacro -> Bool)
-> (IsMacro -> IsMacro -> Bool)
-> (IsMacro -> IsMacro -> Bool)
-> (IsMacro -> IsMacro -> Bool)
-> (IsMacro -> IsMacro -> IsMacro)
-> (IsMacro -> IsMacro -> IsMacro)
-> Ord IsMacro
IsMacro -> IsMacro -> Bool
IsMacro -> IsMacro -> Ordering
IsMacro -> IsMacro -> IsMacro
forall a.
Eq a =>
(a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
$ccompare :: IsMacro -> IsMacro -> Ordering
compare :: IsMacro -> IsMacro -> Ordering
$c< :: IsMacro -> IsMacro -> Bool
< :: IsMacro -> IsMacro -> Bool
$c<= :: IsMacro -> IsMacro -> Bool
<= :: IsMacro -> IsMacro -> Bool
$c> :: IsMacro -> IsMacro -> Bool
> :: IsMacro -> IsMacro -> Bool
$c>= :: IsMacro -> IsMacro -> Bool
>= :: IsMacro -> IsMacro -> Bool
$cmax :: IsMacro -> IsMacro -> IsMacro
max :: IsMacro -> IsMacro -> IsMacro
$cmin :: IsMacro -> IsMacro -> IsMacro
min :: IsMacro -> IsMacro -> IsMacro
Ord, (forall x. IsMacro -> Rep IsMacro x)
-> (forall x. Rep IsMacro x -> IsMacro) -> Generic IsMacro
forall x. Rep IsMacro x -> IsMacro
forall x. IsMacro -> Rep IsMacro x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cfrom :: forall x. IsMacro -> Rep IsMacro x
from :: forall x. IsMacro -> Rep IsMacro x
$cto :: forall x. Rep IsMacro x -> IsMacro
to :: forall x. Rep IsMacro x -> IsMacro
Generic)

instance KillRange IsMacro where killRange :: IsMacro -> IsMacro
killRange = IsMacro -> IsMacro
forall a. a -> a
id
instance HasRange  IsMacro where getRange :: IsMacro -> Range
getRange IsMacro
_ = Range
forall a. Range' a
noRange

instance NFData IsMacro

-- ** opaque blocks

-- | Opaque or transparent.
data IsOpaque
  = OpaqueDef {-# UNPACK #-} !OpaqueId
    -- ^ This definition is opaque, and it is guarded by the given
    -- opaque block.
  | TransparentDef
  deriving (Int -> IsOpaque -> ShowS
[IsOpaque] -> ShowS
IsOpaque -> ArgName
(Int -> IsOpaque -> ShowS)
-> (IsOpaque -> ArgName) -> ([IsOpaque] -> ShowS) -> Show IsOpaque
forall a.
(Int -> a -> ShowS) -> (a -> ArgName) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> IsOpaque -> ShowS
showsPrec :: Int -> IsOpaque -> ShowS
$cshow :: IsOpaque -> ArgName
show :: IsOpaque -> ArgName
$cshowList :: [IsOpaque] -> ShowS
showList :: [IsOpaque] -> ShowS
Show, IsOpaque -> IsOpaque -> Bool
(IsOpaque -> IsOpaque -> Bool)
-> (IsOpaque -> IsOpaque -> Bool) -> Eq IsOpaque
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: IsOpaque -> IsOpaque -> Bool
== :: IsOpaque -> IsOpaque -> Bool
$c/= :: IsOpaque -> IsOpaque -> Bool
/= :: IsOpaque -> IsOpaque -> Bool
Eq, Eq IsOpaque
Eq IsOpaque =>
(IsOpaque -> IsOpaque -> Ordering)
-> (IsOpaque -> IsOpaque -> Bool)
-> (IsOpaque -> IsOpaque -> Bool)
-> (IsOpaque -> IsOpaque -> Bool)
-> (IsOpaque -> IsOpaque -> Bool)
-> (IsOpaque -> IsOpaque -> IsOpaque)
-> (IsOpaque -> IsOpaque -> IsOpaque)
-> Ord IsOpaque
IsOpaque -> IsOpaque -> Bool
IsOpaque -> IsOpaque -> Ordering
IsOpaque -> IsOpaque -> IsOpaque
forall a.
Eq a =>
(a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
$ccompare :: IsOpaque -> IsOpaque -> Ordering
compare :: IsOpaque -> IsOpaque -> Ordering
$c< :: IsOpaque -> IsOpaque -> Bool
< :: IsOpaque -> IsOpaque -> Bool
$c<= :: IsOpaque -> IsOpaque -> Bool
<= :: IsOpaque -> IsOpaque -> Bool
$c> :: IsOpaque -> IsOpaque -> Bool
> :: IsOpaque -> IsOpaque -> Bool
$c>= :: IsOpaque -> IsOpaque -> Bool
>= :: IsOpaque -> IsOpaque -> Bool
$cmax :: IsOpaque -> IsOpaque -> IsOpaque
max :: IsOpaque -> IsOpaque -> IsOpaque
$cmin :: IsOpaque -> IsOpaque -> IsOpaque
min :: IsOpaque -> IsOpaque -> IsOpaque
Ord, (forall x. IsOpaque -> Rep IsOpaque x)
-> (forall x. Rep IsOpaque x -> IsOpaque) -> Generic IsOpaque
forall x. Rep IsOpaque x -> IsOpaque
forall x. IsOpaque -> Rep IsOpaque x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cfrom :: forall x. IsOpaque -> Rep IsOpaque x
from :: forall x. IsOpaque -> Rep IsOpaque x
$cto :: forall x. Rep IsOpaque x -> IsOpaque
to :: forall x. Rep IsOpaque x -> IsOpaque
Generic)

instance KillRange IsOpaque where
  killRange :: IsOpaque -> IsOpaque
killRange = IsOpaque -> IsOpaque
forall a. a -> a
id

instance NFData IsOpaque

class LensIsOpaque a where
  lensIsOpaque :: Lens' a IsOpaque

instance LensIsOpaque IsOpaque where
  lensIsOpaque :: Lens' IsOpaque IsOpaque
lensIsOpaque = (IsOpaque -> f IsOpaque) -> IsOpaque -> f IsOpaque
forall a. a -> a
id

-- | Monoid representing the combined opaque blocks of a 'Foldable'
-- containing possibly-opaque declarations.
data JointOpacity
  = UniqueOpaque    {-# UNPACK #-} !OpaqueId
  -- ^ Every definition agrees on what opaque block they belong to.
  | DifferentOpaque !(HashSet OpaqueId)
  -- ^ More than one opaque block was found.
  | NoOpaque
  -- ^ Nothing here is opaque.

instance Semigroup JointOpacity where
  UniqueOpaque OpaqueId
i <> :: JointOpacity -> JointOpacity -> JointOpacity
<> UniqueOpaque OpaqueId
j
    | OpaqueId
i OpaqueId -> OpaqueId -> Bool
forall a. Eq a => a -> a -> Bool
== OpaqueId
j    = OpaqueId -> JointOpacity
UniqueOpaque OpaqueId
i
    | Bool
otherwise = HashSet OpaqueId -> JointOpacity
DifferentOpaque ([OpaqueId] -> HashSet OpaqueId
forall a. (Eq a, Hashable a) => [a] -> HashSet a
HashSet.fromList [OpaqueId
i, OpaqueId
j])

  DifferentOpaque HashSet OpaqueId
is <> UniqueOpaque OpaqueId
j     = HashSet OpaqueId -> JointOpacity
DifferentOpaque (OpaqueId -> HashSet OpaqueId -> HashSet OpaqueId
forall a. (Eq a, Hashable a) => a -> HashSet a -> HashSet a
HashSet.insert OpaqueId
j HashSet OpaqueId
is)
  UniqueOpaque OpaqueId
i     <> DifferentOpaque HashSet OpaqueId
js = HashSet OpaqueId -> JointOpacity
DifferentOpaque (OpaqueId -> HashSet OpaqueId -> HashSet OpaqueId
forall a. (Eq a, Hashable a) => a -> HashSet a -> HashSet a
HashSet.insert OpaqueId
i HashSet OpaqueId
js)
  DifferentOpaque HashSet OpaqueId
is <> DifferentOpaque HashSet OpaqueId
js = HashSet OpaqueId -> JointOpacity
DifferentOpaque (HashSet OpaqueId -> HashSet OpaqueId -> HashSet OpaqueId
forall a. (Eq a, Hashable a) => HashSet a -> HashSet a -> HashSet a
HashSet.union HashSet OpaqueId
is HashSet OpaqueId
js)

  JointOpacity
NoOpaque <> JointOpacity
x = JointOpacity
x
  JointOpacity
x <> JointOpacity
NoOpaque = JointOpacity
x

instance Monoid JointOpacity where
  mappend :: JointOpacity -> JointOpacity -> JointOpacity
mappend = JointOpacity -> JointOpacity -> JointOpacity
forall a. Semigroup a => a -> a -> a
(<>)
  mempty :: JointOpacity
mempty = JointOpacity
NoOpaque

class AllAreOpaque a where
  jointOpacity :: a -> JointOpacity

  default jointOpacity :: (Foldable t, AllAreOpaque b, t b ~ a) => a -> JointOpacity
  jointOpacity = (b -> JointOpacity) -> t b -> JointOpacity
forall m a. Monoid m => (a -> m) -> t a -> m
forall (t :: * -> *) m a.
(Foldable t, Monoid m) =>
(a -> m) -> t a -> m
Fold.foldMap b -> JointOpacity
forall a. AllAreOpaque a => a -> JointOpacity
jointOpacity

instance AllAreOpaque IsOpaque where
  jointOpacity :: IsOpaque -> JointOpacity
jointOpacity = \case
    IsOpaque
TransparentDef -> JointOpacity
NoOpaque
    OpaqueDef OpaqueId
i    -> OpaqueId -> JointOpacity
UniqueOpaque OpaqueId
i

instance AllAreOpaque a => AllAreOpaque [a] where
instance AllAreOpaque a => AllAreOpaque (Maybe a) where

---------------------------------------------------------------------------
-- * NameId
---------------------------------------------------------------------------

newtype ModuleNameHash = ModuleNameHash { ModuleNameHash -> Word64
moduleNameHash :: Word64 }
  deriving (ModuleNameHash -> ModuleNameHash -> Bool
(ModuleNameHash -> ModuleNameHash -> Bool)
-> (ModuleNameHash -> ModuleNameHash -> Bool) -> Eq ModuleNameHash
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: ModuleNameHash -> ModuleNameHash -> Bool
== :: ModuleNameHash -> ModuleNameHash -> Bool
$c/= :: ModuleNameHash -> ModuleNameHash -> Bool
/= :: ModuleNameHash -> ModuleNameHash -> Bool
Eq, Eq ModuleNameHash
Eq ModuleNameHash =>
(ModuleNameHash -> ModuleNameHash -> Ordering)
-> (ModuleNameHash -> ModuleNameHash -> Bool)
-> (ModuleNameHash -> ModuleNameHash -> Bool)
-> (ModuleNameHash -> ModuleNameHash -> Bool)
-> (ModuleNameHash -> ModuleNameHash -> Bool)
-> (ModuleNameHash -> ModuleNameHash -> ModuleNameHash)
-> (ModuleNameHash -> ModuleNameHash -> ModuleNameHash)
-> Ord ModuleNameHash
ModuleNameHash -> ModuleNameHash -> Bool
ModuleNameHash -> ModuleNameHash -> Ordering
ModuleNameHash -> ModuleNameHash -> ModuleNameHash
forall a.
Eq a =>
(a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
$ccompare :: ModuleNameHash -> ModuleNameHash -> Ordering
compare :: ModuleNameHash -> ModuleNameHash -> Ordering
$c< :: ModuleNameHash -> ModuleNameHash -> Bool
< :: ModuleNameHash -> ModuleNameHash -> Bool
$c<= :: ModuleNameHash -> ModuleNameHash -> Bool
<= :: ModuleNameHash -> ModuleNameHash -> Bool
$c> :: ModuleNameHash -> ModuleNameHash -> Bool
> :: ModuleNameHash -> ModuleNameHash -> Bool
$c>= :: ModuleNameHash -> ModuleNameHash -> Bool
>= :: ModuleNameHash -> ModuleNameHash -> Bool
$cmax :: ModuleNameHash -> ModuleNameHash -> ModuleNameHash
max :: ModuleNameHash -> ModuleNameHash -> ModuleNameHash
$cmin :: ModuleNameHash -> ModuleNameHash -> ModuleNameHash
min :: ModuleNameHash -> ModuleNameHash -> ModuleNameHash
Ord, Eq ModuleNameHash
Eq ModuleNameHash =>
(Int -> ModuleNameHash -> Int)
-> (ModuleNameHash -> Int) -> Hashable ModuleNameHash
Int -> ModuleNameHash -> Int
ModuleNameHash -> Int
forall a. Eq a => (Int -> a -> Int) -> (a -> Int) -> Hashable a
$chashWithSalt :: Int -> ModuleNameHash -> Int
hashWithSalt :: Int -> ModuleNameHash -> Int
$chash :: ModuleNameHash -> Int
hash :: ModuleNameHash -> Int
Hashable)

instance HasTag ModuleNameHash where
  type Tag ModuleNameHash = ModuleNameHash
  tag :: ModuleNameHash -> Maybe (Tag ModuleNameHash)
tag = ModuleNameHash -> Maybe ModuleNameHash
forall a. a -> Maybe a
Just (ModuleNameHash -> Maybe ModuleNameHash)
-> (ModuleNameHash -> ModuleNameHash)
-> ModuleNameHash
-> Maybe ModuleNameHash
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ModuleNameHash -> ModuleNameHash
forall a. a -> a
id

noModuleNameHash :: ModuleNameHash
noModuleNameHash :: ModuleNameHash
noModuleNameHash = Word64 -> ModuleNameHash
ModuleNameHash Word64
0

-- | The record selector is not included in the resulting strings.

instance Show ModuleNameHash where
  showsPrec :: Int -> ModuleNameHash -> ShowS
showsPrec Int
p (ModuleNameHash Word64
h) = Bool -> ShowS -> ShowS
showParen (Int
p Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
> Int
0) (ShowS -> ShowS) -> ShowS -> ShowS
forall a b. (a -> b) -> a -> b
$
    ArgName -> ShowS
showString ArgName
"ModuleNameHash " ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Word64 -> ShowS
forall a. Show a => a -> ShowS
shows Word64
h

-- | The unique identifier of a name. Second argument is the top-level module
--   identifier.
data NameId = NameId {-# UNPACK #-} !Word64 {-# UNPACK #-} !ModuleNameHash
    deriving (NameId -> NameId -> Bool
(NameId -> NameId -> Bool)
-> (NameId -> NameId -> Bool) -> Eq NameId
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: NameId -> NameId -> Bool
== :: NameId -> NameId -> Bool
$c/= :: NameId -> NameId -> Bool
/= :: NameId -> NameId -> Bool
Eq, Eq NameId
Eq NameId =>
(NameId -> NameId -> Ordering)
-> (NameId -> NameId -> Bool)
-> (NameId -> NameId -> Bool)
-> (NameId -> NameId -> Bool)
-> (NameId -> NameId -> Bool)
-> (NameId -> NameId -> NameId)
-> (NameId -> NameId -> NameId)
-> Ord NameId
NameId -> NameId -> Bool
NameId -> NameId -> Ordering
NameId -> NameId -> NameId
forall a.
Eq a =>
(a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
$ccompare :: NameId -> NameId -> Ordering
compare :: NameId -> NameId -> Ordering
$c< :: NameId -> NameId -> Bool
< :: NameId -> NameId -> Bool
$c<= :: NameId -> NameId -> Bool
<= :: NameId -> NameId -> Bool
$c> :: NameId -> NameId -> Bool
> :: NameId -> NameId -> Bool
$c>= :: NameId -> NameId -> Bool
>= :: NameId -> NameId -> Bool
$cmax :: NameId -> NameId -> NameId
max :: NameId -> NameId -> NameId
$cmin :: NameId -> NameId -> NameId
min :: NameId -> NameId -> NameId
Ord, (forall x. NameId -> Rep NameId x)
-> (forall x. Rep NameId x -> NameId) -> Generic NameId
forall x. Rep NameId x -> NameId
forall x. NameId -> Rep NameId x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cfrom :: forall x. NameId -> Rep NameId x
from :: forall x. NameId -> Rep NameId x
$cto :: forall x. Rep NameId x -> NameId
to :: forall x. Rep NameId x -> NameId
Generic, Int -> NameId -> ShowS
[NameId] -> ShowS
NameId -> ArgName
(Int -> NameId -> ShowS)
-> (NameId -> ArgName) -> ([NameId] -> ShowS) -> Show NameId
forall a.
(Int -> a -> ShowS) -> (a -> ArgName) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> NameId -> ShowS
showsPrec :: Int -> NameId -> ShowS
$cshow :: NameId -> ArgName
show :: NameId -> ArgName
$cshowList :: [NameId] -> ShowS
showList :: [NameId] -> ShowS
Show)

instance KillRange NameId where
  killRange :: NameId -> NameId
killRange = NameId -> NameId
forall a. a -> a
id

instance Pretty NameId where
  pretty :: NameId -> Doc
pretty (NameId Word64
n ModuleNameHash
m) = ArgName -> Doc
forall a. ArgName -> Doc a
text (ArgName -> Doc) -> ArgName -> Doc
forall a b. (a -> b) -> a -> b
$ Word64 -> ArgName
forall a. Show a => a -> ArgName
show Word64
n ArgName -> ShowS
forall a. [a] -> [a] -> [a]
++ ArgName
"@" ArgName -> ShowS
forall a. [a] -> [a] -> [a]
++ ModuleNameHash -> ArgName
forall a. Show a => a -> ArgName
show ModuleNameHash
m

instance Enum NameId where
  succ :: NameId -> NameId
succ (NameId Word64
n ModuleNameHash
m)     = Word64 -> ModuleNameHash -> NameId
NameId (Word64
n Word64 -> Word64 -> Word64
forall a. Num a => a -> a -> a
+ Word64
1) ModuleNameHash
m
  pred :: NameId -> NameId
pred (NameId Word64
n ModuleNameHash
m)     = Word64 -> ModuleNameHash -> NameId
NameId (Word64
n Word64 -> Word64 -> Word64
forall a. Num a => a -> a -> a
- Word64
1) ModuleNameHash
m
  toEnum :: Int -> NameId
toEnum Int
n              = NameId
forall a. HasCallStack => a
__IMPOSSIBLE__  -- should not be used
  fromEnum :: NameId -> Int
fromEnum (NameId Word64
n ModuleNameHash
_) = Word64 -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral Word64
n

instance NFData NameId where
  rnf :: NameId -> ()
rnf (NameId Word64
_ ModuleNameHash
_) = ()

instance NFData ModuleNameHash where
  rnf :: ModuleNameHash -> ()
rnf ModuleNameHash
_ = ()

instance Hashable NameId where
  {-# INLINE hashWithSalt #-}
  hashWithSalt :: Int -> NameId -> Int
hashWithSalt Int
salt (NameId Word64
n (ModuleNameHash Word64
m)) = Int -> (Word64, Word64) -> Int
forall a. Hashable a => Int -> a -> Int
hashWithSalt Int
salt (Word64
n, Word64
m)

---------------------------------------------------------------------------
-- * Meta variables
---------------------------------------------------------------------------

-- | Meta-variable identifiers use the same structure as 'NameId's.

data MetaId = MetaId
  { MetaId -> Word64
metaId     :: {-# UNPACK #-} !Word64
  , MetaId -> ModuleNameHash
metaModule :: {-# UNPACK #-} !ModuleNameHash
  }
  deriving (MetaId -> MetaId -> Bool
(MetaId -> MetaId -> Bool)
-> (MetaId -> MetaId -> Bool) -> Eq MetaId
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: MetaId -> MetaId -> Bool
== :: MetaId -> MetaId -> Bool
$c/= :: MetaId -> MetaId -> Bool
/= :: MetaId -> MetaId -> Bool
Eq, Eq MetaId
Eq MetaId =>
(MetaId -> MetaId -> Ordering)
-> (MetaId -> MetaId -> Bool)
-> (MetaId -> MetaId -> Bool)
-> (MetaId -> MetaId -> Bool)
-> (MetaId -> MetaId -> Bool)
-> (MetaId -> MetaId -> MetaId)
-> (MetaId -> MetaId -> MetaId)
-> Ord MetaId
MetaId -> MetaId -> Bool
MetaId -> MetaId -> Ordering
MetaId -> MetaId -> MetaId
forall a.
Eq a =>
(a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
$ccompare :: MetaId -> MetaId -> Ordering
compare :: MetaId -> MetaId -> Ordering
$c< :: MetaId -> MetaId -> Bool
< :: MetaId -> MetaId -> Bool
$c<= :: MetaId -> MetaId -> Bool
<= :: MetaId -> MetaId -> Bool
$c> :: MetaId -> MetaId -> Bool
> :: MetaId -> MetaId -> Bool
$c>= :: MetaId -> MetaId -> Bool
>= :: MetaId -> MetaId -> Bool
$cmax :: MetaId -> MetaId -> MetaId
max :: MetaId -> MetaId -> MetaId
$cmin :: MetaId -> MetaId -> MetaId
min :: MetaId -> MetaId -> MetaId
Ord, (forall x. MetaId -> Rep MetaId x)
-> (forall x. Rep MetaId x -> MetaId) -> Generic MetaId
forall x. Rep MetaId x -> MetaId
forall x. MetaId -> Rep MetaId x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cfrom :: forall x. MetaId -> Rep MetaId x
from :: forall x. MetaId -> Rep MetaId x
$cto :: forall x. Rep MetaId x -> MetaId
to :: forall x. Rep MetaId x -> MetaId
Generic)

instance Pretty MetaId where
  pretty :: MetaId -> Doc
pretty (MetaId Word64
n ModuleNameHash
m) =
    ArgName -> Doc
forall a. ArgName -> Doc a
text (ArgName -> Doc) -> ArgName -> Doc
forall a b. (a -> b) -> a -> b
$ ArgName
"_" ArgName -> ShowS
forall a. [a] -> [a] -> [a]
++ Word64 -> ArgName
forall a. Show a => a -> ArgName
show Word64
n ArgName -> ShowS
forall a. [a] -> [a] -> [a]
++ ArgName
"@" ArgName -> ShowS
forall a. [a] -> [a] -> [a]
++ Word64 -> ArgName
forall a. Show a => a -> ArgName
show (ModuleNameHash -> Word64
moduleNameHash ModuleNameHash
m)

instance Enum MetaId where
  succ :: MetaId -> MetaId
succ MetaId{Word64
ModuleNameHash
metaId :: MetaId -> Word64
metaModule :: MetaId -> ModuleNameHash
metaId :: Word64
metaModule :: ModuleNameHash
..} = MetaId { metaId :: Word64
metaId = Word64 -> Word64
forall a. Enum a => a -> a
succ Word64
metaId, ModuleNameHash
metaModule :: ModuleNameHash
metaModule :: ModuleNameHash
.. }
  pred :: MetaId -> MetaId
pred MetaId{Word64
ModuleNameHash
metaId :: MetaId -> Word64
metaModule :: MetaId -> ModuleNameHash
metaId :: Word64
metaModule :: ModuleNameHash
..} = MetaId { metaId :: Word64
metaId = Word64 -> Word64
forall a. Enum a => a -> a
pred Word64
metaId, ModuleNameHash
metaModule :: ModuleNameHash
metaModule :: ModuleNameHash
.. }

  -- The following functions should not be used.
  toEnum :: Int -> MetaId
toEnum   = Int -> MetaId
forall a. HasCallStack => a
__IMPOSSIBLE__
  fromEnum :: MetaId -> Int
fromEnum = MetaId -> Int
forall a. HasCallStack => a
__IMPOSSIBLE__

-- | The record selectors are not included in the resulting strings.

instance Show MetaId where
  showsPrec :: Int -> MetaId -> ShowS
showsPrec Int
p (MetaId Word64
n ModuleNameHash
m) = Bool -> ShowS -> ShowS
showParen (Int
p Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
> Int
0) (ShowS -> ShowS) -> ShowS -> ShowS
forall a b. (a -> b) -> a -> b
$
    ArgName -> ShowS
showString ArgName
"MetaId " ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
.
    Int -> Word64 -> ShowS
forall a. Show a => Int -> a -> ShowS
showsPrec Int
11 Word64
n ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
.
    ArgName -> ShowS
showString ArgName
" " ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
.
    Int -> ModuleNameHash -> ShowS
forall a. Show a => Int -> a -> ShowS
showsPrec Int
11 ModuleNameHash
m

instance NFData MetaId where
  rnf :: MetaId -> ()
rnf (MetaId Word64
x ModuleNameHash
y) = Word64 -> ()
forall a. NFData a => a -> ()
rnf Word64
x () -> () -> ()
forall a b. a -> b -> b
`seq` ModuleNameHash -> ()
forall a. NFData a => a -> ()
rnf ModuleNameHash
y

instance Hashable MetaId where
  {-# INLINE hashWithSalt #-}
  hashWithSalt :: Int -> MetaId -> Int
hashWithSalt Int
salt (MetaId Word64
n ModuleNameHash
m) = Int -> (Word64, ModuleNameHash) -> Int
forall a. Hashable a => Int -> a -> Int
hashWithSalt Int
salt (Word64
n, ModuleNameHash
m)

newtype Constr a = Constr a

-----------------------------------------------------------------------------
-- * Problems
-----------------------------------------------------------------------------

-- | A "problem" consists of a set of constraints and the same constraint can be part of multiple
--   problems.
newtype ProblemId = ProblemId Nat
  deriving (ProblemId -> ProblemId -> Bool
(ProblemId -> ProblemId -> Bool)
-> (ProblemId -> ProblemId -> Bool) -> Eq ProblemId
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: ProblemId -> ProblemId -> Bool
== :: ProblemId -> ProblemId -> Bool
$c/= :: ProblemId -> ProblemId -> Bool
/= :: ProblemId -> ProblemId -> Bool
Eq, Eq ProblemId
Eq ProblemId =>
(ProblemId -> ProblemId -> Ordering)
-> (ProblemId -> ProblemId -> Bool)
-> (ProblemId -> ProblemId -> Bool)
-> (ProblemId -> ProblemId -> Bool)
-> (ProblemId -> ProblemId -> Bool)
-> (ProblemId -> ProblemId -> ProblemId)
-> (ProblemId -> ProblemId -> ProblemId)
-> Ord ProblemId
ProblemId -> ProblemId -> Bool
ProblemId -> ProblemId -> Ordering
ProblemId -> ProblemId -> ProblemId
forall a.
Eq a =>
(a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
$ccompare :: ProblemId -> ProblemId -> Ordering
compare :: ProblemId -> ProblemId -> Ordering
$c< :: ProblemId -> ProblemId -> Bool
< :: ProblemId -> ProblemId -> Bool
$c<= :: ProblemId -> ProblemId -> Bool
<= :: ProblemId -> ProblemId -> Bool
$c> :: ProblemId -> ProblemId -> Bool
> :: ProblemId -> ProblemId -> Bool
$c>= :: ProblemId -> ProblemId -> Bool
>= :: ProblemId -> ProblemId -> Bool
$cmax :: ProblemId -> ProblemId -> ProblemId
max :: ProblemId -> ProblemId -> ProblemId
$cmin :: ProblemId -> ProblemId -> ProblemId
min :: ProblemId -> ProblemId -> ProblemId
Ord, Int -> ProblemId
ProblemId -> Int
ProblemId -> [ProblemId]
ProblemId -> ProblemId
ProblemId -> ProblemId -> [ProblemId]
ProblemId -> ProblemId -> ProblemId -> [ProblemId]
(ProblemId -> ProblemId)
-> (ProblemId -> ProblemId)
-> (Int -> ProblemId)
-> (ProblemId -> Int)
-> (ProblemId -> [ProblemId])
-> (ProblemId -> ProblemId -> [ProblemId])
-> (ProblemId -> ProblemId -> [ProblemId])
-> (ProblemId -> ProblemId -> ProblemId -> [ProblemId])
-> Enum ProblemId
forall a.
(a -> a)
-> (a -> a)
-> (Int -> a)
-> (a -> Int)
-> (a -> [a])
-> (a -> a -> [a])
-> (a -> a -> [a])
-> (a -> a -> a -> [a])
-> Enum a
$csucc :: ProblemId -> ProblemId
succ :: ProblemId -> ProblemId
$cpred :: ProblemId -> ProblemId
pred :: ProblemId -> ProblemId
$ctoEnum :: Int -> ProblemId
toEnum :: Int -> ProblemId
$cfromEnum :: ProblemId -> Int
fromEnum :: ProblemId -> Int
$cenumFrom :: ProblemId -> [ProblemId]
enumFrom :: ProblemId -> [ProblemId]
$cenumFromThen :: ProblemId -> ProblemId -> [ProblemId]
enumFromThen :: ProblemId -> ProblemId -> [ProblemId]
$cenumFromTo :: ProblemId -> ProblemId -> [ProblemId]
enumFromTo :: ProblemId -> ProblemId -> [ProblemId]
$cenumFromThenTo :: ProblemId -> ProblemId -> ProblemId -> [ProblemId]
enumFromThenTo :: ProblemId -> ProblemId -> ProblemId -> [ProblemId]
Enum, Num ProblemId
Ord ProblemId
(Num ProblemId, Ord ProblemId) =>
(ProblemId -> Rational) -> Real ProblemId
ProblemId -> Rational
forall a. (Num a, Ord a) => (a -> Rational) -> Real a
$ctoRational :: ProblemId -> Rational
toRational :: ProblemId -> Rational
Real, Enum ProblemId
Real ProblemId
(Real ProblemId, Enum ProblemId) =>
(ProblemId -> ProblemId -> ProblemId)
-> (ProblemId -> ProblemId -> ProblemId)
-> (ProblemId -> ProblemId -> ProblemId)
-> (ProblemId -> ProblemId -> ProblemId)
-> (ProblemId -> ProblemId -> (ProblemId, ProblemId))
-> (ProblemId -> ProblemId -> (ProblemId, ProblemId))
-> (ProblemId -> Integer)
-> Integral ProblemId
ProblemId -> Integer
ProblemId -> ProblemId -> (ProblemId, ProblemId)
ProblemId -> ProblemId -> ProblemId
forall a.
(Real a, Enum a) =>
(a -> a -> a)
-> (a -> a -> a)
-> (a -> a -> a)
-> (a -> a -> a)
-> (a -> a -> (a, a))
-> (a -> a -> (a, a))
-> (a -> Integer)
-> Integral a
$cquot :: ProblemId -> ProblemId -> ProblemId
quot :: ProblemId -> ProblemId -> ProblemId
$crem :: ProblemId -> ProblemId -> ProblemId
rem :: ProblemId -> ProblemId -> ProblemId
$cdiv :: ProblemId -> ProblemId -> ProblemId
div :: ProblemId -> ProblemId -> ProblemId
$cmod :: ProblemId -> ProblemId -> ProblemId
mod :: ProblemId -> ProblemId -> ProblemId
$cquotRem :: ProblemId -> ProblemId -> (ProblemId, ProblemId)
quotRem :: ProblemId -> ProblemId -> (ProblemId, ProblemId)
$cdivMod :: ProblemId -> ProblemId -> (ProblemId, ProblemId)
divMod :: ProblemId -> ProblemId -> (ProblemId, ProblemId)
$ctoInteger :: ProblemId -> Integer
toInteger :: ProblemId -> Integer
Integral, Integer -> ProblemId
ProblemId -> ProblemId
ProblemId -> ProblemId -> ProblemId
(ProblemId -> ProblemId -> ProblemId)
-> (ProblemId -> ProblemId -> ProblemId)
-> (ProblemId -> ProblemId -> ProblemId)
-> (ProblemId -> ProblemId)
-> (ProblemId -> ProblemId)
-> (ProblemId -> ProblemId)
-> (Integer -> ProblemId)
-> Num ProblemId
forall a.
(a -> a -> a)
-> (a -> a -> a)
-> (a -> a -> a)
-> (a -> a)
-> (a -> a)
-> (a -> a)
-> (Integer -> a)
-> Num a
$c+ :: ProblemId -> ProblemId -> ProblemId
+ :: ProblemId -> ProblemId -> ProblemId
$c- :: ProblemId -> ProblemId -> ProblemId
- :: ProblemId -> ProblemId -> ProblemId
$c* :: ProblemId -> ProblemId -> ProblemId
* :: ProblemId -> ProblemId -> ProblemId
$cnegate :: ProblemId -> ProblemId
negate :: ProblemId -> ProblemId
$cabs :: ProblemId -> ProblemId
abs :: ProblemId -> ProblemId
$csignum :: ProblemId -> ProblemId
signum :: ProblemId -> ProblemId
$cfromInteger :: Integer -> ProblemId
fromInteger :: Integer -> ProblemId
Num, ProblemId -> ()
(ProblemId -> ()) -> NFData ProblemId
forall a. (a -> ()) -> NFData a
$crnf :: ProblemId -> ()
rnf :: ProblemId -> ()
NFData)

-- This particular Show instance is ok because of the Num instance.
instance Show   ProblemId where show :: ProblemId -> ArgName
show   (ProblemId Int
n) = Int -> ArgName
forall a. Show a => a -> ArgName
show Int
n
instance Pretty ProblemId where pretty :: ProblemId -> Doc
pretty (ProblemId Int
n) = Int -> Doc
forall a. Pretty a => a -> Doc
pretty Int
n

-- | The unique identifier of an opaque block. Second argument is the
-- top-level module identifier.
data OpaqueId = OpaqueId {-# UNPACK #-} !Word64 {-# UNPACK #-} !ModuleNameHash
    deriving (OpaqueId -> OpaqueId -> Bool
(OpaqueId -> OpaqueId -> Bool)
-> (OpaqueId -> OpaqueId -> Bool) -> Eq OpaqueId
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: OpaqueId -> OpaqueId -> Bool
== :: OpaqueId -> OpaqueId -> Bool
$c/= :: OpaqueId -> OpaqueId -> Bool
/= :: OpaqueId -> OpaqueId -> Bool
Eq, Eq OpaqueId
Eq OpaqueId =>
(OpaqueId -> OpaqueId -> Ordering)
-> (OpaqueId -> OpaqueId -> Bool)
-> (OpaqueId -> OpaqueId -> Bool)
-> (OpaqueId -> OpaqueId -> Bool)
-> (OpaqueId -> OpaqueId -> Bool)
-> (OpaqueId -> OpaqueId -> OpaqueId)
-> (OpaqueId -> OpaqueId -> OpaqueId)
-> Ord OpaqueId
OpaqueId -> OpaqueId -> Bool
OpaqueId -> OpaqueId -> Ordering
OpaqueId -> OpaqueId -> OpaqueId
forall a.
Eq a =>
(a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
$ccompare :: OpaqueId -> OpaqueId -> Ordering
compare :: OpaqueId -> OpaqueId -> Ordering
$c< :: OpaqueId -> OpaqueId -> Bool
< :: OpaqueId -> OpaqueId -> Bool
$c<= :: OpaqueId -> OpaqueId -> Bool
<= :: OpaqueId -> OpaqueId -> Bool
$c> :: OpaqueId -> OpaqueId -> Bool
> :: OpaqueId -> OpaqueId -> Bool
$c>= :: OpaqueId -> OpaqueId -> Bool
>= :: OpaqueId -> OpaqueId -> Bool
$cmax :: OpaqueId -> OpaqueId -> OpaqueId
max :: OpaqueId -> OpaqueId -> OpaqueId
$cmin :: OpaqueId -> OpaqueId -> OpaqueId
min :: OpaqueId -> OpaqueId -> OpaqueId
Ord, (forall x. OpaqueId -> Rep OpaqueId x)
-> (forall x. Rep OpaqueId x -> OpaqueId) -> Generic OpaqueId
forall x. Rep OpaqueId x -> OpaqueId
forall x. OpaqueId -> Rep OpaqueId x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cfrom :: forall x. OpaqueId -> Rep OpaqueId x
from :: forall x. OpaqueId -> Rep OpaqueId x
$cto :: forall x. Rep OpaqueId x -> OpaqueId
to :: forall x. Rep OpaqueId x -> OpaqueId
Generic, Int -> OpaqueId -> ShowS
[OpaqueId] -> ShowS
OpaqueId -> ArgName
(Int -> OpaqueId -> ShowS)
-> (OpaqueId -> ArgName) -> ([OpaqueId] -> ShowS) -> Show OpaqueId
forall a.
(Int -> a -> ShowS) -> (a -> ArgName) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> OpaqueId -> ShowS
showsPrec :: Int -> OpaqueId -> ShowS
$cshow :: OpaqueId -> ArgName
show :: OpaqueId -> ArgName
$cshowList :: [OpaqueId] -> ShowS
showList :: [OpaqueId] -> ShowS
Show)

instance KillRange OpaqueId where
  killRange :: OpaqueId -> OpaqueId
killRange = OpaqueId -> OpaqueId
forall a. a -> a
id

instance Pretty OpaqueId where
  pretty :: OpaqueId -> Doc
pretty (OpaqueId Word64
n ModuleNameHash
m) = ArgName -> Doc
forall a. ArgName -> Doc a
text (ArgName -> Doc) -> ArgName -> Doc
forall a b. (a -> b) -> a -> b
$ Word64 -> ArgName
forall a. Show a => a -> ArgName
show Word64
n ArgName -> ShowS
forall a. [a] -> [a] -> [a]
++ ArgName
"@" ArgName -> ShowS
forall a. [a] -> [a] -> [a]
++ ModuleNameHash -> ArgName
forall a. Show a => a -> ArgName
show ModuleNameHash
m

instance Enum OpaqueId where
  succ :: OpaqueId -> OpaqueId
succ (OpaqueId Word64
n ModuleNameHash
m)     = Word64 -> ModuleNameHash -> OpaqueId
OpaqueId (Word64
n Word64 -> Word64 -> Word64
forall a. Num a => a -> a -> a
+ Word64
1) ModuleNameHash
m
  pred :: OpaqueId -> OpaqueId
pred (OpaqueId Word64
n ModuleNameHash
m)     = Word64 -> ModuleNameHash -> OpaqueId
OpaqueId (Word64
n Word64 -> Word64 -> Word64
forall a. Num a => a -> a -> a
- Word64
1) ModuleNameHash
m
  toEnum :: Int -> OpaqueId
toEnum Int
n                = OpaqueId
forall a. HasCallStack => a
__IMPOSSIBLE__  -- should not be used
  fromEnum :: OpaqueId -> Int
fromEnum (OpaqueId Word64
n ModuleNameHash
_) = Word64 -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral Word64
n

instance NFData OpaqueId where
  rnf :: OpaqueId -> ()
rnf (OpaqueId Word64
_ ModuleNameHash
_) = ()

instance Hashable OpaqueId where
  {-# INLINE hashWithSalt #-}
  hashWithSalt :: Int -> OpaqueId -> Int
hashWithSalt Int
salt (OpaqueId Word64
n (ModuleNameHash Word64
m)) = Int -> (Word64, Word64) -> Int
forall a. Hashable a => Int -> a -> Int
hashWithSalt Int
salt (Word64
n, Word64
m)

------------------------------------------------------------------------
-- * Placeholders (used to parse sections)
------------------------------------------------------------------------

-- | The position of a name part or underscore in a name.

data PositionInName
  = Beginning
    -- ^ The following underscore is at the beginning of the name:
    -- @_foo@.
  | Middle
    -- ^ The following underscore is in the middle of the name:
    -- @foo_bar@.
  | End
    -- ^ The following underscore is at the end of the name: @foo_@.
  deriving (Int -> PositionInName -> ShowS
[PositionInName] -> ShowS
PositionInName -> ArgName
(Int -> PositionInName -> ShowS)
-> (PositionInName -> ArgName)
-> ([PositionInName] -> ShowS)
-> Show PositionInName
forall a.
(Int -> a -> ShowS) -> (a -> ArgName) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> PositionInName -> ShowS
showsPrec :: Int -> PositionInName -> ShowS
$cshow :: PositionInName -> ArgName
show :: PositionInName -> ArgName
$cshowList :: [PositionInName] -> ShowS
showList :: [PositionInName] -> ShowS
Show, PositionInName -> PositionInName -> Bool
(PositionInName -> PositionInName -> Bool)
-> (PositionInName -> PositionInName -> Bool) -> Eq PositionInName
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: PositionInName -> PositionInName -> Bool
== :: PositionInName -> PositionInName -> Bool
$c/= :: PositionInName -> PositionInName -> Bool
/= :: PositionInName -> PositionInName -> Bool
Eq, Eq PositionInName
Eq PositionInName =>
(PositionInName -> PositionInName -> Ordering)
-> (PositionInName -> PositionInName -> Bool)
-> (PositionInName -> PositionInName -> Bool)
-> (PositionInName -> PositionInName -> Bool)
-> (PositionInName -> PositionInName -> Bool)
-> (PositionInName -> PositionInName -> PositionInName)
-> (PositionInName -> PositionInName -> PositionInName)
-> Ord PositionInName
PositionInName -> PositionInName -> Bool
PositionInName -> PositionInName -> Ordering
PositionInName -> PositionInName -> PositionInName
forall a.
Eq a =>
(a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
$ccompare :: PositionInName -> PositionInName -> Ordering
compare :: PositionInName -> PositionInName -> Ordering
$c< :: PositionInName -> PositionInName -> Bool
< :: PositionInName -> PositionInName -> Bool
$c<= :: PositionInName -> PositionInName -> Bool
<= :: PositionInName -> PositionInName -> Bool
$c> :: PositionInName -> PositionInName -> Bool
> :: PositionInName -> PositionInName -> Bool
$c>= :: PositionInName -> PositionInName -> Bool
>= :: PositionInName -> PositionInName -> Bool
$cmax :: PositionInName -> PositionInName -> PositionInName
max :: PositionInName -> PositionInName -> PositionInName
$cmin :: PositionInName -> PositionInName -> PositionInName
min :: PositionInName -> PositionInName -> PositionInName
Ord)

-- | Placeholders are used to represent the underscores in a section.

data MaybePlaceholder e
  = Placeholder !PositionInName
  | NoPlaceholder !(Strict.Maybe PositionInName) e
    -- ^ The second argument is used only (but not always) for name
    -- parts other than underscores.
  deriving (MaybePlaceholder e -> MaybePlaceholder e -> Bool
(MaybePlaceholder e -> MaybePlaceholder e -> Bool)
-> (MaybePlaceholder e -> MaybePlaceholder e -> Bool)
-> Eq (MaybePlaceholder e)
forall e. Eq e => MaybePlaceholder e -> MaybePlaceholder e -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: forall e. Eq e => MaybePlaceholder e -> MaybePlaceholder e -> Bool
== :: MaybePlaceholder e -> MaybePlaceholder e -> Bool
$c/= :: forall e. Eq e => MaybePlaceholder e -> MaybePlaceholder e -> Bool
/= :: MaybePlaceholder e -> MaybePlaceholder e -> Bool
Eq, Eq (MaybePlaceholder e)
Eq (MaybePlaceholder e) =>
(MaybePlaceholder e -> MaybePlaceholder e -> Ordering)
-> (MaybePlaceholder e -> MaybePlaceholder e -> Bool)
-> (MaybePlaceholder e -> MaybePlaceholder e -> Bool)
-> (MaybePlaceholder e -> MaybePlaceholder e -> Bool)
-> (MaybePlaceholder e -> MaybePlaceholder e -> Bool)
-> (MaybePlaceholder e -> MaybePlaceholder e -> MaybePlaceholder e)
-> (MaybePlaceholder e -> MaybePlaceholder e -> MaybePlaceholder e)
-> Ord (MaybePlaceholder e)
MaybePlaceholder e -> MaybePlaceholder e -> Bool
MaybePlaceholder e -> MaybePlaceholder e -> Ordering
MaybePlaceholder e -> MaybePlaceholder e -> MaybePlaceholder e
forall a.
Eq a =>
(a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
forall e. Ord e => Eq (MaybePlaceholder e)
forall e. Ord e => MaybePlaceholder e -> MaybePlaceholder e -> Bool
forall e.
Ord e =>
MaybePlaceholder e -> MaybePlaceholder e -> Ordering
forall e.
Ord e =>
MaybePlaceholder e -> MaybePlaceholder e -> MaybePlaceholder e
$ccompare :: forall e.
Ord e =>
MaybePlaceholder e -> MaybePlaceholder e -> Ordering
compare :: MaybePlaceholder e -> MaybePlaceholder e -> Ordering
$c< :: forall e. Ord e => MaybePlaceholder e -> MaybePlaceholder e -> Bool
< :: MaybePlaceholder e -> MaybePlaceholder e -> Bool
$c<= :: forall e. Ord e => MaybePlaceholder e -> MaybePlaceholder e -> Bool
<= :: MaybePlaceholder e -> MaybePlaceholder e -> Bool
$c> :: forall e. Ord e => MaybePlaceholder e -> MaybePlaceholder e -> Bool
> :: MaybePlaceholder e -> MaybePlaceholder e -> Bool
$c>= :: forall e. Ord e => MaybePlaceholder e -> MaybePlaceholder e -> Bool
>= :: MaybePlaceholder e -> MaybePlaceholder e -> Bool
$cmax :: forall e.
Ord e =>
MaybePlaceholder e -> MaybePlaceholder e -> MaybePlaceholder e
max :: MaybePlaceholder e -> MaybePlaceholder e -> MaybePlaceholder e
$cmin :: forall e.
Ord e =>
MaybePlaceholder e -> MaybePlaceholder e -> MaybePlaceholder e
min :: MaybePlaceholder e -> MaybePlaceholder e -> MaybePlaceholder e
Ord, (forall a b. (a -> b) -> MaybePlaceholder a -> MaybePlaceholder b)
-> (forall a b. a -> MaybePlaceholder b -> MaybePlaceholder a)
-> Functor MaybePlaceholder
forall a b. a -> MaybePlaceholder b -> MaybePlaceholder a
forall a b. (a -> b) -> MaybePlaceholder a -> MaybePlaceholder b
forall (f :: * -> *).
(forall a b. (a -> b) -> f a -> f b)
-> (forall a b. a -> f b -> f a) -> Functor f
$cfmap :: forall a b. (a -> b) -> MaybePlaceholder a -> MaybePlaceholder b
fmap :: forall a b. (a -> b) -> MaybePlaceholder a -> MaybePlaceholder b
$c<$ :: forall a b. a -> MaybePlaceholder b -> MaybePlaceholder a
<$ :: forall a b. a -> MaybePlaceholder b -> MaybePlaceholder a
Functor, (forall m. Monoid m => MaybePlaceholder m -> m)
-> (forall m a. Monoid m => (a -> m) -> MaybePlaceholder a -> m)
-> (forall m a. Monoid m => (a -> m) -> MaybePlaceholder a -> m)
-> (forall a b. (a -> b -> b) -> b -> MaybePlaceholder a -> b)
-> (forall a b. (a -> b -> b) -> b -> MaybePlaceholder a -> b)
-> (forall b a. (b -> a -> b) -> b -> MaybePlaceholder a -> b)
-> (forall b a. (b -> a -> b) -> b -> MaybePlaceholder a -> b)
-> (forall a. (a -> a -> a) -> MaybePlaceholder a -> a)
-> (forall a. (a -> a -> a) -> MaybePlaceholder a -> a)
-> (forall a. MaybePlaceholder a -> [a])
-> (forall a. MaybePlaceholder a -> Bool)
-> (forall a. MaybePlaceholder a -> Int)
-> (forall a. Eq a => a -> MaybePlaceholder a -> Bool)
-> (forall a. Ord a => MaybePlaceholder a -> a)
-> (forall a. Ord a => MaybePlaceholder a -> a)
-> (forall a. Num a => MaybePlaceholder a -> a)
-> (forall a. Num a => MaybePlaceholder a -> a)
-> Foldable MaybePlaceholder
forall a. Eq a => a -> MaybePlaceholder a -> Bool
forall a. Num a => MaybePlaceholder a -> a
forall a. Ord a => MaybePlaceholder a -> a
forall m. Monoid m => MaybePlaceholder m -> m
forall a. MaybePlaceholder a -> Bool
forall a. MaybePlaceholder a -> Int
forall a. MaybePlaceholder a -> [a]
forall a. (a -> a -> a) -> MaybePlaceholder a -> a
forall m a. Monoid m => (a -> m) -> MaybePlaceholder a -> m
forall b a. (b -> a -> b) -> b -> MaybePlaceholder a -> b
forall a b. (a -> b -> b) -> b -> MaybePlaceholder a -> b
forall (t :: * -> *).
(forall m. Monoid m => t m -> m)
-> (forall m a. Monoid m => (a -> m) -> t a -> m)
-> (forall m a. Monoid m => (a -> m) -> t a -> m)
-> (forall a b. (a -> b -> b) -> b -> t a -> b)
-> (forall a b. (a -> b -> b) -> b -> t a -> b)
-> (forall b a. (b -> a -> b) -> b -> t a -> b)
-> (forall b a. (b -> a -> b) -> b -> t a -> b)
-> (forall a. (a -> a -> a) -> t a -> a)
-> (forall a. (a -> a -> a) -> t a -> a)
-> (forall a. t a -> [a])
-> (forall a. t a -> Bool)
-> (forall a. t a -> Int)
-> (forall a. Eq a => a -> t a -> Bool)
-> (forall a. Ord a => t a -> a)
-> (forall a. Ord a => t a -> a)
-> (forall a. Num a => t a -> a)
-> (forall a. Num a => t a -> a)
-> Foldable t
$cfold :: forall m. Monoid m => MaybePlaceholder m -> m
fold :: forall m. Monoid m => MaybePlaceholder m -> m
$cfoldMap :: forall m a. Monoid m => (a -> m) -> MaybePlaceholder a -> m
foldMap :: forall m a. Monoid m => (a -> m) -> MaybePlaceholder a -> m
$cfoldMap' :: forall m a. Monoid m => (a -> m) -> MaybePlaceholder a -> m
foldMap' :: forall m a. Monoid m => (a -> m) -> MaybePlaceholder a -> m
$cfoldr :: forall a b. (a -> b -> b) -> b -> MaybePlaceholder a -> b
foldr :: forall a b. (a -> b -> b) -> b -> MaybePlaceholder a -> b
$cfoldr' :: forall a b. (a -> b -> b) -> b -> MaybePlaceholder a -> b
foldr' :: forall a b. (a -> b -> b) -> b -> MaybePlaceholder a -> b
$cfoldl :: forall b a. (b -> a -> b) -> b -> MaybePlaceholder a -> b
foldl :: forall b a. (b -> a -> b) -> b -> MaybePlaceholder a -> b
$cfoldl' :: forall b a. (b -> a -> b) -> b -> MaybePlaceholder a -> b
foldl' :: forall b a. (b -> a -> b) -> b -> MaybePlaceholder a -> b
$cfoldr1 :: forall a. (a -> a -> a) -> MaybePlaceholder a -> a
foldr1 :: forall a. (a -> a -> a) -> MaybePlaceholder a -> a
$cfoldl1 :: forall a. (a -> a -> a) -> MaybePlaceholder a -> a
foldl1 :: forall a. (a -> a -> a) -> MaybePlaceholder a -> a
$ctoList :: forall a. MaybePlaceholder a -> [a]
toList :: forall a. MaybePlaceholder a -> [a]
$cnull :: forall a. MaybePlaceholder a -> Bool
null :: forall a. MaybePlaceholder a -> Bool
$clength :: forall a. MaybePlaceholder a -> Int
length :: forall a. MaybePlaceholder a -> Int
$celem :: forall a. Eq a => a -> MaybePlaceholder a -> Bool
elem :: forall a. Eq a => a -> MaybePlaceholder a -> Bool
$cmaximum :: forall a. Ord a => MaybePlaceholder a -> a
maximum :: forall a. Ord a => MaybePlaceholder a -> a
$cminimum :: forall a. Ord a => MaybePlaceholder a -> a
minimum :: forall a. Ord a => MaybePlaceholder a -> a
$csum :: forall a. Num a => MaybePlaceholder a -> a
sum :: forall a. Num a => MaybePlaceholder a -> a
$cproduct :: forall a. Num a => MaybePlaceholder a -> a
product :: forall a. Num a => MaybePlaceholder a -> a
Foldable, Functor MaybePlaceholder
Foldable MaybePlaceholder
(Functor MaybePlaceholder, Foldable MaybePlaceholder) =>
(forall (f :: * -> *) a b.
 Applicative f =>
 (a -> f b) -> MaybePlaceholder a -> f (MaybePlaceholder b))
-> (forall (f :: * -> *) a.
    Applicative f =>
    MaybePlaceholder (f a) -> f (MaybePlaceholder a))
-> (forall (m :: * -> *) a b.
    Monad m =>
    (a -> m b) -> MaybePlaceholder a -> m (MaybePlaceholder b))
-> (forall (m :: * -> *) a.
    Monad m =>
    MaybePlaceholder (m a) -> m (MaybePlaceholder a))
-> Traversable MaybePlaceholder
forall (t :: * -> *).
(Functor t, Foldable t) =>
(forall (f :: * -> *) a b.
 Applicative f =>
 (a -> f b) -> t a -> f (t b))
-> (forall (f :: * -> *) a. Applicative f => t (f a) -> f (t a))
-> (forall (m :: * -> *) a b.
    Monad m =>
    (a -> m b) -> t a -> m (t b))
-> (forall (m :: * -> *) a. Monad m => t (m a) -> m (t a))
-> Traversable t
forall (m :: * -> *) a.
Monad m =>
MaybePlaceholder (m a) -> m (MaybePlaceholder a)
forall (f :: * -> *) a.
Applicative f =>
MaybePlaceholder (f a) -> f (MaybePlaceholder a)
forall (m :: * -> *) a b.
Monad m =>
(a -> m b) -> MaybePlaceholder a -> m (MaybePlaceholder b)
forall (f :: * -> *) a b.
Applicative f =>
(a -> f b) -> MaybePlaceholder a -> f (MaybePlaceholder b)
$ctraverse :: forall (f :: * -> *) a b.
Applicative f =>
(a -> f b) -> MaybePlaceholder a -> f (MaybePlaceholder b)
traverse :: forall (f :: * -> *) a b.
Applicative f =>
(a -> f b) -> MaybePlaceholder a -> f (MaybePlaceholder b)
$csequenceA :: forall (f :: * -> *) a.
Applicative f =>
MaybePlaceholder (f a) -> f (MaybePlaceholder a)
sequenceA :: forall (f :: * -> *) a.
Applicative f =>
MaybePlaceholder (f a) -> f (MaybePlaceholder a)
$cmapM :: forall (m :: * -> *) a b.
Monad m =>
(a -> m b) -> MaybePlaceholder a -> m (MaybePlaceholder b)
mapM :: forall (m :: * -> *) a b.
Monad m =>
(a -> m b) -> MaybePlaceholder a -> m (MaybePlaceholder b)
$csequence :: forall (m :: * -> *) a.
Monad m =>
MaybePlaceholder (m a) -> m (MaybePlaceholder a)
sequence :: forall (m :: * -> *) a.
Monad m =>
MaybePlaceholder (m a) -> m (MaybePlaceholder a)
Traversable, Int -> MaybePlaceholder e -> ShowS
[MaybePlaceholder e] -> ShowS
MaybePlaceholder e -> ArgName
(Int -> MaybePlaceholder e -> ShowS)
-> (MaybePlaceholder e -> ArgName)
-> ([MaybePlaceholder e] -> ShowS)
-> Show (MaybePlaceholder e)
forall e. Show e => Int -> MaybePlaceholder e -> ShowS
forall e. Show e => [MaybePlaceholder e] -> ShowS
forall e. Show e => MaybePlaceholder e -> ArgName
forall a.
(Int -> a -> ShowS) -> (a -> ArgName) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: forall e. Show e => Int -> MaybePlaceholder e -> ShowS
showsPrec :: Int -> MaybePlaceholder e -> ShowS
$cshow :: forall e. Show e => MaybePlaceholder e -> ArgName
show :: MaybePlaceholder e -> ArgName
$cshowList :: forall e. Show e => [MaybePlaceholder e] -> ShowS
showList :: [MaybePlaceholder e] -> ShowS
Show)

-- | An abbreviation: @noPlaceholder = 'NoPlaceholder'
-- 'Strict.Nothing'@.

noPlaceholder :: e -> MaybePlaceholder e
noPlaceholder :: forall e. e -> MaybePlaceholder e
noPlaceholder = Maybe PositionInName -> e -> MaybePlaceholder e
forall e. Maybe PositionInName -> e -> MaybePlaceholder e
NoPlaceholder Maybe PositionInName
forall a. Maybe a
Strict.Nothing

instance HasRange a => HasRange (MaybePlaceholder a) where
  getRange :: MaybePlaceholder a -> Range
getRange Placeholder{}       = Range
forall a. Range' a
noRange
  getRange (NoPlaceholder Maybe PositionInName
_ a
e) = a -> Range
forall a. HasRange a => a -> Range
getRange a
e

instance KillRange a => KillRange (MaybePlaceholder a) where
  killRange :: KillRangeT (MaybePlaceholder a)
killRange p :: MaybePlaceholder a
p@Placeholder{}     = MaybePlaceholder a
p
  killRange (NoPlaceholder Maybe PositionInName
p a
e) = (a -> MaybePlaceholder a) -> a -> MaybePlaceholder a
forall t (b :: Bool).
(KILLRANGE t b, IsBase t ~ b, All KillRange (Domains t)) =>
t -> t
killRangeN (Maybe PositionInName -> a -> MaybePlaceholder a
forall e. Maybe PositionInName -> e -> MaybePlaceholder e
NoPlaceholder Maybe PositionInName
p) a
e

instance NFData a => NFData (MaybePlaceholder a) where
  rnf :: MaybePlaceholder a -> ()
rnf (Placeholder PositionInName
_)     = ()
  rnf (NoPlaceholder Maybe PositionInName
_ a
a) = a -> ()
forall a. NFData a => a -> ()
rnf a
a

---------------------------------------------------------------------------
-- * Interaction meta variables
---------------------------------------------------------------------------

newtype InteractionId = InteractionId { InteractionId -> Int
interactionId :: Nat }
    deriving ( InteractionId -> InteractionId -> Bool
(InteractionId -> InteractionId -> Bool)
-> (InteractionId -> InteractionId -> Bool) -> Eq InteractionId
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: InteractionId -> InteractionId -> Bool
== :: InteractionId -> InteractionId -> Bool
$c/= :: InteractionId -> InteractionId -> Bool
/= :: InteractionId -> InteractionId -> Bool
Eq
             , Eq InteractionId
Eq InteractionId =>
(InteractionId -> InteractionId -> Ordering)
-> (InteractionId -> InteractionId -> Bool)
-> (InteractionId -> InteractionId -> Bool)
-> (InteractionId -> InteractionId -> Bool)
-> (InteractionId -> InteractionId -> Bool)
-> (InteractionId -> InteractionId -> InteractionId)
-> (InteractionId -> InteractionId -> InteractionId)
-> Ord InteractionId
InteractionId -> InteractionId -> Bool
InteractionId -> InteractionId -> Ordering
InteractionId -> InteractionId -> InteractionId
forall a.
Eq a =>
(a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
$ccompare :: InteractionId -> InteractionId -> Ordering
compare :: InteractionId -> InteractionId -> Ordering
$c< :: InteractionId -> InteractionId -> Bool
< :: InteractionId -> InteractionId -> Bool
$c<= :: InteractionId -> InteractionId -> Bool
<= :: InteractionId -> InteractionId -> Bool
$c> :: InteractionId -> InteractionId -> Bool
> :: InteractionId -> InteractionId -> Bool
$c>= :: InteractionId -> InteractionId -> Bool
>= :: InteractionId -> InteractionId -> Bool
$cmax :: InteractionId -> InteractionId -> InteractionId
max :: InteractionId -> InteractionId -> InteractionId
$cmin :: InteractionId -> InteractionId -> InteractionId
min :: InteractionId -> InteractionId -> InteractionId
Ord
             , Int -> InteractionId -> ShowS
[InteractionId] -> ShowS
InteractionId -> ArgName
(Int -> InteractionId -> ShowS)
-> (InteractionId -> ArgName)
-> ([InteractionId] -> ShowS)
-> Show InteractionId
forall a.
(Int -> a -> ShowS) -> (a -> ArgName) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> InteractionId -> ShowS
showsPrec :: Int -> InteractionId -> ShowS
$cshow :: InteractionId -> ArgName
show :: InteractionId -> ArgName
$cshowList :: [InteractionId] -> ShowS
showList :: [InteractionId] -> ShowS
Show
             , Integer -> InteractionId
InteractionId -> InteractionId
InteractionId -> InteractionId -> InteractionId
(InteractionId -> InteractionId -> InteractionId)
-> (InteractionId -> InteractionId -> InteractionId)
-> (InteractionId -> InteractionId -> InteractionId)
-> (InteractionId -> InteractionId)
-> (InteractionId -> InteractionId)
-> (InteractionId -> InteractionId)
-> (Integer -> InteractionId)
-> Num InteractionId
forall a.
(a -> a -> a)
-> (a -> a -> a)
-> (a -> a -> a)
-> (a -> a)
-> (a -> a)
-> (a -> a)
-> (Integer -> a)
-> Num a
$c+ :: InteractionId -> InteractionId -> InteractionId
+ :: InteractionId -> InteractionId -> InteractionId
$c- :: InteractionId -> InteractionId -> InteractionId
- :: InteractionId -> InteractionId -> InteractionId
$c* :: InteractionId -> InteractionId -> InteractionId
* :: InteractionId -> InteractionId -> InteractionId
$cnegate :: InteractionId -> InteractionId
negate :: InteractionId -> InteractionId
$cabs :: InteractionId -> InteractionId
abs :: InteractionId -> InteractionId
$csignum :: InteractionId -> InteractionId
signum :: InteractionId -> InteractionId
$cfromInteger :: Integer -> InteractionId
fromInteger :: Integer -> InteractionId
Num
             , Enum InteractionId
Real InteractionId
(Real InteractionId, Enum InteractionId) =>
(InteractionId -> InteractionId -> InteractionId)
-> (InteractionId -> InteractionId -> InteractionId)
-> (InteractionId -> InteractionId -> InteractionId)
-> (InteractionId -> InteractionId -> InteractionId)
-> (InteractionId
    -> InteractionId -> (InteractionId, InteractionId))
-> (InteractionId
    -> InteractionId -> (InteractionId, InteractionId))
-> (InteractionId -> Integer)
-> Integral InteractionId
InteractionId -> Integer
InteractionId -> InteractionId -> (InteractionId, InteractionId)
InteractionId -> InteractionId -> InteractionId
forall a.
(Real a, Enum a) =>
(a -> a -> a)
-> (a -> a -> a)
-> (a -> a -> a)
-> (a -> a -> a)
-> (a -> a -> (a, a))
-> (a -> a -> (a, a))
-> (a -> Integer)
-> Integral a
$cquot :: InteractionId -> InteractionId -> InteractionId
quot :: InteractionId -> InteractionId -> InteractionId
$crem :: InteractionId -> InteractionId -> InteractionId
rem :: InteractionId -> InteractionId -> InteractionId
$cdiv :: InteractionId -> InteractionId -> InteractionId
div :: InteractionId -> InteractionId -> InteractionId
$cmod :: InteractionId -> InteractionId -> InteractionId
mod :: InteractionId -> InteractionId -> InteractionId
$cquotRem :: InteractionId -> InteractionId -> (InteractionId, InteractionId)
quotRem :: InteractionId -> InteractionId -> (InteractionId, InteractionId)
$cdivMod :: InteractionId -> InteractionId -> (InteractionId, InteractionId)
divMod :: InteractionId -> InteractionId -> (InteractionId, InteractionId)
$ctoInteger :: InteractionId -> Integer
toInteger :: InteractionId -> Integer
Integral
             , Num InteractionId
Ord InteractionId
(Num InteractionId, Ord InteractionId) =>
(InteractionId -> Rational) -> Real InteractionId
InteractionId -> Rational
forall a. (Num a, Ord a) => (a -> Rational) -> Real a
$ctoRational :: InteractionId -> Rational
toRational :: InteractionId -> Rational
Real
             , Int -> InteractionId
InteractionId -> Int
InteractionId -> [InteractionId]
InteractionId -> InteractionId
InteractionId -> InteractionId -> [InteractionId]
InteractionId -> InteractionId -> InteractionId -> [InteractionId]
(InteractionId -> InteractionId)
-> (InteractionId -> InteractionId)
-> (Int -> InteractionId)
-> (InteractionId -> Int)
-> (InteractionId -> [InteractionId])
-> (InteractionId -> InteractionId -> [InteractionId])
-> (InteractionId -> InteractionId -> [InteractionId])
-> (InteractionId
    -> InteractionId -> InteractionId -> [InteractionId])
-> Enum InteractionId
forall a.
(a -> a)
-> (a -> a)
-> (Int -> a)
-> (a -> Int)
-> (a -> [a])
-> (a -> a -> [a])
-> (a -> a -> [a])
-> (a -> a -> a -> [a])
-> Enum a
$csucc :: InteractionId -> InteractionId
succ :: InteractionId -> InteractionId
$cpred :: InteractionId -> InteractionId
pred :: InteractionId -> InteractionId
$ctoEnum :: Int -> InteractionId
toEnum :: Int -> InteractionId
$cfromEnum :: InteractionId -> Int
fromEnum :: InteractionId -> Int
$cenumFrom :: InteractionId -> [InteractionId]
enumFrom :: InteractionId -> [InteractionId]
$cenumFromThen :: InteractionId -> InteractionId -> [InteractionId]
enumFromThen :: InteractionId -> InteractionId -> [InteractionId]
$cenumFromTo :: InteractionId -> InteractionId -> [InteractionId]
enumFromTo :: InteractionId -> InteractionId -> [InteractionId]
$cenumFromThenTo :: InteractionId -> InteractionId -> InteractionId -> [InteractionId]
enumFromThenTo :: InteractionId -> InteractionId -> InteractionId -> [InteractionId]
Enum
             , InteractionId -> ()
(InteractionId -> ()) -> NFData InteractionId
forall a. (a -> ()) -> NFData a
$crnf :: InteractionId -> ()
rnf :: InteractionId -> ()
NFData
             )

instance Pretty InteractionId where
    pretty :: InteractionId -> Doc
pretty (InteractionId Int
i) = ArgName -> Doc
forall a. ArgName -> Doc a
text (ArgName -> Doc) -> ArgName -> Doc
forall a b. (a -> b) -> a -> b
$ ArgName
"?" ArgName -> ShowS
forall a. [a] -> [a] -> [a]
++ Int -> ArgName
forall a. Show a => a -> ArgName
show Int
i

instance KillRange InteractionId where killRange :: InteractionId -> InteractionId
killRange = InteractionId -> InteractionId
forall a. a -> a
id

---------------------------------------------------------------------------
-- * Fixity
---------------------------------------------------------------------------

-- | Precedence levels for operators.

type PrecedenceLevel = Double

data FixityLevel
  = Unrelated
    -- ^ No fixity declared.
  | Related !PrecedenceLevel
    -- ^ Fixity level declared as the number.
  deriving (FixityLevel -> FixityLevel -> Bool
(FixityLevel -> FixityLevel -> Bool)
-> (FixityLevel -> FixityLevel -> Bool) -> Eq FixityLevel
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: FixityLevel -> FixityLevel -> Bool
== :: FixityLevel -> FixityLevel -> Bool
$c/= :: FixityLevel -> FixityLevel -> Bool
/= :: FixityLevel -> FixityLevel -> Bool
Eq, Eq FixityLevel
Eq FixityLevel =>
(FixityLevel -> FixityLevel -> Ordering)
-> (FixityLevel -> FixityLevel -> Bool)
-> (FixityLevel -> FixityLevel -> Bool)
-> (FixityLevel -> FixityLevel -> Bool)
-> (FixityLevel -> FixityLevel -> Bool)
-> (FixityLevel -> FixityLevel -> FixityLevel)
-> (FixityLevel -> FixityLevel -> FixityLevel)
-> Ord FixityLevel
FixityLevel -> FixityLevel -> Bool
FixityLevel -> FixityLevel -> Ordering
FixityLevel -> FixityLevel -> FixityLevel
forall a.
Eq a =>
(a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
$ccompare :: FixityLevel -> FixityLevel -> Ordering
compare :: FixityLevel -> FixityLevel -> Ordering
$c< :: FixityLevel -> FixityLevel -> Bool
< :: FixityLevel -> FixityLevel -> Bool
$c<= :: FixityLevel -> FixityLevel -> Bool
<= :: FixityLevel -> FixityLevel -> Bool
$c> :: FixityLevel -> FixityLevel -> Bool
> :: FixityLevel -> FixityLevel -> Bool
$c>= :: FixityLevel -> FixityLevel -> Bool
>= :: FixityLevel -> FixityLevel -> Bool
$cmax :: FixityLevel -> FixityLevel -> FixityLevel
max :: FixityLevel -> FixityLevel -> FixityLevel
$cmin :: FixityLevel -> FixityLevel -> FixityLevel
min :: FixityLevel -> FixityLevel -> FixityLevel
Ord, Int -> FixityLevel -> ShowS
[FixityLevel] -> ShowS
FixityLevel -> ArgName
(Int -> FixityLevel -> ShowS)
-> (FixityLevel -> ArgName)
-> ([FixityLevel] -> ShowS)
-> Show FixityLevel
forall a.
(Int -> a -> ShowS) -> (a -> ArgName) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> FixityLevel -> ShowS
showsPrec :: Int -> FixityLevel -> ShowS
$cshow :: FixityLevel -> ArgName
show :: FixityLevel -> ArgName
$cshowList :: [FixityLevel] -> ShowS
showList :: [FixityLevel] -> ShowS
Show)

instance Null FixityLevel where
  null :: FixityLevel -> Bool
null FixityLevel
Unrelated = Bool
True
  null Related{} = Bool
False
  empty :: FixityLevel
empty = FixityLevel
Unrelated

instance NFData FixityLevel where
  rnf :: FixityLevel -> ()
rnf FixityLevel
Unrelated   = ()
  rnf (Related PrecedenceLevel
_) = ()

-- | Associativity.

data Associativity = NonAssoc | LeftAssoc | RightAssoc
   deriving (Associativity -> Associativity -> Bool
(Associativity -> Associativity -> Bool)
-> (Associativity -> Associativity -> Bool) -> Eq Associativity
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: Associativity -> Associativity -> Bool
== :: Associativity -> Associativity -> Bool
$c/= :: Associativity -> Associativity -> Bool
/= :: Associativity -> Associativity -> Bool
Eq, Eq Associativity
Eq Associativity =>
(Associativity -> Associativity -> Ordering)
-> (Associativity -> Associativity -> Bool)
-> (Associativity -> Associativity -> Bool)
-> (Associativity -> Associativity -> Bool)
-> (Associativity -> Associativity -> Bool)
-> (Associativity -> Associativity -> Associativity)
-> (Associativity -> Associativity -> Associativity)
-> Ord Associativity
Associativity -> Associativity -> Bool
Associativity -> Associativity -> Ordering
Associativity -> Associativity -> Associativity
forall a.
Eq a =>
(a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
$ccompare :: Associativity -> Associativity -> Ordering
compare :: Associativity -> Associativity -> Ordering
$c< :: Associativity -> Associativity -> Bool
< :: Associativity -> Associativity -> Bool
$c<= :: Associativity -> Associativity -> Bool
<= :: Associativity -> Associativity -> Bool
$c> :: Associativity -> Associativity -> Bool
> :: Associativity -> Associativity -> Bool
$c>= :: Associativity -> Associativity -> Bool
>= :: Associativity -> Associativity -> Bool
$cmax :: Associativity -> Associativity -> Associativity
max :: Associativity -> Associativity -> Associativity
$cmin :: Associativity -> Associativity -> Associativity
min :: Associativity -> Associativity -> Associativity
Ord, Int -> Associativity -> ShowS
[Associativity] -> ShowS
Associativity -> ArgName
(Int -> Associativity -> ShowS)
-> (Associativity -> ArgName)
-> ([Associativity] -> ShowS)
-> Show Associativity
forall a.
(Int -> a -> ShowS) -> (a -> ArgName) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> Associativity -> ShowS
showsPrec :: Int -> Associativity -> ShowS
$cshow :: Associativity -> ArgName
show :: Associativity -> ArgName
$cshowList :: [Associativity] -> ShowS
showList :: [Associativity] -> ShowS
Show)

-- | Fixity of operators.

data Fixity = Fixity
  { Fixity -> Range
fixityRange :: Range
    -- ^ Range of the whole fixity declaration.
  , Fixity -> FixityLevel
fixityLevel :: !FixityLevel
  , Fixity -> Associativity
fixityAssoc :: !Associativity
  }
  deriving Int -> Fixity -> ShowS
[Fixity] -> ShowS
Fixity -> ArgName
(Int -> Fixity -> ShowS)
-> (Fixity -> ArgName) -> ([Fixity] -> ShowS) -> Show Fixity
forall a.
(Int -> a -> ShowS) -> (a -> ArgName) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> Fixity -> ShowS
showsPrec :: Int -> Fixity -> ShowS
$cshow :: Fixity -> ArgName
show :: Fixity -> ArgName
$cshowList :: [Fixity] -> ShowS
showList :: [Fixity] -> ShowS
Show

noFixity :: Fixity
noFixity :: Fixity
noFixity = Range -> FixityLevel -> Associativity -> Fixity
Fixity Range
forall a. Range' a
noRange FixityLevel
Unrelated Associativity
NonAssoc

defaultFixity :: Fixity
defaultFixity :: Fixity
defaultFixity = Range -> FixityLevel -> Associativity -> Fixity
Fixity Range
forall a. Range' a
noRange (PrecedenceLevel -> FixityLevel
Related PrecedenceLevel
20) Associativity
NonAssoc

-- For @instance Pretty Fixity@, see Agda.Syntax.Concrete.Pretty

instance Eq Fixity where
  Fixity
f1 == :: Fixity -> Fixity -> Bool
== Fixity
f2 = Fixity -> Fixity -> Ordering
forall a. Ord a => a -> a -> Ordering
compare Fixity
f1 Fixity
f2 Ordering -> Ordering -> Bool
forall a. Eq a => a -> a -> Bool
== Ordering
EQ

instance Ord Fixity where
  compare :: Fixity -> Fixity -> Ordering
compare = (FixityLevel, Associativity)
-> (FixityLevel, Associativity) -> Ordering
forall a. Ord a => a -> a -> Ordering
compare ((FixityLevel, Associativity)
 -> (FixityLevel, Associativity) -> Ordering)
-> (Fixity -> (FixityLevel, Associativity))
-> Fixity
-> Fixity
-> Ordering
forall b c a. (b -> b -> c) -> (a -> b) -> a -> a -> c
`on` (Fixity -> FixityLevel
fixityLevel (Fixity -> FixityLevel)
-> (Fixity -> Associativity)
-> Fixity
-> (FixityLevel, Associativity)
forall b c c'. (b -> c) -> (b -> c') -> b -> (c, c')
forall (a :: * -> * -> *) b c c'.
Arrow a =>
a b c -> a b c' -> a b (c, c')
&&& Fixity -> Associativity
fixityAssoc)

instance Null Fixity where
  null :: Fixity -> Bool
null  = FixityLevel -> Bool
forall a. Null a => a -> Bool
null (FixityLevel -> Bool) -> (Fixity -> FixityLevel) -> Fixity -> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Fixity -> FixityLevel
fixityLevel
  empty :: Fixity
empty = Fixity
noFixity

instance HasRange Fixity where
  getRange :: Fixity -> Range
getRange = Fixity -> Range
fixityRange

instance KillRange Fixity where
  killRange :: Fixity -> Fixity
killRange Fixity
f = Fixity
f { fixityRange = noRange }

instance NFData Fixity where
  rnf :: Fixity -> ()
rnf (Fixity Range
_ FixityLevel
_ Associativity
_) = ()     -- Ranges are not forced, the other fields are strict.

-- * Notation coupled with 'Fixity'

-- | The notation is handled as the fixity in the renamer.
--   Hence, they are grouped together in this type.
data Fixity' = Fixity'
    { Fixity' -> Fixity
theFixity   :: !Fixity
    , Fixity' -> Notation
theNotation :: Notation
    , Fixity' -> Range
theNameRange :: Range
      -- ^ Range of the name in the fixity declaration
      --   (used for correct highlighting, see issue #2140).
    }
  deriving Int -> Fixity' -> ShowS
[Fixity'] -> ShowS
Fixity' -> ArgName
(Int -> Fixity' -> ShowS)
-> (Fixity' -> ArgName) -> ([Fixity'] -> ShowS) -> Show Fixity'
forall a.
(Int -> a -> ShowS) -> (a -> ArgName) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> Fixity' -> ShowS
showsPrec :: Int -> Fixity' -> ShowS
$cshow :: Fixity' -> ArgName
show :: Fixity' -> ArgName
$cshowList :: [Fixity'] -> ShowS
showList :: [Fixity'] -> ShowS
Show

noFixity' :: Fixity'
noFixity' :: Fixity'
noFixity' = Fixity -> Notation -> Range -> Fixity'
Fixity' Fixity
noFixity Notation
noNotation Range
forall a. Range' a
noRange

instance Eq Fixity' where
  Fixity' Fixity
f Notation
n Range
_ == :: Fixity' -> Fixity' -> Bool
== Fixity' Fixity
f' Notation
n' Range
_ = Fixity
f Fixity -> Fixity -> Bool
forall a. Eq a => a -> a -> Bool
== Fixity
f' Bool -> Bool -> Bool
&& Notation
n Notation -> Notation -> Bool
forall a. Eq a => a -> a -> Bool
== Notation
n'

instance Null Fixity' where
  null :: Fixity' -> Bool
null (Fixity' Fixity
f Notation
n Range
_) = Fixity -> Bool
forall a. Null a => a -> Bool
null Fixity
f Bool -> Bool -> Bool
&& Notation -> Bool
forall a. Null a => a -> Bool
null Notation
n
  empty :: Fixity'
empty = Fixity'
noFixity'

instance NFData Fixity' where
  rnf :: Fixity' -> ()
rnf (Fixity' Fixity
_ Notation
a Range
_) = Notation -> ()
forall a. NFData a => a -> ()
rnf Notation
a

instance KillRange Fixity' where
  killRange :: KillRangeT Fixity'
killRange (Fixity' Fixity
f Notation
n Range
r) = (Fixity -> Notation -> Range -> Fixity')
-> Fixity -> Notation -> Range -> Fixity'
forall t (b :: Bool).
(KILLRANGE t b, IsBase t ~ b, All KillRange (Domains t)) =>
t -> t
killRangeN Fixity -> Notation -> Range -> Fixity'
Fixity' Fixity
f Notation
n Range
r

-- lenses

_fixityAssoc :: Lens' Fixity Associativity
_fixityAssoc :: Lens' Fixity Associativity
_fixityAssoc Associativity -> f Associativity
f Fixity
r = Associativity -> f Associativity
f (Fixity -> Associativity
fixityAssoc Fixity
r) f Associativity -> (Associativity -> Fixity) -> f Fixity
forall (m :: * -> *) a b. Functor m => m a -> (a -> b) -> m b
<&> \Associativity
x -> Fixity
r { fixityAssoc = x }

_fixityLevel :: Lens' Fixity FixityLevel
_fixityLevel :: Lens' Fixity FixityLevel
_fixityLevel FixityLevel -> f FixityLevel
f Fixity
r = FixityLevel -> f FixityLevel
f (Fixity -> FixityLevel
fixityLevel Fixity
r) f FixityLevel -> (FixityLevel -> Fixity) -> f Fixity
forall (m :: * -> *) a b. Functor m => m a -> (a -> b) -> m b
<&> \FixityLevel
x -> Fixity
r { fixityLevel = x }

-- Lens focusing on Fixity

class LensFixity a where
  lensFixity :: Lens' a Fixity

instance LensFixity Fixity where
  lensFixity :: Lens' Fixity Fixity
lensFixity = (Fixity -> f Fixity) -> Fixity -> f Fixity
forall a. a -> a
id

instance LensFixity Fixity' where
  lensFixity :: Lens' Fixity' Fixity
lensFixity Fixity -> f Fixity
f Fixity'
fix' = Fixity -> f Fixity
f (Fixity' -> Fixity
theFixity Fixity'
fix') f Fixity -> (Fixity -> Fixity') -> f Fixity'
forall (m :: * -> *) a b. Functor m => m a -> (a -> b) -> m b
<&> \ Fixity
fx -> Fixity'
fix' { theFixity = fx }

-- Lens focusing on Fixity'

class LensFixity' a where
  lensFixity' :: Lens' a Fixity'

instance LensFixity' Fixity' where
  lensFixity' :: Lens' Fixity' Fixity'
lensFixity' = (Fixity' -> f Fixity') -> Fixity' -> f Fixity'
forall a. a -> a
id
---------------------------------------------------------------------------
-- * Import directive
---------------------------------------------------------------------------

-- | The things you are allowed to say when you shuffle names between name
--   spaces (i.e. in @import@, @namespace@, or @open@ declarations).
data ImportDirective' n m = ImportDirective
  { forall n m. ImportDirective' n m -> Range
importDirRange :: Range
  , forall n m. ImportDirective' n m -> Using' n m
using          :: Using' n m
  , forall n m. ImportDirective' n m -> HidingDirective' n m
hiding         :: HidingDirective' n m
  , forall n m. ImportDirective' n m -> RenamingDirective' n m
impRenaming    :: RenamingDirective' n m
  , forall n m. ImportDirective' n m -> Maybe Range
publicOpen     :: Maybe Range -- ^ Only for @open@. Exports the opened names from the current module.
  }
  deriving ImportDirective' n m -> ImportDirective' n m -> Bool
(ImportDirective' n m -> ImportDirective' n m -> Bool)
-> (ImportDirective' n m -> ImportDirective' n m -> Bool)
-> Eq (ImportDirective' n m)
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
forall n m.
(Eq m, Eq n) =>
ImportDirective' n m -> ImportDirective' n m -> Bool
$c== :: forall n m.
(Eq m, Eq n) =>
ImportDirective' n m -> ImportDirective' n m -> Bool
== :: ImportDirective' n m -> ImportDirective' n m -> Bool
$c/= :: forall n m.
(Eq m, Eq n) =>
ImportDirective' n m -> ImportDirective' n m -> Bool
/= :: ImportDirective' n m -> ImportDirective' n m -> Bool
Eq

type HidingDirective'   n m = [ImportedName' n m]
type RenamingDirective' n m = [Renaming' n m]

-- | @null@ for import directives holds when everything is imported unchanged
--   (no names are hidden or renamed).
instance Null (ImportDirective' n m) where
  null :: ImportDirective' n m -> Bool
null = \case
    ImportDirective Range
_ Using' n m
UseEverything [] [] Maybe Range
_ -> Bool
True
    ImportDirective' n m
_ -> Bool
False
  empty :: ImportDirective' n m
empty = ImportDirective' n m
forall n m. ImportDirective' n m
defaultImportDir

instance (HasRange n, HasRange m) => Semigroup (ImportDirective' n m) where
  ImportDirective' n m
i1 <> :: ImportDirective' n m
-> ImportDirective' n m -> ImportDirective' n m
<> ImportDirective' n m
i2 = ImportDirective
    { importDirRange :: Range
importDirRange = ImportDirective' n m -> ImportDirective' n m -> Range
forall u t. (HasRange u, HasRange t) => u -> t -> Range
fuseRange ImportDirective' n m
i1 ImportDirective' n m
i2
    , using :: Using' n m
using          = ImportDirective' n m -> Using' n m
forall n m. ImportDirective' n m -> Using' n m
using ImportDirective' n m
i1 Using' n m -> Using' n m -> Using' n m
forall a. Semigroup a => a -> a -> a
<> ImportDirective' n m -> Using' n m
forall n m. ImportDirective' n m -> Using' n m
using ImportDirective' n m
i2
    , hiding :: HidingDirective' n m
hiding         = ImportDirective' n m -> HidingDirective' n m
forall n m. ImportDirective' n m -> HidingDirective' n m
hiding ImportDirective' n m
i1 HidingDirective' n m
-> HidingDirective' n m -> HidingDirective' n m
forall a. [a] -> [a] -> [a]
++ ImportDirective' n m -> HidingDirective' n m
forall n m. ImportDirective' n m -> HidingDirective' n m
hiding ImportDirective' n m
i2
    , impRenaming :: RenamingDirective' n m
impRenaming    = ImportDirective' n m -> RenamingDirective' n m
forall n m. ImportDirective' n m -> RenamingDirective' n m
impRenaming ImportDirective' n m
i1 RenamingDirective' n m
-> RenamingDirective' n m -> RenamingDirective' n m
forall a. [a] -> [a] -> [a]
++ ImportDirective' n m -> RenamingDirective' n m
forall n m. ImportDirective' n m -> RenamingDirective' n m
impRenaming ImportDirective' n m
i2
    , publicOpen :: Maybe Range
publicOpen     = ImportDirective' n m -> Maybe Range
forall n m. ImportDirective' n m -> Maybe Range
publicOpen ImportDirective' n m
i1 Maybe Range -> Maybe Range -> Maybe Range
forall a. Maybe a -> Maybe a -> Maybe a
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> ImportDirective' n m -> Maybe Range
forall n m. ImportDirective' n m -> Maybe Range
publicOpen ImportDirective' n m
i2
    }

instance (HasRange n, HasRange m) => Monoid (ImportDirective' n m) where
  mempty :: ImportDirective' n m
mempty  = ImportDirective' n m
forall a. Null a => a
empty
  mappend :: ImportDirective' n m
-> ImportDirective' n m -> ImportDirective' n m
mappend = ImportDirective' n m
-> ImportDirective' n m -> ImportDirective' n m
forall a. Semigroup a => a -> a -> a
(<>)

-- | Default is directive is @private@ (use everything, but do not export).
defaultImportDir :: ImportDirective' n m
defaultImportDir :: forall n m. ImportDirective' n m
defaultImportDir = Range
-> Using' n m
-> HidingDirective' n m
-> RenamingDirective' n m
-> Maybe Range
-> ImportDirective' n m
forall n m.
Range
-> Using' n m
-> HidingDirective' n m
-> RenamingDirective' n m
-> Maybe Range
-> ImportDirective' n m
ImportDirective Range
forall a. Range' a
noRange Using' n m
forall n m. Using' n m
UseEverything [] [] Maybe Range
forall a. Maybe a
Nothing

-- | @isDefaultImportDir@ implies @null@, but not the other way round.
isDefaultImportDir :: ImportDirective' n m -> Bool
isDefaultImportDir :: forall n m. ImportDirective' n m -> Bool
isDefaultImportDir ImportDirective' n m
dir = ImportDirective' n m -> Bool
forall a. Null a => a -> Bool
null ImportDirective' n m
dir Bool -> Bool -> Bool
&& Maybe Range -> Bool
forall a. Null a => a -> Bool
null (ImportDirective' n m -> Maybe Range
forall n m. ImportDirective' n m -> Maybe Range
publicOpen ImportDirective' n m
dir)

-- | The @using@ clause of import directive.
data Using' n m
  = UseEverything              -- ^ No @using@ clause given.
  | Using [ImportedName' n m]  -- ^ @using@ the specified names.
  deriving Using' n m -> Using' n m -> Bool
(Using' n m -> Using' n m -> Bool)
-> (Using' n m -> Using' n m -> Bool) -> Eq (Using' n m)
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
forall n m. (Eq m, Eq n) => Using' n m -> Using' n m -> Bool
$c== :: forall n m. (Eq m, Eq n) => Using' n m -> Using' n m -> Bool
== :: Using' n m -> Using' n m -> Bool
$c/= :: forall n m. (Eq m, Eq n) => Using' n m -> Using' n m -> Bool
/= :: Using' n m -> Using' n m -> Bool
Eq

instance Semigroup (Using' n m) where
  Using' n m
UseEverything <> :: Using' n m -> Using' n m -> Using' n m
<> Using' n m
u             = Using' n m
u
  Using' n m
u             <> Using' n m
UseEverything = Using' n m
u
  Using [ImportedName' n m]
xs      <> Using [ImportedName' n m]
ys      = [ImportedName' n m] -> Using' n m
forall n m. [ImportedName' n m] -> Using' n m
Using ([ImportedName' n m]
xs [ImportedName' n m] -> [ImportedName' n m] -> [ImportedName' n m]
forall a. [a] -> [a] -> [a]
++ [ImportedName' n m]
ys)

instance Monoid (Using' n m) where
  mempty :: Using' n m
mempty  = Using' n m
forall n m. Using' n m
UseEverything
  mappend :: Using' n m -> Using' n m -> Using' n m
mappend = Using' n m -> Using' n m -> Using' n m
forall a. Semigroup a => a -> a -> a
(<>)

instance Null (Using' n m) where
  null :: Using' n m -> Bool
null Using' n m
UseEverything = Bool
True
  null Using{}       = Bool
False
  empty :: Using' n m
empty = Using' n m
forall a. Monoid a => a
mempty

mapUsing :: ([ImportedName' n1 m1] -> [ImportedName' n2 m2]) -> Using' n1 m1 -> Using' n2 m2
mapUsing :: forall n1 m1 n2 m2.
([ImportedName' n1 m1] -> [ImportedName' n2 m2])
-> Using' n1 m1 -> Using' n2 m2
mapUsing [ImportedName' n1 m1] -> [ImportedName' n2 m2]
f = \case
  Using' n1 m1
UseEverything -> Using' n2 m2
forall n m. Using' n m
UseEverything
  Using [ImportedName' n1 m1]
xs      -> [ImportedName' n2 m2] -> Using' n2 m2
forall n m. [ImportedName' n m] -> Using' n m
Using ([ImportedName' n2 m2] -> Using' n2 m2)
-> [ImportedName' n2 m2] -> Using' n2 m2
forall a b. (a -> b) -> a -> b
$ [ImportedName' n1 m1] -> [ImportedName' n2 m2]
f [ImportedName' n1 m1]
xs

-- | An imported name can be a module or a defined name.
data ImportedName' n m
  = ImportedModule  m  -- ^ Imported module name of type @m@.
  | ImportedName    n  -- ^ Imported name of type @n@.
  deriving (ImportedName' n m -> ImportedName' n m -> Bool
(ImportedName' n m -> ImportedName' n m -> Bool)
-> (ImportedName' n m -> ImportedName' n m -> Bool)
-> Eq (ImportedName' n m)
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
forall n m.
(Eq m, Eq n) =>
ImportedName' n m -> ImportedName' n m -> Bool
$c== :: forall n m.
(Eq m, Eq n) =>
ImportedName' n m -> ImportedName' n m -> Bool
== :: ImportedName' n m -> ImportedName' n m -> Bool
$c/= :: forall n m.
(Eq m, Eq n) =>
ImportedName' n m -> ImportedName' n m -> Bool
/= :: ImportedName' n m -> ImportedName' n m -> Bool
Eq, Eq (ImportedName' n m)
Eq (ImportedName' n m) =>
(ImportedName' n m -> ImportedName' n m -> Ordering)
-> (ImportedName' n m -> ImportedName' n m -> Bool)
-> (ImportedName' n m -> ImportedName' n m -> Bool)
-> (ImportedName' n m -> ImportedName' n m -> Bool)
-> (ImportedName' n m -> ImportedName' n m -> Bool)
-> (ImportedName' n m -> ImportedName' n m -> ImportedName' n m)
-> (ImportedName' n m -> ImportedName' n m -> ImportedName' n m)
-> Ord (ImportedName' n m)
ImportedName' n m -> ImportedName' n m -> Bool
ImportedName' n m -> ImportedName' n m -> Ordering
ImportedName' n m -> ImportedName' n m -> ImportedName' n m
forall a.
Eq a =>
(a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
forall n m. (Ord m, Ord n) => Eq (ImportedName' n m)
forall n m.
(Ord m, Ord n) =>
ImportedName' n m -> ImportedName' n m -> Bool
forall n m.
(Ord m, Ord n) =>
ImportedName' n m -> ImportedName' n m -> Ordering
forall n m.
(Ord m, Ord n) =>
ImportedName' n m -> ImportedName' n m -> ImportedName' n m
$ccompare :: forall n m.
(Ord m, Ord n) =>
ImportedName' n m -> ImportedName' n m -> Ordering
compare :: ImportedName' n m -> ImportedName' n m -> Ordering
$c< :: forall n m.
(Ord m, Ord n) =>
ImportedName' n m -> ImportedName' n m -> Bool
< :: ImportedName' n m -> ImportedName' n m -> Bool
$c<= :: forall n m.
(Ord m, Ord n) =>
ImportedName' n m -> ImportedName' n m -> Bool
<= :: ImportedName' n m -> ImportedName' n m -> Bool
$c> :: forall n m.
(Ord m, Ord n) =>
ImportedName' n m -> ImportedName' n m -> Bool
> :: ImportedName' n m -> ImportedName' n m -> Bool
$c>= :: forall n m.
(Ord m, Ord n) =>
ImportedName' n m -> ImportedName' n m -> Bool
>= :: ImportedName' n m -> ImportedName' n m -> Bool
$cmax :: forall n m.
(Ord m, Ord n) =>
ImportedName' n m -> ImportedName' n m -> ImportedName' n m
max :: ImportedName' n m -> ImportedName' n m -> ImportedName' n m
$cmin :: forall n m.
(Ord m, Ord n) =>
ImportedName' n m -> ImportedName' n m -> ImportedName' n m
min :: ImportedName' n m -> ImportedName' n m -> ImportedName' n m
Ord, Int -> ImportedName' n m -> ShowS
[ImportedName' n m] -> ShowS
ImportedName' n m -> ArgName
(Int -> ImportedName' n m -> ShowS)
-> (ImportedName' n m -> ArgName)
-> ([ImportedName' n m] -> ShowS)
-> Show (ImportedName' n m)
forall a.
(Int -> a -> ShowS) -> (a -> ArgName) -> ([a] -> ShowS) -> Show a
forall n m. (Show m, Show n) => Int -> ImportedName' n m -> ShowS
forall n m. (Show m, Show n) => [ImportedName' n m] -> ShowS
forall n m. (Show m, Show n) => ImportedName' n m -> ArgName
$cshowsPrec :: forall n m. (Show m, Show n) => Int -> ImportedName' n m -> ShowS
showsPrec :: Int -> ImportedName' n m -> ShowS
$cshow :: forall n m. (Show m, Show n) => ImportedName' n m -> ArgName
show :: ImportedName' n m -> ArgName
$cshowList :: forall n m. (Show m, Show n) => [ImportedName' n m] -> ShowS
showList :: [ImportedName' n m] -> ShowS
Show)

fromImportedName :: ImportedName' a a -> a
fromImportedName :: forall a. ImportedName' a a -> a
fromImportedName = \case
  ImportedModule a
x -> a
x
  ImportedName   a
x -> a
x

setImportedName :: ImportedName' a a -> a -> ImportedName' a a
setImportedName :: forall a. ImportedName' a a -> a -> ImportedName' a a
setImportedName (ImportedName   a
x) a
y = a -> ImportedName' a a
forall n m. n -> ImportedName' n m
ImportedName   a
y
setImportedName (ImportedModule a
x) a
y = a -> ImportedName' a a
forall n m. m -> ImportedName' n m
ImportedModule a
y

-- | Like 'partitionEithers'.
partitionImportedNames :: [ImportedName' n m] -> ([n], [m])
partitionImportedNames :: forall n m. [ImportedName' n m] -> ([n], [m])
partitionImportedNames = ((ImportedName' n m -> ([n], [m]) -> ([n], [m]))
 -> ([n], [m]) -> [ImportedName' n m] -> ([n], [m]))
-> ([n], [m])
-> (ImportedName' n m -> ([n], [m]) -> ([n], [m]))
-> [ImportedName' n m]
-> ([n], [m])
forall a b c. (a -> b -> c) -> b -> a -> c
flip (ImportedName' n m -> ([n], [m]) -> ([n], [m]))
-> ([n], [m]) -> [ImportedName' n m] -> ([n], [m])
forall a b. (a -> b -> b) -> b -> [a] -> b
forall (t :: * -> *) a b.
Foldable t =>
(a -> b -> b) -> b -> t a -> b
foldr ([], []) ((ImportedName' n m -> ([n], [m]) -> ([n], [m]))
 -> [ImportedName' n m] -> ([n], [m]))
-> (ImportedName' n m -> ([n], [m]) -> ([n], [m]))
-> [ImportedName' n m]
-> ([n], [m])
forall a b. (a -> b) -> a -> b
$ \case
  ImportedName   n
n -> ([n] -> [n]) -> ([n], [m]) -> ([n], [m])
forall a b c. (a -> b) -> (a, c) -> (b, c)
forall (p :: * -> * -> *) a b c.
Bifunctor p =>
(a -> b) -> p a c -> p b c
first  (n
nn -> [n] -> [n]
forall a. a -> [a] -> [a]
:)
  ImportedModule m
m -> ([m] -> [m]) -> ([n], [m]) -> ([n], [m])
forall b c a. (b -> c) -> (a, b) -> (a, c)
forall (p :: * -> * -> *) b c a.
Bifunctor p =>
(b -> c) -> p a b -> p a c
second (m
mm -> [m] -> [m]
forall a. a -> [a] -> [a]
:)

-- -- Defined in Concrete.Pretty
-- instance (Pretty n, Pretty m) => Pretty (ImportedName' n m) where
--   pretty (ImportedModule x) = "module" <+> pretty x
--   pretty (ImportedName   x) = pretty x

-- instance (Show n, Show m) => Show (ImportedName' n m) where
--   show (ImportedModule x) = "module " ++ show x
--   show (ImportedName   x) = show x

data Renaming' n m = Renaming
  { forall n m. Renaming' n m -> ImportedName' n m
renFrom    :: ImportedName' n m
    -- ^ Rename from this name.
  , forall n m. Renaming' n m -> ImportedName' n m
renTo      :: ImportedName' n m
    -- ^ To this one.  Must be same kind as 'renFrom'.
  , forall n m. Renaming' n m -> Maybe Fixity
renFixity  :: Maybe Fixity
    -- ^ New fixity of 'renTo' (optional).
  , forall n m. Renaming' n m -> Range
renToRange :: Range
    -- ^ The range of the \"to\" keyword.  Retained for highlighting purposes.
  }
  deriving Renaming' n m -> Renaming' n m -> Bool
(Renaming' n m -> Renaming' n m -> Bool)
-> (Renaming' n m -> Renaming' n m -> Bool) -> Eq (Renaming' n m)
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
forall n m. (Eq m, Eq n) => Renaming' n m -> Renaming' n m -> Bool
$c== :: forall n m. (Eq m, Eq n) => Renaming' n m -> Renaming' n m -> Bool
== :: Renaming' n m -> Renaming' n m -> Bool
$c/= :: forall n m. (Eq m, Eq n) => Renaming' n m -> Renaming' n m -> Bool
/= :: Renaming' n m -> Renaming' n m -> Bool
Eq

-- ** HasRange instances

instance (HasRange a, HasRange b) => HasRange (ImportDirective' a b) where
  getRange :: ImportDirective' a b -> Range
getRange = ImportDirective' a b -> Range
forall n m. ImportDirective' n m -> Range
importDirRange

instance (HasRange a, HasRange b) => HasRange (Using' a b) where
  getRange :: Using' a b -> Range
getRange (Using  [ImportedName' a b]
xs) = [ImportedName' a b] -> Range
forall a. HasRange a => a -> Range
getRange [ImportedName' a b]
xs
  getRange Using' a b
UseEverything = Range
forall a. Range' a
noRange

instance (HasRange a, HasRange b) => HasRange (Renaming' a b) where
  getRange :: Renaming' a b -> Range
getRange Renaming' a b
r = (ImportedName' a b, ImportedName' a b) -> Range
forall a. HasRange a => a -> Range
getRange (Renaming' a b -> ImportedName' a b
forall n m. Renaming' n m -> ImportedName' n m
renFrom Renaming' a b
r, Renaming' a b -> ImportedName' a b
forall n m. Renaming' n m -> ImportedName' n m
renTo Renaming' a b
r)

instance (HasRange a, HasRange b) => HasRange (ImportedName' a b) where
  getRange :: ImportedName' a b -> Range
getRange (ImportedName   a
x) = a -> Range
forall a. HasRange a => a -> Range
getRange a
x
  getRange (ImportedModule b
x) = b -> Range
forall a. HasRange a => a -> Range
getRange b
x

-- ** KillRange instances

instance (KillRange a, KillRange b) => KillRange (ImportDirective' a b) where
  killRange :: KillRangeT (ImportDirective' a b)
killRange (ImportDirective Range
_ Using' a b
u HidingDirective' a b
h RenamingDirective' a b
r Maybe Range
p) =
    (Using' a b
 -> HidingDirective' a b
 -> RenamingDirective' a b
 -> ImportDirective' a b)
-> Using' a b
-> HidingDirective' a b
-> RenamingDirective' a b
-> ImportDirective' a b
forall t (b :: Bool).
(KILLRANGE t b, IsBase t ~ b, All KillRange (Domains t)) =>
t -> t
killRangeN (\Using' a b
u HidingDirective' a b
h RenamingDirective' a b
r -> Range
-> Using' a b
-> HidingDirective' a b
-> RenamingDirective' a b
-> Maybe Range
-> ImportDirective' a b
forall n m.
Range
-> Using' n m
-> HidingDirective' n m
-> RenamingDirective' n m
-> Maybe Range
-> ImportDirective' n m
ImportDirective Range
forall a. Range' a
noRange Using' a b
u HidingDirective' a b
h RenamingDirective' a b
r Maybe Range
p) Using' a b
u HidingDirective' a b
h RenamingDirective' a b
r

instance (KillRange a, KillRange b) => KillRange (Using' a b) where
  killRange :: KillRangeT (Using' a b)
killRange (Using  [ImportedName' a b]
i) = ([ImportedName' a b] -> Using' a b)
-> [ImportedName' a b] -> Using' a b
forall t (b :: Bool).
(KILLRANGE t b, IsBase t ~ b, All KillRange (Domains t)) =>
t -> t
killRangeN [ImportedName' a b] -> Using' a b
forall n m. [ImportedName' n m] -> Using' n m
Using  [ImportedName' a b]
i
  killRange Using' a b
UseEverything = Using' a b
forall n m. Using' n m
UseEverything

instance (KillRange a, KillRange b) => KillRange (Renaming' a b) where
  killRange :: KillRangeT (Renaming' a b)
killRange (Renaming ImportedName' a b
i ImportedName' a b
n Maybe Fixity
mf Range
_to) = (ImportedName' a b
 -> ImportedName' a b -> Maybe Fixity -> Renaming' a b)
-> ImportedName' a b
-> ImportedName' a b
-> Maybe Fixity
-> Renaming' a b
forall t (b :: Bool).
(KILLRANGE t b, IsBase t ~ b, All KillRange (Domains t)) =>
t -> t
killRangeN (\ ImportedName' a b
i ImportedName' a b
n Maybe Fixity
mf -> ImportedName' a b
-> ImportedName' a b -> Maybe Fixity -> Range -> Renaming' a b
forall n m.
ImportedName' n m
-> ImportedName' n m -> Maybe Fixity -> Range -> Renaming' n m
Renaming ImportedName' a b
i ImportedName' a b
n Maybe Fixity
mf Range
forall a. Range' a
noRange) ImportedName' a b
i ImportedName' a b
n Maybe Fixity
mf

instance (KillRange a, KillRange b) => KillRange (ImportedName' a b) where
  killRange :: KillRangeT (ImportedName' a b)
killRange (ImportedModule b
n) = (b -> ImportedName' a b) -> b -> ImportedName' a b
forall t (b :: Bool).
(KILLRANGE t b, IsBase t ~ b, All KillRange (Domains t)) =>
t -> t
killRangeN b -> ImportedName' a b
forall n m. m -> ImportedName' n m
ImportedModule b
n
  killRange (ImportedName   a
n) = (a -> ImportedName' a b) -> a -> ImportedName' a b
forall t (b :: Bool).
(KILLRANGE t b, IsBase t ~ b, All KillRange (Domains t)) =>
t -> t
killRangeN a -> ImportedName' a b
forall n m. n -> ImportedName' n m
ImportedName   a
n

-- ** NFData instances

-- | Ranges are not forced.

instance (NFData a, NFData b) => NFData (ImportDirective' a b) where
  rnf :: ImportDirective' a b -> ()
rnf (ImportDirective Range
_ Using' a b
a HidingDirective' a b
b RenamingDirective' a b
c Maybe Range
_) = Using' a b -> ()
forall a. NFData a => a -> ()
rnf Using' a b
a () -> () -> ()
forall a b. a -> b -> b
`seq` HidingDirective' a b -> ()
forall a. NFData a => a -> ()
rnf HidingDirective' a b
b () -> () -> ()
forall a b. a -> b -> b
`seq` RenamingDirective' a b -> ()
forall a. NFData a => a -> ()
rnf RenamingDirective' a b
c

instance (NFData a, NFData b) => NFData (Using' a b) where
  rnf :: Using' a b -> ()
rnf Using' a b
UseEverything = ()
  rnf (Using [ImportedName' a b]
a)     = [ImportedName' a b] -> ()
forall a. NFData a => a -> ()
rnf [ImportedName' a b]
a

-- | Ranges are not forced.

instance (NFData a, NFData b) => NFData (Renaming' a b) where
  rnf :: Renaming' a b -> ()
rnf (Renaming ImportedName' a b
a ImportedName' a b
b Maybe Fixity
c Range
_) = ImportedName' a b -> ()
forall a. NFData a => a -> ()
rnf ImportedName' a b
a () -> () -> ()
forall a b. a -> b -> b
`seq` ImportedName' a b -> ()
forall a. NFData a => a -> ()
rnf ImportedName' a b
b () -> () -> ()
forall a b. a -> b -> b
`seq` Maybe Fixity -> ()
forall a. NFData a => a -> ()
rnf Maybe Fixity
c

instance (NFData a, NFData b) => NFData (ImportedName' a b) where
  rnf :: ImportedName' a b -> ()
rnf (ImportedModule b
a) = b -> ()
forall a. NFData a => a -> ()
rnf b
a
  rnf (ImportedName a
a)   = a -> ()
forall a. NFData a => a -> ()
rnf a
a

-----------------------------------------------------------------------------
-- * Termination
-----------------------------------------------------------------------------

-- | Termination check? (Default = TerminationCheck).
data TerminationCheck m
  = TerminationCheck
    -- ^ Run the termination checker.
  | NoTerminationCheck
    -- ^ Skip termination checking (unsafe).
  | NonTerminating
    -- ^ Treat as non-terminating.
  | Terminating
    -- ^ Treat as terminating (unsafe).  Same effect as 'NoTerminationCheck'.
  | TerminationMeasure Range m
    -- ^ Skip termination checking but use measure instead.
    deriving (Int -> TerminationCheck m -> ShowS
[TerminationCheck m] -> ShowS
TerminationCheck m -> ArgName
(Int -> TerminationCheck m -> ShowS)
-> (TerminationCheck m -> ArgName)
-> ([TerminationCheck m] -> ShowS)
-> Show (TerminationCheck m)
forall m. Show m => Int -> TerminationCheck m -> ShowS
forall m. Show m => [TerminationCheck m] -> ShowS
forall m. Show m => TerminationCheck m -> ArgName
forall a.
(Int -> a -> ShowS) -> (a -> ArgName) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: forall m. Show m => Int -> TerminationCheck m -> ShowS
showsPrec :: Int -> TerminationCheck m -> ShowS
$cshow :: forall m. Show m => TerminationCheck m -> ArgName
show :: TerminationCheck m -> ArgName
$cshowList :: forall m. Show m => [TerminationCheck m] -> ShowS
showList :: [TerminationCheck m] -> ShowS
Show, TerminationCheck m -> TerminationCheck m -> Bool
(TerminationCheck m -> TerminationCheck m -> Bool)
-> (TerminationCheck m -> TerminationCheck m -> Bool)
-> Eq (TerminationCheck m)
forall m. Eq m => TerminationCheck m -> TerminationCheck m -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: forall m. Eq m => TerminationCheck m -> TerminationCheck m -> Bool
== :: TerminationCheck m -> TerminationCheck m -> Bool
$c/= :: forall m. Eq m => TerminationCheck m -> TerminationCheck m -> Bool
/= :: TerminationCheck m -> TerminationCheck m -> Bool
Eq, (forall a b. (a -> b) -> TerminationCheck a -> TerminationCheck b)
-> (forall a b. a -> TerminationCheck b -> TerminationCheck a)
-> Functor TerminationCheck
forall a b. a -> TerminationCheck b -> TerminationCheck a
forall a b. (a -> b) -> TerminationCheck a -> TerminationCheck b
forall (f :: * -> *).
(forall a b. (a -> b) -> f a -> f b)
-> (forall a b. a -> f b -> f a) -> Functor f
$cfmap :: forall a b. (a -> b) -> TerminationCheck a -> TerminationCheck b
fmap :: forall a b. (a -> b) -> TerminationCheck a -> TerminationCheck b
$c<$ :: forall a b. a -> TerminationCheck b -> TerminationCheck a
<$ :: forall a b. a -> TerminationCheck b -> TerminationCheck a
Functor)

instance KillRange m => KillRange (TerminationCheck m) where
  killRange :: KillRangeT (TerminationCheck m)
killRange (TerminationMeasure Range
_ m
m) = Range -> m -> TerminationCheck m
forall m. Range -> m -> TerminationCheck m
TerminationMeasure Range
forall a. Range' a
noRange (KillRangeT m
forall a. KillRange a => KillRangeT a
killRange m
m)
  killRange TerminationCheck m
t                        = TerminationCheck m
t

instance NFData a => NFData (TerminationCheck a) where
  rnf :: TerminationCheck a -> ()
rnf TerminationCheck a
TerminationCheck         = ()
  rnf TerminationCheck a
NoTerminationCheck       = ()
  rnf TerminationCheck a
NonTerminating           = ()
  rnf TerminationCheck a
Terminating              = ()
  rnf (TerminationMeasure Range
_ a
a) = a -> ()
forall a. NFData a => a -> ()
rnf a
a

-----------------------------------------------------------------------------
-- * Positivity
-----------------------------------------------------------------------------

-- | Positivity check? (Default = True).
data PositivityCheck = YesPositivityCheck | NoPositivityCheck
  deriving (PositivityCheck -> PositivityCheck -> Bool
(PositivityCheck -> PositivityCheck -> Bool)
-> (PositivityCheck -> PositivityCheck -> Bool)
-> Eq PositivityCheck
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: PositivityCheck -> PositivityCheck -> Bool
== :: PositivityCheck -> PositivityCheck -> Bool
$c/= :: PositivityCheck -> PositivityCheck -> Bool
/= :: PositivityCheck -> PositivityCheck -> Bool
Eq, Eq PositivityCheck
Eq PositivityCheck =>
(PositivityCheck -> PositivityCheck -> Ordering)
-> (PositivityCheck -> PositivityCheck -> Bool)
-> (PositivityCheck -> PositivityCheck -> Bool)
-> (PositivityCheck -> PositivityCheck -> Bool)
-> (PositivityCheck -> PositivityCheck -> Bool)
-> (PositivityCheck -> PositivityCheck -> PositivityCheck)
-> (PositivityCheck -> PositivityCheck -> PositivityCheck)
-> Ord PositivityCheck
PositivityCheck -> PositivityCheck -> Bool
PositivityCheck -> PositivityCheck -> Ordering
PositivityCheck -> PositivityCheck -> PositivityCheck
forall a.
Eq a =>
(a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
$ccompare :: PositivityCheck -> PositivityCheck -> Ordering
compare :: PositivityCheck -> PositivityCheck -> Ordering
$c< :: PositivityCheck -> PositivityCheck -> Bool
< :: PositivityCheck -> PositivityCheck -> Bool
$c<= :: PositivityCheck -> PositivityCheck -> Bool
<= :: PositivityCheck -> PositivityCheck -> Bool
$c> :: PositivityCheck -> PositivityCheck -> Bool
> :: PositivityCheck -> PositivityCheck -> Bool
$c>= :: PositivityCheck -> PositivityCheck -> Bool
>= :: PositivityCheck -> PositivityCheck -> Bool
$cmax :: PositivityCheck -> PositivityCheck -> PositivityCheck
max :: PositivityCheck -> PositivityCheck -> PositivityCheck
$cmin :: PositivityCheck -> PositivityCheck -> PositivityCheck
min :: PositivityCheck -> PositivityCheck -> PositivityCheck
Ord, Int -> PositivityCheck -> ShowS
[PositivityCheck] -> ShowS
PositivityCheck -> ArgName
(Int -> PositivityCheck -> ShowS)
-> (PositivityCheck -> ArgName)
-> ([PositivityCheck] -> ShowS)
-> Show PositivityCheck
forall a.
(Int -> a -> ShowS) -> (a -> ArgName) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> PositivityCheck -> ShowS
showsPrec :: Int -> PositivityCheck -> ShowS
$cshow :: PositivityCheck -> ArgName
show :: PositivityCheck -> ArgName
$cshowList :: [PositivityCheck] -> ShowS
showList :: [PositivityCheck] -> ShowS
Show, PositivityCheck
PositivityCheck -> PositivityCheck -> Bounded PositivityCheck
forall a. a -> a -> Bounded a
$cminBound :: PositivityCheck
minBound :: PositivityCheck
$cmaxBound :: PositivityCheck
maxBound :: PositivityCheck
Bounded, Int -> PositivityCheck
PositivityCheck -> Int
PositivityCheck -> [PositivityCheck]
PositivityCheck -> PositivityCheck
PositivityCheck -> PositivityCheck -> [PositivityCheck]
PositivityCheck
-> PositivityCheck -> PositivityCheck -> [PositivityCheck]
(PositivityCheck -> PositivityCheck)
-> (PositivityCheck -> PositivityCheck)
-> (Int -> PositivityCheck)
-> (PositivityCheck -> Int)
-> (PositivityCheck -> [PositivityCheck])
-> (PositivityCheck -> PositivityCheck -> [PositivityCheck])
-> (PositivityCheck -> PositivityCheck -> [PositivityCheck])
-> (PositivityCheck
    -> PositivityCheck -> PositivityCheck -> [PositivityCheck])
-> Enum PositivityCheck
forall a.
(a -> a)
-> (a -> a)
-> (Int -> a)
-> (a -> Int)
-> (a -> [a])
-> (a -> a -> [a])
-> (a -> a -> [a])
-> (a -> a -> a -> [a])
-> Enum a
$csucc :: PositivityCheck -> PositivityCheck
succ :: PositivityCheck -> PositivityCheck
$cpred :: PositivityCheck -> PositivityCheck
pred :: PositivityCheck -> PositivityCheck
$ctoEnum :: Int -> PositivityCheck
toEnum :: Int -> PositivityCheck
$cfromEnum :: PositivityCheck -> Int
fromEnum :: PositivityCheck -> Int
$cenumFrom :: PositivityCheck -> [PositivityCheck]
enumFrom :: PositivityCheck -> [PositivityCheck]
$cenumFromThen :: PositivityCheck -> PositivityCheck -> [PositivityCheck]
enumFromThen :: PositivityCheck -> PositivityCheck -> [PositivityCheck]
$cenumFromTo :: PositivityCheck -> PositivityCheck -> [PositivityCheck]
enumFromTo :: PositivityCheck -> PositivityCheck -> [PositivityCheck]
$cenumFromThenTo :: PositivityCheck
-> PositivityCheck -> PositivityCheck -> [PositivityCheck]
enumFromThenTo :: PositivityCheck
-> PositivityCheck -> PositivityCheck -> [PositivityCheck]
Enum, (forall x. PositivityCheck -> Rep PositivityCheck x)
-> (forall x. Rep PositivityCheck x -> PositivityCheck)
-> Generic PositivityCheck
forall x. Rep PositivityCheck x -> PositivityCheck
forall x. PositivityCheck -> Rep PositivityCheck x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cfrom :: forall x. PositivityCheck -> Rep PositivityCheck x
from :: forall x. PositivityCheck -> Rep PositivityCheck x
$cto :: forall x. Rep PositivityCheck x -> PositivityCheck
to :: forall x. Rep PositivityCheck x -> PositivityCheck
Generic)

instance KillRange PositivityCheck where
  killRange :: PositivityCheck -> PositivityCheck
killRange = PositivityCheck -> PositivityCheck
forall a. a -> a
id

-- Semigroup and Monoid via conjunction
instance Semigroup PositivityCheck where
  PositivityCheck
NoPositivityCheck <> :: PositivityCheck -> PositivityCheck -> PositivityCheck
<> PositivityCheck
_ = PositivityCheck
NoPositivityCheck
  PositivityCheck
_ <> PositivityCheck
NoPositivityCheck = PositivityCheck
NoPositivityCheck
  PositivityCheck
_ <> PositivityCheck
_ = PositivityCheck
YesPositivityCheck

instance Monoid PositivityCheck where
  mempty :: PositivityCheck
mempty  = PositivityCheck
YesPositivityCheck
  mappend :: PositivityCheck -> PositivityCheck -> PositivityCheck
mappend = PositivityCheck -> PositivityCheck -> PositivityCheck
forall a. Semigroup a => a -> a -> a
(<>)

instance NFData PositivityCheck

-----------------------------------------------------------------------------
-- * Universe checking
-----------------------------------------------------------------------------

-- | Universe check? (Default is yes).
data UniverseCheck = YesUniverseCheck | NoUniverseCheck
  deriving (UniverseCheck -> UniverseCheck -> Bool
(UniverseCheck -> UniverseCheck -> Bool)
-> (UniverseCheck -> UniverseCheck -> Bool) -> Eq UniverseCheck
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: UniverseCheck -> UniverseCheck -> Bool
== :: UniverseCheck -> UniverseCheck -> Bool
$c/= :: UniverseCheck -> UniverseCheck -> Bool
/= :: UniverseCheck -> UniverseCheck -> Bool
Eq, Eq UniverseCheck
Eq UniverseCheck =>
(UniverseCheck -> UniverseCheck -> Ordering)
-> (UniverseCheck -> UniverseCheck -> Bool)
-> (UniverseCheck -> UniverseCheck -> Bool)
-> (UniverseCheck -> UniverseCheck -> Bool)
-> (UniverseCheck -> UniverseCheck -> Bool)
-> (UniverseCheck -> UniverseCheck -> UniverseCheck)
-> (UniverseCheck -> UniverseCheck -> UniverseCheck)
-> Ord UniverseCheck
UniverseCheck -> UniverseCheck -> Bool
UniverseCheck -> UniverseCheck -> Ordering
UniverseCheck -> UniverseCheck -> UniverseCheck
forall a.
Eq a =>
(a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
$ccompare :: UniverseCheck -> UniverseCheck -> Ordering
compare :: UniverseCheck -> UniverseCheck -> Ordering
$c< :: UniverseCheck -> UniverseCheck -> Bool
< :: UniverseCheck -> UniverseCheck -> Bool
$c<= :: UniverseCheck -> UniverseCheck -> Bool
<= :: UniverseCheck -> UniverseCheck -> Bool
$c> :: UniverseCheck -> UniverseCheck -> Bool
> :: UniverseCheck -> UniverseCheck -> Bool
$c>= :: UniverseCheck -> UniverseCheck -> Bool
>= :: UniverseCheck -> UniverseCheck -> Bool
$cmax :: UniverseCheck -> UniverseCheck -> UniverseCheck
max :: UniverseCheck -> UniverseCheck -> UniverseCheck
$cmin :: UniverseCheck -> UniverseCheck -> UniverseCheck
min :: UniverseCheck -> UniverseCheck -> UniverseCheck
Ord, Int -> UniverseCheck -> ShowS
[UniverseCheck] -> ShowS
UniverseCheck -> ArgName
(Int -> UniverseCheck -> ShowS)
-> (UniverseCheck -> ArgName)
-> ([UniverseCheck] -> ShowS)
-> Show UniverseCheck
forall a.
(Int -> a -> ShowS) -> (a -> ArgName) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> UniverseCheck -> ShowS
showsPrec :: Int -> UniverseCheck -> ShowS
$cshow :: UniverseCheck -> ArgName
show :: UniverseCheck -> ArgName
$cshowList :: [UniverseCheck] -> ShowS
showList :: [UniverseCheck] -> ShowS
Show, UniverseCheck
UniverseCheck -> UniverseCheck -> Bounded UniverseCheck
forall a. a -> a -> Bounded a
$cminBound :: UniverseCheck
minBound :: UniverseCheck
$cmaxBound :: UniverseCheck
maxBound :: UniverseCheck
Bounded, Int -> UniverseCheck
UniverseCheck -> Int
UniverseCheck -> [UniverseCheck]
UniverseCheck -> UniverseCheck
UniverseCheck -> UniverseCheck -> [UniverseCheck]
UniverseCheck -> UniverseCheck -> UniverseCheck -> [UniverseCheck]
(UniverseCheck -> UniverseCheck)
-> (UniverseCheck -> UniverseCheck)
-> (Int -> UniverseCheck)
-> (UniverseCheck -> Int)
-> (UniverseCheck -> [UniverseCheck])
-> (UniverseCheck -> UniverseCheck -> [UniverseCheck])
-> (UniverseCheck -> UniverseCheck -> [UniverseCheck])
-> (UniverseCheck
    -> UniverseCheck -> UniverseCheck -> [UniverseCheck])
-> Enum UniverseCheck
forall a.
(a -> a)
-> (a -> a)
-> (Int -> a)
-> (a -> Int)
-> (a -> [a])
-> (a -> a -> [a])
-> (a -> a -> [a])
-> (a -> a -> a -> [a])
-> Enum a
$csucc :: UniverseCheck -> UniverseCheck
succ :: UniverseCheck -> UniverseCheck
$cpred :: UniverseCheck -> UniverseCheck
pred :: UniverseCheck -> UniverseCheck
$ctoEnum :: Int -> UniverseCheck
toEnum :: Int -> UniverseCheck
$cfromEnum :: UniverseCheck -> Int
fromEnum :: UniverseCheck -> Int
$cenumFrom :: UniverseCheck -> [UniverseCheck]
enumFrom :: UniverseCheck -> [UniverseCheck]
$cenumFromThen :: UniverseCheck -> UniverseCheck -> [UniverseCheck]
enumFromThen :: UniverseCheck -> UniverseCheck -> [UniverseCheck]
$cenumFromTo :: UniverseCheck -> UniverseCheck -> [UniverseCheck]
enumFromTo :: UniverseCheck -> UniverseCheck -> [UniverseCheck]
$cenumFromThenTo :: UniverseCheck -> UniverseCheck -> UniverseCheck -> [UniverseCheck]
enumFromThenTo :: UniverseCheck -> UniverseCheck -> UniverseCheck -> [UniverseCheck]
Enum, (forall x. UniverseCheck -> Rep UniverseCheck x)
-> (forall x. Rep UniverseCheck x -> UniverseCheck)
-> Generic UniverseCheck
forall x. Rep UniverseCheck x -> UniverseCheck
forall x. UniverseCheck -> Rep UniverseCheck x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cfrom :: forall x. UniverseCheck -> Rep UniverseCheck x
from :: forall x. UniverseCheck -> Rep UniverseCheck x
$cto :: forall x. Rep UniverseCheck x -> UniverseCheck
to :: forall x. Rep UniverseCheck x -> UniverseCheck
Generic)

instance KillRange UniverseCheck where
  killRange :: UniverseCheck -> UniverseCheck
killRange = UniverseCheck -> UniverseCheck
forall a. a -> a
id

instance NFData UniverseCheck

-----------------------------------------------------------------------------
-- * Universe checking
-----------------------------------------------------------------------------

-- | Coverage check? (Default is yes).
data CoverageCheck = YesCoverageCheck | NoCoverageCheck
  deriving (CoverageCheck -> CoverageCheck -> Bool
(CoverageCheck -> CoverageCheck -> Bool)
-> (CoverageCheck -> CoverageCheck -> Bool) -> Eq CoverageCheck
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: CoverageCheck -> CoverageCheck -> Bool
== :: CoverageCheck -> CoverageCheck -> Bool
$c/= :: CoverageCheck -> CoverageCheck -> Bool
/= :: CoverageCheck -> CoverageCheck -> Bool
Eq, Eq CoverageCheck
Eq CoverageCheck =>
(CoverageCheck -> CoverageCheck -> Ordering)
-> (CoverageCheck -> CoverageCheck -> Bool)
-> (CoverageCheck -> CoverageCheck -> Bool)
-> (CoverageCheck -> CoverageCheck -> Bool)
-> (CoverageCheck -> CoverageCheck -> Bool)
-> (CoverageCheck -> CoverageCheck -> CoverageCheck)
-> (CoverageCheck -> CoverageCheck -> CoverageCheck)
-> Ord CoverageCheck
CoverageCheck -> CoverageCheck -> Bool
CoverageCheck -> CoverageCheck -> Ordering
CoverageCheck -> CoverageCheck -> CoverageCheck
forall a.
Eq a =>
(a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
$ccompare :: CoverageCheck -> CoverageCheck -> Ordering
compare :: CoverageCheck -> CoverageCheck -> Ordering
$c< :: CoverageCheck -> CoverageCheck -> Bool
< :: CoverageCheck -> CoverageCheck -> Bool
$c<= :: CoverageCheck -> CoverageCheck -> Bool
<= :: CoverageCheck -> CoverageCheck -> Bool
$c> :: CoverageCheck -> CoverageCheck -> Bool
> :: CoverageCheck -> CoverageCheck -> Bool
$c>= :: CoverageCheck -> CoverageCheck -> Bool
>= :: CoverageCheck -> CoverageCheck -> Bool
$cmax :: CoverageCheck -> CoverageCheck -> CoverageCheck
max :: CoverageCheck -> CoverageCheck -> CoverageCheck
$cmin :: CoverageCheck -> CoverageCheck -> CoverageCheck
min :: CoverageCheck -> CoverageCheck -> CoverageCheck
Ord, Int -> CoverageCheck -> ShowS
[CoverageCheck] -> ShowS
CoverageCheck -> ArgName
(Int -> CoverageCheck -> ShowS)
-> (CoverageCheck -> ArgName)
-> ([CoverageCheck] -> ShowS)
-> Show CoverageCheck
forall a.
(Int -> a -> ShowS) -> (a -> ArgName) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> CoverageCheck -> ShowS
showsPrec :: Int -> CoverageCheck -> ShowS
$cshow :: CoverageCheck -> ArgName
show :: CoverageCheck -> ArgName
$cshowList :: [CoverageCheck] -> ShowS
showList :: [CoverageCheck] -> ShowS
Show, CoverageCheck
CoverageCheck -> CoverageCheck -> Bounded CoverageCheck
forall a. a -> a -> Bounded a
$cminBound :: CoverageCheck
minBound :: CoverageCheck
$cmaxBound :: CoverageCheck
maxBound :: CoverageCheck
Bounded, Int -> CoverageCheck
CoverageCheck -> Int
CoverageCheck -> [CoverageCheck]
CoverageCheck -> CoverageCheck
CoverageCheck -> CoverageCheck -> [CoverageCheck]
CoverageCheck -> CoverageCheck -> CoverageCheck -> [CoverageCheck]
(CoverageCheck -> CoverageCheck)
-> (CoverageCheck -> CoverageCheck)
-> (Int -> CoverageCheck)
-> (CoverageCheck -> Int)
-> (CoverageCheck -> [CoverageCheck])
-> (CoverageCheck -> CoverageCheck -> [CoverageCheck])
-> (CoverageCheck -> CoverageCheck -> [CoverageCheck])
-> (CoverageCheck
    -> CoverageCheck -> CoverageCheck -> [CoverageCheck])
-> Enum CoverageCheck
forall a.
(a -> a)
-> (a -> a)
-> (Int -> a)
-> (a -> Int)
-> (a -> [a])
-> (a -> a -> [a])
-> (a -> a -> [a])
-> (a -> a -> a -> [a])
-> Enum a
$csucc :: CoverageCheck -> CoverageCheck
succ :: CoverageCheck -> CoverageCheck
$cpred :: CoverageCheck -> CoverageCheck
pred :: CoverageCheck -> CoverageCheck
$ctoEnum :: Int -> CoverageCheck
toEnum :: Int -> CoverageCheck
$cfromEnum :: CoverageCheck -> Int
fromEnum :: CoverageCheck -> Int
$cenumFrom :: CoverageCheck -> [CoverageCheck]
enumFrom :: CoverageCheck -> [CoverageCheck]
$cenumFromThen :: CoverageCheck -> CoverageCheck -> [CoverageCheck]
enumFromThen :: CoverageCheck -> CoverageCheck -> [CoverageCheck]
$cenumFromTo :: CoverageCheck -> CoverageCheck -> [CoverageCheck]
enumFromTo :: CoverageCheck -> CoverageCheck -> [CoverageCheck]
$cenumFromThenTo :: CoverageCheck -> CoverageCheck -> CoverageCheck -> [CoverageCheck]
enumFromThenTo :: CoverageCheck -> CoverageCheck -> CoverageCheck -> [CoverageCheck]
Enum, (forall x. CoverageCheck -> Rep CoverageCheck x)
-> (forall x. Rep CoverageCheck x -> CoverageCheck)
-> Generic CoverageCheck
forall x. Rep CoverageCheck x -> CoverageCheck
forall x. CoverageCheck -> Rep CoverageCheck x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cfrom :: forall x. CoverageCheck -> Rep CoverageCheck x
from :: forall x. CoverageCheck -> Rep CoverageCheck x
$cto :: forall x. Rep CoverageCheck x -> CoverageCheck
to :: forall x. Rep CoverageCheck x -> CoverageCheck
Generic)

instance KillRange CoverageCheck where
  killRange :: CoverageCheck -> CoverageCheck
killRange = CoverageCheck -> CoverageCheck
forall a. a -> a
id

-- Semigroup and Monoid via conjunction
instance Semigroup CoverageCheck where
  CoverageCheck
NoCoverageCheck <> :: CoverageCheck -> CoverageCheck -> CoverageCheck
<> CoverageCheck
_ = CoverageCheck
NoCoverageCheck
  CoverageCheck
_ <> CoverageCheck
NoCoverageCheck = CoverageCheck
NoCoverageCheck
  CoverageCheck
_ <> CoverageCheck
_ = CoverageCheck
YesCoverageCheck

instance Monoid CoverageCheck where
  mempty :: CoverageCheck
mempty  = CoverageCheck
YesCoverageCheck
  mappend :: CoverageCheck -> CoverageCheck -> CoverageCheck
mappend = CoverageCheck -> CoverageCheck -> CoverageCheck
forall a. Semigroup a => a -> a -> a
(<>)

instance NFData CoverageCheck

-----------------------------------------------------------------------------
-- * Rewrite Directives on the LHS
-----------------------------------------------------------------------------

-- | @RewriteEqn' qn p e@ represents the @rewrite@ and irrefutable @with@
--   clauses of the LHS.
--   @qn@ stands for the QName of the auxiliary function generated to implement the feature
--   @nm@ is the type of names for pattern variables
--   @p@  is the type of patterns
--   @e@  is the type of expressions

data RewriteEqn' qn nm p e
  = Rewrite (List1 (qn, e))             -- ^ @rewrite e@
  | Invert qn (List1 (Named nm (p, e))) -- ^ @with p <- e in eq@
  deriving (RewriteEqn' qn nm p e -> RewriteEqn' qn nm p e -> Bool
(RewriteEqn' qn nm p e -> RewriteEqn' qn nm p e -> Bool)
-> (RewriteEqn' qn nm p e -> RewriteEqn' qn nm p e -> Bool)
-> Eq (RewriteEqn' qn nm p e)
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
forall qn nm p e.
(Eq e, Eq qn, Eq nm, Eq p) =>
RewriteEqn' qn nm p e -> RewriteEqn' qn nm p e -> Bool
$c== :: forall qn nm p e.
(Eq e, Eq qn, Eq nm, Eq p) =>
RewriteEqn' qn nm p e -> RewriteEqn' qn nm p e -> Bool
== :: RewriteEqn' qn nm p e -> RewriteEqn' qn nm p e -> Bool
$c/= :: forall qn nm p e.
(Eq e, Eq qn, Eq nm, Eq p) =>
RewriteEqn' qn nm p e -> RewriteEqn' qn nm p e -> Bool
/= :: RewriteEqn' qn nm p e -> RewriteEqn' qn nm p e -> Bool
Eq, Int -> RewriteEqn' qn nm p e -> ShowS
[RewriteEqn' qn nm p e] -> ShowS
RewriteEqn' qn nm p e -> ArgName
(Int -> RewriteEqn' qn nm p e -> ShowS)
-> (RewriteEqn' qn nm p e -> ArgName)
-> ([RewriteEqn' qn nm p e] -> ShowS)
-> Show (RewriteEqn' qn nm p e)
forall a.
(Int -> a -> ShowS) -> (a -> ArgName) -> ([a] -> ShowS) -> Show a
forall qn nm p e.
(Show e, Show qn, Show nm, Show p) =>
Int -> RewriteEqn' qn nm p e -> ShowS
forall qn nm p e.
(Show e, Show qn, Show nm, Show p) =>
[RewriteEqn' qn nm p e] -> ShowS
forall qn nm p e.
(Show e, Show qn, Show nm, Show p) =>
RewriteEqn' qn nm p e -> ArgName
$cshowsPrec :: forall qn nm p e.
(Show e, Show qn, Show nm, Show p) =>
Int -> RewriteEqn' qn nm p e -> ShowS
showsPrec :: Int -> RewriteEqn' qn nm p e -> ShowS
$cshow :: forall qn nm p e.
(Show e, Show qn, Show nm, Show p) =>
RewriteEqn' qn nm p e -> ArgName
show :: RewriteEqn' qn nm p e -> ArgName
$cshowList :: forall qn nm p e.
(Show e, Show qn, Show nm, Show p) =>
[RewriteEqn' qn nm p e] -> ShowS
showList :: [RewriteEqn' qn nm p e] -> ShowS
Show, (forall a b.
 (a -> b) -> RewriteEqn' qn nm p a -> RewriteEqn' qn nm p b)
-> (forall a b.
    a -> RewriteEqn' qn nm p b -> RewriteEqn' qn nm p a)
-> Functor (RewriteEqn' qn nm p)
forall a b. a -> RewriteEqn' qn nm p b -> RewriteEqn' qn nm p a
forall a b.
(a -> b) -> RewriteEqn' qn nm p a -> RewriteEqn' qn nm p b
forall qn nm p a b.
a -> RewriteEqn' qn nm p b -> RewriteEqn' qn nm p a
forall qn nm p a b.
(a -> b) -> RewriteEqn' qn nm p a -> RewriteEqn' qn nm p b
forall (f :: * -> *).
(forall a b. (a -> b) -> f a -> f b)
-> (forall a b. a -> f b -> f a) -> Functor f
$cfmap :: forall qn nm p a b.
(a -> b) -> RewriteEqn' qn nm p a -> RewriteEqn' qn nm p b
fmap :: forall a b.
(a -> b) -> RewriteEqn' qn nm p a -> RewriteEqn' qn nm p b
$c<$ :: forall qn nm p a b.
a -> RewriteEqn' qn nm p b -> RewriteEqn' qn nm p a
<$ :: forall a b. a -> RewriteEqn' qn nm p b -> RewriteEqn' qn nm p a
Functor, (forall m. Monoid m => RewriteEqn' qn nm p m -> m)
-> (forall m a. Monoid m => (a -> m) -> RewriteEqn' qn nm p a -> m)
-> (forall m a. Monoid m => (a -> m) -> RewriteEqn' qn nm p a -> m)
-> (forall a b. (a -> b -> b) -> b -> RewriteEqn' qn nm p a -> b)
-> (forall a b. (a -> b -> b) -> b -> RewriteEqn' qn nm p a -> b)
-> (forall b a. (b -> a -> b) -> b -> RewriteEqn' qn nm p a -> b)
-> (forall b a. (b -> a -> b) -> b -> RewriteEqn' qn nm p a -> b)
-> (forall a. (a -> a -> a) -> RewriteEqn' qn nm p a -> a)
-> (forall a. (a -> a -> a) -> RewriteEqn' qn nm p a -> a)
-> (forall a. RewriteEqn' qn nm p a -> [a])
-> (forall a. RewriteEqn' qn nm p a -> Bool)
-> (forall a. RewriteEqn' qn nm p a -> Int)
-> (forall a. Eq a => a -> RewriteEqn' qn nm p a -> Bool)
-> (forall a. Ord a => RewriteEqn' qn nm p a -> a)
-> (forall a. Ord a => RewriteEqn' qn nm p a -> a)
-> (forall a. Num a => RewriteEqn' qn nm p a -> a)
-> (forall a. Num a => RewriteEqn' qn nm p a -> a)
-> Foldable (RewriteEqn' qn nm p)
forall a. Eq a => a -> RewriteEqn' qn nm p a -> Bool
forall a. Num a => RewriteEqn' qn nm p a -> a
forall a. Ord a => RewriteEqn' qn nm p a -> a
forall m. Monoid m => RewriteEqn' qn nm p m -> m
forall a. RewriteEqn' qn nm p a -> Bool
forall a. RewriteEqn' qn nm p a -> Int
forall a. RewriteEqn' qn nm p a -> [a]
forall a. (a -> a -> a) -> RewriteEqn' qn nm p a -> a
forall m a. Monoid m => (a -> m) -> RewriteEqn' qn nm p a -> m
forall b a. (b -> a -> b) -> b -> RewriteEqn' qn nm p a -> b
forall a b. (a -> b -> b) -> b -> RewriteEqn' qn nm p a -> b
forall qn nm p a. Eq a => a -> RewriteEqn' qn nm p a -> Bool
forall qn nm p a. Num a => RewriteEqn' qn nm p a -> a
forall qn nm p a. Ord a => RewriteEqn' qn nm p a -> a
forall qn nm p m. Monoid m => RewriteEqn' qn nm p m -> m
forall qn nm p a. RewriteEqn' qn nm p a -> Bool
forall qn nm p a. RewriteEqn' qn nm p a -> Int
forall qn nm p a. RewriteEqn' qn nm p a -> [a]
forall qn nm p a. (a -> a -> a) -> RewriteEqn' qn nm p a -> a
forall qn nm p m a.
Monoid m =>
(a -> m) -> RewriteEqn' qn nm p a -> m
forall qn nm p b a.
(b -> a -> b) -> b -> RewriteEqn' qn nm p a -> b
forall qn nm p a b.
(a -> b -> b) -> b -> RewriteEqn' qn nm p a -> b
forall (t :: * -> *).
(forall m. Monoid m => t m -> m)
-> (forall m a. Monoid m => (a -> m) -> t a -> m)
-> (forall m a. Monoid m => (a -> m) -> t a -> m)
-> (forall a b. (a -> b -> b) -> b -> t a -> b)
-> (forall a b. (a -> b -> b) -> b -> t a -> b)
-> (forall b a. (b -> a -> b) -> b -> t a -> b)
-> (forall b a. (b -> a -> b) -> b -> t a -> b)
-> (forall a. (a -> a -> a) -> t a -> a)
-> (forall a. (a -> a -> a) -> t a -> a)
-> (forall a. t a -> [a])
-> (forall a. t a -> Bool)
-> (forall a. t a -> Int)
-> (forall a. Eq a => a -> t a -> Bool)
-> (forall a. Ord a => t a -> a)
-> (forall a. Ord a => t a -> a)
-> (forall a. Num a => t a -> a)
-> (forall a. Num a => t a -> a)
-> Foldable t
$cfold :: forall qn nm p m. Monoid m => RewriteEqn' qn nm p m -> m
fold :: forall m. Monoid m => RewriteEqn' qn nm p m -> m
$cfoldMap :: forall qn nm p m a.
Monoid m =>
(a -> m) -> RewriteEqn' qn nm p a -> m
foldMap :: forall m a. Monoid m => (a -> m) -> RewriteEqn' qn nm p a -> m
$cfoldMap' :: forall qn nm p m a.
Monoid m =>
(a -> m) -> RewriteEqn' qn nm p a -> m
foldMap' :: forall m a. Monoid m => (a -> m) -> RewriteEqn' qn nm p a -> m
$cfoldr :: forall qn nm p a b.
(a -> b -> b) -> b -> RewriteEqn' qn nm p a -> b
foldr :: forall a b. (a -> b -> b) -> b -> RewriteEqn' qn nm p a -> b
$cfoldr' :: forall qn nm p a b.
(a -> b -> b) -> b -> RewriteEqn' qn nm p a -> b
foldr' :: forall a b. (a -> b -> b) -> b -> RewriteEqn' qn nm p a -> b
$cfoldl :: forall qn nm p b a.
(b -> a -> b) -> b -> RewriteEqn' qn nm p a -> b
foldl :: forall b a. (b -> a -> b) -> b -> RewriteEqn' qn nm p a -> b
$cfoldl' :: forall qn nm p b a.
(b -> a -> b) -> b -> RewriteEqn' qn nm p a -> b
foldl' :: forall b a. (b -> a -> b) -> b -> RewriteEqn' qn nm p a -> b
$cfoldr1 :: forall qn nm p a. (a -> a -> a) -> RewriteEqn' qn nm p a -> a
foldr1 :: forall a. (a -> a -> a) -> RewriteEqn' qn nm p a -> a
$cfoldl1 :: forall qn nm p a. (a -> a -> a) -> RewriteEqn' qn nm p a -> a
foldl1 :: forall a. (a -> a -> a) -> RewriteEqn' qn nm p a -> a
$ctoList :: forall qn nm p a. RewriteEqn' qn nm p a -> [a]
toList :: forall a. RewriteEqn' qn nm p a -> [a]
$cnull :: forall qn nm p a. RewriteEqn' qn nm p a -> Bool
null :: forall a. RewriteEqn' qn nm p a -> Bool
$clength :: forall qn nm p a. RewriteEqn' qn nm p a -> Int
length :: forall a. RewriteEqn' qn nm p a -> Int
$celem :: forall qn nm p a. Eq a => a -> RewriteEqn' qn nm p a -> Bool
elem :: forall a. Eq a => a -> RewriteEqn' qn nm p a -> Bool
$cmaximum :: forall qn nm p a. Ord a => RewriteEqn' qn nm p a -> a
maximum :: forall a. Ord a => RewriteEqn' qn nm p a -> a
$cminimum :: forall qn nm p a. Ord a => RewriteEqn' qn nm p a -> a
minimum :: forall a. Ord a => RewriteEqn' qn nm p a -> a
$csum :: forall qn nm p a. Num a => RewriteEqn' qn nm p a -> a
sum :: forall a. Num a => RewriteEqn' qn nm p a -> a
$cproduct :: forall qn nm p a. Num a => RewriteEqn' qn nm p a -> a
product :: forall a. Num a => RewriteEqn' qn nm p a -> a
Foldable, Functor (RewriteEqn' qn nm p)
Foldable (RewriteEqn' qn nm p)
(Functor (RewriteEqn' qn nm p), Foldable (RewriteEqn' qn nm p)) =>
(forall (f :: * -> *) a b.
 Applicative f =>
 (a -> f b) -> RewriteEqn' qn nm p a -> f (RewriteEqn' qn nm p b))
-> (forall (f :: * -> *) a.
    Applicative f =>
    RewriteEqn' qn nm p (f a) -> f (RewriteEqn' qn nm p a))
-> (forall (m :: * -> *) a b.
    Monad m =>
    (a -> m b) -> RewriteEqn' qn nm p a -> m (RewriteEqn' qn nm p b))
-> (forall (m :: * -> *) a.
    Monad m =>
    RewriteEqn' qn nm p (m a) -> m (RewriteEqn' qn nm p a))
-> Traversable (RewriteEqn' qn nm p)
forall qn nm p. Functor (RewriteEqn' qn nm p)
forall qn nm p. Foldable (RewriteEqn' qn nm p)
forall qn nm p (m :: * -> *) a.
Monad m =>
RewriteEqn' qn nm p (m a) -> m (RewriteEqn' qn nm p a)
forall qn nm p (f :: * -> *) a.
Applicative f =>
RewriteEqn' qn nm p (f a) -> f (RewriteEqn' qn nm p a)
forall qn nm p (m :: * -> *) a b.
Monad m =>
(a -> m b) -> RewriteEqn' qn nm p a -> m (RewriteEqn' qn nm p b)
forall qn nm p (f :: * -> *) a b.
Applicative f =>
(a -> f b) -> RewriteEqn' qn nm p a -> f (RewriteEqn' qn nm p b)
forall (t :: * -> *).
(Functor t, Foldable t) =>
(forall (f :: * -> *) a b.
 Applicative f =>
 (a -> f b) -> t a -> f (t b))
-> (forall (f :: * -> *) a. Applicative f => t (f a) -> f (t a))
-> (forall (m :: * -> *) a b.
    Monad m =>
    (a -> m b) -> t a -> m (t b))
-> (forall (m :: * -> *) a. Monad m => t (m a) -> m (t a))
-> Traversable t
forall (m :: * -> *) a.
Monad m =>
RewriteEqn' qn nm p (m a) -> m (RewriteEqn' qn nm p a)
forall (f :: * -> *) a.
Applicative f =>
RewriteEqn' qn nm p (f a) -> f (RewriteEqn' qn nm p a)
forall (m :: * -> *) a b.
Monad m =>
(a -> m b) -> RewriteEqn' qn nm p a -> m (RewriteEqn' qn nm p b)
forall (f :: * -> *) a b.
Applicative f =>
(a -> f b) -> RewriteEqn' qn nm p a -> f (RewriteEqn' qn nm p b)
$ctraverse :: forall qn nm p (f :: * -> *) a b.
Applicative f =>
(a -> f b) -> RewriteEqn' qn nm p a -> f (RewriteEqn' qn nm p b)
traverse :: forall (f :: * -> *) a b.
Applicative f =>
(a -> f b) -> RewriteEqn' qn nm p a -> f (RewriteEqn' qn nm p b)
$csequenceA :: forall qn nm p (f :: * -> *) a.
Applicative f =>
RewriteEqn' qn nm p (f a) -> f (RewriteEqn' qn nm p a)
sequenceA :: forall (f :: * -> *) a.
Applicative f =>
RewriteEqn' qn nm p (f a) -> f (RewriteEqn' qn nm p a)
$cmapM :: forall qn nm p (m :: * -> *) a b.
Monad m =>
(a -> m b) -> RewriteEqn' qn nm p a -> m (RewriteEqn' qn nm p b)
mapM :: forall (m :: * -> *) a b.
Monad m =>
(a -> m b) -> RewriteEqn' qn nm p a -> m (RewriteEqn' qn nm p b)
$csequence :: forall qn nm p (m :: * -> *) a.
Monad m =>
RewriteEqn' qn nm p (m a) -> m (RewriteEqn' qn nm p a)
sequence :: forall (m :: * -> *) a.
Monad m =>
RewriteEqn' qn nm p (m a) -> m (RewriteEqn' qn nm p a)
Traversable)

instance (NFData qn, NFData nm, NFData p, NFData e) => NFData (RewriteEqn' qn nm p e) where
  rnf :: RewriteEqn' qn nm p e -> ()
rnf = \case
    Rewrite List1 (qn, e)
es    -> List1 (qn, e) -> ()
forall a. NFData a => a -> ()
rnf List1 (qn, e)
es
    Invert qn
qn List1 (Named nm (p, e))
pes -> (qn, List1 (Named nm (p, e))) -> ()
forall a. NFData a => a -> ()
rnf (qn
qn, List1 (Named nm (p, e))
pes)

instance (Pretty nm, Pretty p, Pretty e) => Pretty (RewriteEqn' qn nm p e) where
  pretty :: RewriteEqn' qn nm p e -> Doc
pretty = \case
    Rewrite List1 (qn, e)
es   -> Doc -> [Doc] -> Doc
prefixedThings (ArgName -> Doc
forall a. ArgName -> Doc a
text ArgName
"rewrite") ([Doc] -> Doc) -> [Doc] -> Doc
forall a b. (a -> b) -> a -> b
$ NonEmpty Doc -> [Item (NonEmpty Doc)]
forall l. IsList l => l -> [Item l]
List1.toList (e -> Doc
forall a. Pretty a => a -> Doc
pretty (e -> Doc) -> ((qn, e) -> e) -> (qn, e) -> Doc
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (qn, e) -> e
forall a b. (a, b) -> b
snd ((qn, e) -> Doc) -> List1 (qn, e) -> NonEmpty Doc
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> List1 (qn, e)
es)
    Invert qn
_ List1 (Named nm (p, e))
pes -> Doc -> [Doc] -> Doc
prefixedThings (ArgName -> Doc
forall a. ArgName -> Doc a
text ArgName
"invert") ([Doc] -> Doc) -> [Doc] -> Doc
forall a b. (a -> b) -> a -> b
$ NonEmpty Doc -> [Item (NonEmpty Doc)]
forall l. IsList l => l -> [Item l]
List1.toList (Named nm (p, e) -> Doc
forall {a} {a} {a}.
(Pretty a, Pretty a, Pretty a) =>
Named a (a, a) -> Doc
namedWith (Named nm (p, e) -> Doc) -> List1 (Named nm (p, e)) -> NonEmpty Doc
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> List1 (Named nm (p, e))
pes) where

      namedWith :: Named a (a, a) -> Doc
namedWith (Named Maybe a
nm (a
p, a
e)) =
        let patexp :: Doc
patexp = a -> Doc
forall a. Pretty a => a -> Doc
pretty a
p Doc -> Doc -> Doc
forall a. Doc a -> Doc a -> Doc a
<+> Doc
"<-" Doc -> Doc -> Doc
forall a. Doc a -> Doc a -> Doc a
<+> a -> Doc
forall a. Pretty a => a -> Doc
pretty a
e in
        case Maybe a
nm of
          Maybe a
Nothing -> Doc
patexp
          Just a
nm -> a -> Doc
forall a. Pretty a => a -> Doc
pretty a
nm Doc -> Doc -> Doc
forall a. Doc a -> Doc a -> Doc a
<+> Doc
":" Doc -> Doc -> Doc
forall a. Doc a -> Doc a -> Doc a
<+> Doc
patexp

instance (HasRange qn, HasRange nm, HasRange p, HasRange e) => HasRange (RewriteEqn' qn nm p e) where
  getRange :: RewriteEqn' qn nm p e -> Range
getRange = \case
    Rewrite List1 (qn, e)
es    -> List1 (qn, e) -> Range
forall a. HasRange a => a -> Range
getRange List1 (qn, e)
es
    Invert qn
qn List1 (Named nm (p, e))
pes -> (qn, List1 (Named nm (p, e))) -> Range
forall a. HasRange a => a -> Range
getRange (qn
qn, List1 (Named nm (p, e))
pes)

instance (KillRange qn, KillRange nm, KillRange e, KillRange p) => KillRange (RewriteEqn' qn nm p e) where
  killRange :: KillRangeT (RewriteEqn' qn nm p e)
killRange = \case
    Rewrite List1 (qn, e)
es    -> (List1 (qn, e) -> RewriteEqn' qn nm p e)
-> List1 (qn, e) -> RewriteEqn' qn nm p e
forall t (b :: Bool).
(KILLRANGE t b, IsBase t ~ b, All KillRange (Domains t)) =>
t -> t
killRangeN List1 (qn, e) -> RewriteEqn' qn nm p e
forall qn nm p e. List1 (qn, e) -> RewriteEqn' qn nm p e
Rewrite List1 (qn, e)
es
    Invert qn
qn List1 (Named nm (p, e))
pes -> (qn -> List1 (Named nm (p, e)) -> RewriteEqn' qn nm p e)
-> qn -> List1 (Named nm (p, e)) -> RewriteEqn' qn nm p e
forall t (b :: Bool).
(KILLRANGE t b, IsBase t ~ b, All KillRange (Domains t)) =>
t -> t
killRangeN qn -> List1 (Named nm (p, e)) -> RewriteEqn' qn nm p e
forall qn nm p e.
qn -> List1 (Named nm (p, e)) -> RewriteEqn' qn nm p e
Invert qn
qn List1 (Named nm (p, e))
pes

-----------------------------------------------------------------------------
-- * Information on expanded ellipsis (@...@)
-----------------------------------------------------------------------------

-- ^ When the ellipsis in a clause is expanded, we remember that we
--   did so. We also store the number of with-arguments that are
--   included in the expanded ellipsis.
data ExpandedEllipsis
  = ExpandedEllipsis
  { ExpandedEllipsis -> Range
ellipsisRange :: Range
  , ExpandedEllipsis -> Int
ellipsisWithArgs :: Int
  }
  | NoEllipsis
  deriving (Int -> ExpandedEllipsis -> ShowS
[ExpandedEllipsis] -> ShowS
ExpandedEllipsis -> ArgName
(Int -> ExpandedEllipsis -> ShowS)
-> (ExpandedEllipsis -> ArgName)
-> ([ExpandedEllipsis] -> ShowS)
-> Show ExpandedEllipsis
forall a.
(Int -> a -> ShowS) -> (a -> ArgName) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> ExpandedEllipsis -> ShowS
showsPrec :: Int -> ExpandedEllipsis -> ShowS
$cshow :: ExpandedEllipsis -> ArgName
show :: ExpandedEllipsis -> ArgName
$cshowList :: [ExpandedEllipsis] -> ShowS
showList :: [ExpandedEllipsis] -> ShowS
Show, ExpandedEllipsis -> ExpandedEllipsis -> Bool
(ExpandedEllipsis -> ExpandedEllipsis -> Bool)
-> (ExpandedEllipsis -> ExpandedEllipsis -> Bool)
-> Eq ExpandedEllipsis
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: ExpandedEllipsis -> ExpandedEllipsis -> Bool
== :: ExpandedEllipsis -> ExpandedEllipsis -> Bool
$c/= :: ExpandedEllipsis -> ExpandedEllipsis -> Bool
/= :: ExpandedEllipsis -> ExpandedEllipsis -> Bool
Eq)

instance Null ExpandedEllipsis where
  null :: ExpandedEllipsis -> Bool
null  = (ExpandedEllipsis -> ExpandedEllipsis -> Bool
forall a. Eq a => a -> a -> Bool
== ExpandedEllipsis
NoEllipsis)
  empty :: ExpandedEllipsis
empty = ExpandedEllipsis
NoEllipsis

instance Semigroup ExpandedEllipsis where
  ExpandedEllipsis
NoEllipsis <> :: ExpandedEllipsis -> ExpandedEllipsis -> ExpandedEllipsis
<> ExpandedEllipsis
e          = ExpandedEllipsis
e
  ExpandedEllipsis
e          <> ExpandedEllipsis
NoEllipsis = ExpandedEllipsis
e
  (ExpandedEllipsis Range
r1 Int
k1) <> (ExpandedEllipsis Range
r2 Int
k2) = Range -> Int -> ExpandedEllipsis
ExpandedEllipsis (Range
r1 Range -> Range -> Range
forall a. Semigroup a => a -> a -> a
<> Range
r2) (Int
k1 Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
k2)

instance Monoid ExpandedEllipsis where
  mempty :: ExpandedEllipsis
mempty  = ExpandedEllipsis
NoEllipsis
  mappend :: ExpandedEllipsis -> ExpandedEllipsis -> ExpandedEllipsis
mappend = ExpandedEllipsis -> ExpandedEllipsis -> ExpandedEllipsis
forall a. Semigroup a => a -> a -> a
(<>)

instance KillRange ExpandedEllipsis where
  killRange :: ExpandedEllipsis -> ExpandedEllipsis
killRange (ExpandedEllipsis Range
_ Int
k) = Range -> Int -> ExpandedEllipsis
ExpandedEllipsis Range
forall a. Range' a
noRange Int
k
  killRange ExpandedEllipsis
NoEllipsis             = ExpandedEllipsis
NoEllipsis

instance NFData ExpandedEllipsis where
  rnf :: ExpandedEllipsis -> ()
rnf (ExpandedEllipsis Range
_ Int
a) = Int -> ()
forall a. NFData a => a -> ()
rnf Int
a
  rnf ExpandedEllipsis
NoEllipsis             = ()

-- | Notation as provided by the @syntax@ declaration.
type Notation = [NotationPart]

noNotation :: Notation
noNotation :: Notation
noNotation = []

-- | Positions of variables in syntax declarations.

data BoundVariablePosition = BoundVariablePosition
  { BoundVariablePosition -> Int
holeNumber :: !Int
    -- ^ The position (in the left-hand side of the syntax
    -- declaration) of the hole in which the variable is bound,
    -- counting from zero (and excluding parts that are not holes).
    -- For instance, for @syntax Σ A (λ x → B) = B , A , x@ the number
    -- for @x@ is @1@, corresponding to @B@ (@0@ would correspond to
    -- @A@).
  , BoundVariablePosition -> Int
varNumber :: !Int
    -- ^ The position in the list of variables for this particular
    -- variable, counting from zero, and including wildcards. For
    -- instance, for @syntax F (λ x _ y → A) = y ! A ! x@ the number
    -- for @x@ is @0@, the number for @_@ is @1@, and the number for
    -- @y@ is @2@.
  }
  deriving (BoundVariablePosition -> BoundVariablePosition -> Bool
(BoundVariablePosition -> BoundVariablePosition -> Bool)
-> (BoundVariablePosition -> BoundVariablePosition -> Bool)
-> Eq BoundVariablePosition
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: BoundVariablePosition -> BoundVariablePosition -> Bool
== :: BoundVariablePosition -> BoundVariablePosition -> Bool
$c/= :: BoundVariablePosition -> BoundVariablePosition -> Bool
/= :: BoundVariablePosition -> BoundVariablePosition -> Bool
Eq, Eq BoundVariablePosition
Eq BoundVariablePosition =>
(BoundVariablePosition -> BoundVariablePosition -> Ordering)
-> (BoundVariablePosition -> BoundVariablePosition -> Bool)
-> (BoundVariablePosition -> BoundVariablePosition -> Bool)
-> (BoundVariablePosition -> BoundVariablePosition -> Bool)
-> (BoundVariablePosition -> BoundVariablePosition -> Bool)
-> (BoundVariablePosition
    -> BoundVariablePosition -> BoundVariablePosition)
-> (BoundVariablePosition
    -> BoundVariablePosition -> BoundVariablePosition)
-> Ord BoundVariablePosition
BoundVariablePosition -> BoundVariablePosition -> Bool
BoundVariablePosition -> BoundVariablePosition -> Ordering
BoundVariablePosition
-> BoundVariablePosition -> BoundVariablePosition
forall a.
Eq a =>
(a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
$ccompare :: BoundVariablePosition -> BoundVariablePosition -> Ordering
compare :: BoundVariablePosition -> BoundVariablePosition -> Ordering
$c< :: BoundVariablePosition -> BoundVariablePosition -> Bool
< :: BoundVariablePosition -> BoundVariablePosition -> Bool
$c<= :: BoundVariablePosition -> BoundVariablePosition -> Bool
<= :: BoundVariablePosition -> BoundVariablePosition -> Bool
$c> :: BoundVariablePosition -> BoundVariablePosition -> Bool
> :: BoundVariablePosition -> BoundVariablePosition -> Bool
$c>= :: BoundVariablePosition -> BoundVariablePosition -> Bool
>= :: BoundVariablePosition -> BoundVariablePosition -> Bool
$cmax :: BoundVariablePosition
-> BoundVariablePosition -> BoundVariablePosition
max :: BoundVariablePosition
-> BoundVariablePosition -> BoundVariablePosition
$cmin :: BoundVariablePosition
-> BoundVariablePosition -> BoundVariablePosition
min :: BoundVariablePosition
-> BoundVariablePosition -> BoundVariablePosition
Ord, Int -> BoundVariablePosition -> ShowS
[BoundVariablePosition] -> ShowS
BoundVariablePosition -> ArgName
(Int -> BoundVariablePosition -> ShowS)
-> (BoundVariablePosition -> ArgName)
-> ([BoundVariablePosition] -> ShowS)
-> Show BoundVariablePosition
forall a.
(Int -> a -> ShowS) -> (a -> ArgName) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> BoundVariablePosition -> ShowS
showsPrec :: Int -> BoundVariablePosition -> ShowS
$cshow :: BoundVariablePosition -> ArgName
show :: BoundVariablePosition -> ArgName
$cshowList :: [BoundVariablePosition] -> ShowS
showList :: [BoundVariablePosition] -> ShowS
Show)

-- | Notation parts.

data NotationPart
  = IdPart RString
    -- ^ An identifier part. For instance, for @_+_@ the only
    -- identifier part is @+@.
  | HolePart Range (NamedArg (Ranged Int))
    -- ^ A hole: a place where argument expressions can be written.
    -- For instance, for @_+_@ the two underscores are holes, and for
    -- @syntax Σ A (λ x → B) = B , A , x@ the variables @A@ and @B@
    -- are holes. The number is the position of the hole, counting
    -- from zero. For instance, the number for @A@ is @0@, and the
    -- number for @B@ is @1@.
  | VarPart Range (Ranged BoundVariablePosition)
    -- ^ A bound variable.
    --
    -- The first range is the range of the variable in the right-hand
    -- side of the syntax declaration, and the second range is the
    -- range of the variable in the left-hand side.
  | WildPart (Ranged BoundVariablePosition)
    -- ^ A wildcard (an underscore in binding position).
  deriving Int -> NotationPart -> ShowS
Notation -> ShowS
NotationPart -> ArgName
(Int -> NotationPart -> ShowS)
-> (NotationPart -> ArgName)
-> (Notation -> ShowS)
-> Show NotationPart
forall a.
(Int -> a -> ShowS) -> (a -> ArgName) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> NotationPart -> ShowS
showsPrec :: Int -> NotationPart -> ShowS
$cshow :: NotationPart -> ArgName
show :: NotationPart -> ArgName
$cshowList :: Notation -> ShowS
showList :: Notation -> ShowS
Show

instance Eq NotationPart where
  VarPart Range
_ Ranged BoundVariablePosition
i  == :: NotationPart -> NotationPart -> Bool
== VarPart Range
_ Ranged BoundVariablePosition
j  = Ranged BoundVariablePosition
i Ranged BoundVariablePosition
-> Ranged BoundVariablePosition -> Bool
forall a. Eq a => a -> a -> Bool
== Ranged BoundVariablePosition
j
  HolePart Range
_ NamedArg (Ranged Int)
x == HolePart Range
_ NamedArg (Ranged Int)
y = NamedArg (Ranged Int)
x NamedArg (Ranged Int) -> NamedArg (Ranged Int) -> Bool
forall a. Eq a => a -> a -> Bool
== NamedArg (Ranged Int)
y
  WildPart Ranged BoundVariablePosition
i   == WildPart Ranged BoundVariablePosition
j   = Ranged BoundVariablePosition
i Ranged BoundVariablePosition
-> Ranged BoundVariablePosition -> Bool
forall a. Eq a => a -> a -> Bool
== Ranged BoundVariablePosition
j
  IdPart Ranged ArgName
x     == IdPart Ranged ArgName
y     = Ranged ArgName
x Ranged ArgName -> Ranged ArgName -> Bool
forall a. Eq a => a -> a -> Bool
== Ranged ArgName
y
  NotationPart
_            == NotationPart
_            = Bool
False

instance Ord NotationPart where
  VarPart Range
_ Ranged BoundVariablePosition
i  compare :: NotationPart -> NotationPart -> Ordering
`compare` VarPart Range
_ Ranged BoundVariablePosition
j  = Ranged BoundVariablePosition
i Ranged BoundVariablePosition
-> Ranged BoundVariablePosition -> Ordering
forall a. Ord a => a -> a -> Ordering
`compare` Ranged BoundVariablePosition
j
  HolePart Range
_ NamedArg (Ranged Int)
x `compare` HolePart Range
_ NamedArg (Ranged Int)
y = NamedArg (Ranged Int)
x NamedArg (Ranged Int) -> NamedArg (Ranged Int) -> Ordering
forall a. Ord a => a -> a -> Ordering
`compare` NamedArg (Ranged Int)
y
  WildPart Ranged BoundVariablePosition
i   `compare` WildPart Ranged BoundVariablePosition
j   = Ranged BoundVariablePosition
i Ranged BoundVariablePosition
-> Ranged BoundVariablePosition -> Ordering
forall a. Ord a => a -> a -> Ordering
`compare` Ranged BoundVariablePosition
j
  IdPart Ranged ArgName
x     `compare` IdPart Ranged ArgName
y     = Ranged ArgName
x Ranged ArgName -> Ranged ArgName -> Ordering
forall a. Ord a => a -> a -> Ordering
`compare` Ranged ArgName
y
  VarPart{}    `compare` NotationPart
_            = Ordering
LT
  NotationPart
_            `compare` VarPart{}    = Ordering
GT
  HolePart{}   `compare` NotationPart
_            = Ordering
LT
  NotationPart
_            `compare` HolePart{}   = Ordering
GT
  WildPart{}   `compare` NotationPart
_            = Ordering
LT
  NotationPart
_            `compare` WildPart{}   = Ordering
GT

instance HasRange NotationPart where
  getRange :: NotationPart -> Range
getRange = \case
    IdPart Ranged ArgName
x     -> Ranged ArgName -> Range
forall a. HasRange a => a -> Range
getRange Ranged ArgName
x
    VarPart Range
r Ranged BoundVariablePosition
_  -> Range
r
    WildPart Ranged BoundVariablePosition
i   -> Ranged BoundVariablePosition -> Range
forall a. HasRange a => a -> Range
getRange Ranged BoundVariablePosition
i
    HolePart Range
r NamedArg (Ranged Int)
_ -> Range
r

instance SetRange NotationPart where
  setRange :: Range -> NotationPart -> NotationPart
setRange Range
r = \case
    IdPart Ranged ArgName
x     -> Ranged ArgName -> NotationPart
IdPart Ranged ArgName
x
    VarPart Range
_ Ranged BoundVariablePosition
i  -> Range -> Ranged BoundVariablePosition -> NotationPart
VarPart Range
r Ranged BoundVariablePosition
i
    WildPart Ranged BoundVariablePosition
i   -> Ranged BoundVariablePosition -> NotationPart
WildPart Ranged BoundVariablePosition
i
    HolePart Range
_ NamedArg (Ranged Int)
i -> Range -> NamedArg (Ranged Int) -> NotationPart
HolePart Range
r NamedArg (Ranged Int)
i

instance KillRange NotationPart where
  killRange :: NotationPart -> NotationPart
killRange = \case
    IdPart Ranged ArgName
x     -> Ranged ArgName -> NotationPart
IdPart (Ranged ArgName -> NotationPart) -> Ranged ArgName -> NotationPart
forall a b. (a -> b) -> a -> b
$ KillRangeT (Ranged ArgName)
forall a. KillRange a => KillRangeT a
killRange Ranged ArgName
x
    VarPart Range
_ Ranged BoundVariablePosition
i  -> Range -> Ranged BoundVariablePosition -> NotationPart
VarPart Range
forall a. Range' a
noRange (Ranged BoundVariablePosition -> NotationPart)
-> Ranged BoundVariablePosition -> NotationPart
forall a b. (a -> b) -> a -> b
$ KillRangeT (Ranged BoundVariablePosition)
forall a. KillRange a => KillRangeT a
killRange Ranged BoundVariablePosition
i
    WildPart Ranged BoundVariablePosition
i   -> Ranged BoundVariablePosition -> NotationPart
WildPart (Ranged BoundVariablePosition -> NotationPart)
-> Ranged BoundVariablePosition -> NotationPart
forall a b. (a -> b) -> a -> b
$ KillRangeT (Ranged BoundVariablePosition)
forall a. KillRange a => KillRangeT a
killRange Ranged BoundVariablePosition
i
    HolePart Range
_ NamedArg (Ranged Int)
x -> Range -> NamedArg (Ranged Int) -> NotationPart
HolePart Range
forall a. Range' a
noRange (NamedArg (Ranged Int) -> NotationPart)
-> NamedArg (Ranged Int) -> NotationPart
forall a b. (a -> b) -> a -> b
$ KillRangeT (NamedArg (Ranged Int))
forall a. KillRange a => KillRangeT a
killRange NamedArg (Ranged Int)
x

instance NFData BoundVariablePosition where
  rnf :: BoundVariablePosition -> ()
rnf = (BoundVariablePosition -> () -> ()
forall a b. a -> b -> b
`seq` ())

instance NFData NotationPart where
  rnf :: NotationPart -> ()
rnf (VarPart Range
_ Ranged BoundVariablePosition
a)  = Ranged BoundVariablePosition -> ()
forall a. NFData a => a -> ()
rnf Ranged BoundVariablePosition
a
  rnf (HolePart Range
_ NamedArg (Ranged Int)
a) = NamedArg (Ranged Int) -> ()
forall a. NFData a => a -> ()
rnf NamedArg (Ranged Int)
a
  rnf (WildPart Ranged BoundVariablePosition
a)   = Ranged BoundVariablePosition -> ()
forall a. NFData a => a -> ()
rnf Ranged BoundVariablePosition
a
  rnf (IdPart Ranged ArgName
a)     = Ranged ArgName -> ()
forall a. NFData a => a -> ()
rnf Ranged ArgName
a