{-# LANGUAGE CPP #-}

{-| Some common syntactic entities are defined in this module.
-}
module Agda.Syntax.Common 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
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 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.Utils.Pretty

import Agda.Utils.Impossible

type Nat    = Int
type Arity  = Nat

---------------------------------------------------------------------------
-- * Delayed
---------------------------------------------------------------------------

-- | Used to specify whether something should be delayed.
data Delayed = Delayed | NotDelayed
  deriving (Int -> Delayed -> ShowS
[Delayed] -> ShowS
Delayed -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Delayed] -> ShowS
$cshowList :: [Delayed] -> ShowS
show :: Delayed -> String
$cshow :: Delayed -> String
showsPrec :: Int -> Delayed -> ShowS
$cshowsPrec :: Int -> Delayed -> ShowS
Show, Delayed -> Delayed -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Delayed -> Delayed -> Bool
$c/= :: Delayed -> Delayed -> Bool
== :: Delayed -> Delayed -> Bool
$c== :: Delayed -> Delayed -> Bool
Eq, Eq Delayed
Delayed -> Delayed -> Bool
Delayed -> Delayed -> Ordering
Delayed -> Delayed -> Delayed
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
min :: Delayed -> Delayed -> Delayed
$cmin :: Delayed -> Delayed -> Delayed
max :: Delayed -> Delayed -> Delayed
$cmax :: Delayed -> Delayed -> Delayed
>= :: Delayed -> Delayed -> Bool
$c>= :: Delayed -> Delayed -> Bool
> :: Delayed -> Delayed -> Bool
$c> :: Delayed -> Delayed -> Bool
<= :: Delayed -> Delayed -> Bool
$c<= :: Delayed -> Delayed -> Bool
< :: Delayed -> Delayed -> Bool
$c< :: Delayed -> Delayed -> Bool
compare :: Delayed -> Delayed -> Ordering
$ccompare :: Delayed -> Delayed -> Ordering
Ord, forall x. Rep Delayed x -> Delayed
forall x. Delayed -> Rep Delayed x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep Delayed x -> Delayed
$cfrom :: forall x. Delayed -> Rep Delayed x
Generic)

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

instance NFData Delayed

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

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

instance NFData FileType

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

-- | Variants of Cubical Agda.

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

instance NFData Cubical

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

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

instance KillRange Language where
  killRange :: KillRangeT Language
killRange = 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 -> 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
<$ :: forall a b. a -> RecordDirectives' b -> RecordDirectives' a
$c<$ :: forall a b. a -> RecordDirectives' b -> RecordDirectives' a
fmap :: forall a b. (a -> b) -> RecordDirectives' a -> RecordDirectives' b
$cfmap :: forall a b. (a -> b) -> RecordDirectives' a -> RecordDirectives' b
Functor, Int -> RecordDirectives' a -> ShowS
forall a. Show a => Int -> RecordDirectives' a -> ShowS
forall a. Show a => [RecordDirectives' a] -> ShowS
forall a. Show a => RecordDirectives' a -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [RecordDirectives' a] -> ShowS
$cshowList :: forall a. Show a => [RecordDirectives' a] -> ShowS
show :: RecordDirectives' a -> String
$cshow :: forall a. Show a => RecordDirectives' a -> String
showsPrec :: Int -> RecordDirectives' a -> ShowS
$cshowsPrec :: forall a. Show a => Int -> RecordDirectives' a -> ShowS
Show, RecordDirectives' a -> RecordDirectives' a -> Bool
forall a.
Eq a =>
RecordDirectives' a -> RecordDirectives' a -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: RecordDirectives' a -> RecordDirectives' a -> Bool
$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
Eq)

emptyRecordDirectives :: RecordDirectives' a
emptyRecordDirectives :: forall a. RecordDirectives' a
emptyRecordDirectives = forall a.
Maybe (Ranged Induction)
-> Maybe HasEta0 -> Maybe Range -> Maybe a -> RecordDirectives' a
RecordDirectives forall a. Null a => a
empty forall a. Null a => a
empty forall a. Null a => a
empty 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) = 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) = forall a b c d e.
(KillRange a, KillRange b, KillRange c, KillRange d) =>
(a -> b -> c -> d -> e) -> a -> b -> c -> d -> e
killRange4 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 seq :: forall a b. a -> b -> b
`seq` 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
forall a. Show a => Int -> HasEta' a -> ShowS
forall a. Show a => [HasEta' a] -> ShowS
forall a. Show a => HasEta' a -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [HasEta' a] -> ShowS
$cshowList :: forall a. Show a => [HasEta' a] -> ShowS
show :: HasEta' a -> String
$cshow :: forall a. Show a => HasEta' a -> String
showsPrec :: Int -> HasEta' a -> ShowS
$cshowsPrec :: forall a. Show a => Int -> HasEta' a -> ShowS
Show, HasEta' a -> HasEta' a -> Bool
forall a. Eq a => HasEta' a -> HasEta' a -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: HasEta' a -> HasEta' a -> Bool
$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
Eq, HasEta' a -> HasEta' a -> Bool
HasEta' a -> HasEta' a -> Ordering
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
min :: HasEta' a -> HasEta' a -> HasEta' a
$cmin :: forall a. Ord a => HasEta' a -> HasEta' a -> HasEta' a
max :: HasEta' a -> HasEta' a -> HasEta' a
$cmax :: forall a. Ord a => HasEta' a -> HasEta' a -> HasEta' a
>= :: 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
$c< :: forall a. Ord a => HasEta' a -> HasEta' a -> Bool
compare :: HasEta' a -> HasEta' a -> Ordering
$ccompare :: forall a. Ord a => HasEta' a -> HasEta' a -> Ordering
Ord, 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
<$ :: forall a b. a -> HasEta' b -> HasEta' a
$c<$ :: forall a b. a -> HasEta' b -> HasEta' a
fmap :: forall a b. (a -> b) -> HasEta' a -> HasEta' b
$cfmap :: forall a b. (a -> b) -> HasEta' a -> HasEta' b
Functor, 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
product :: forall a. Num a => HasEta' a -> a
$cproduct :: forall a. Num a => HasEta' a -> a
sum :: forall a. Num a => HasEta' a -> a
$csum :: forall a. Num a => HasEta' a -> a
minimum :: forall a. Ord a => HasEta' a -> a
$cminimum :: forall a. Ord a => HasEta' a -> a
maximum :: forall a. Ord a => HasEta' a -> a
$cmaximum :: forall a. Ord a => HasEta' a -> a
elem :: forall a. Eq a => a -> HasEta' a -> Bool
$celem :: forall a. Eq a => a -> HasEta' a -> Bool
length :: forall a. HasEta' a -> Int
$clength :: forall a. HasEta' a -> Int
null :: forall a. HasEta' a -> Bool
$cnull :: forall a. HasEta' a -> Bool
toList :: forall a. HasEta' a -> [a]
$ctoList :: forall a. HasEta' a -> [a]
foldl1 :: forall a. (a -> a -> a) -> HasEta' a -> a
$cfoldl1 :: forall a. (a -> a -> a) -> HasEta' a -> a
foldr1 :: forall a. (a -> a -> a) -> HasEta' a -> a
$cfoldr1 :: forall a. (a -> a -> a) -> HasEta' a -> a
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
$cfoldl :: forall b a. (b -> a -> 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
$cfoldr :: forall a b. (a -> b -> b) -> b -> HasEta' a -> b
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
$cfoldMap :: forall m a. Monoid m => (a -> m) -> HasEta' a -> m
fold :: forall m. Monoid m => HasEta' m -> m
$cfold :: forall m. Monoid m => HasEta' m -> m
Foldable, Functor HasEta'
Foldable 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)
sequence :: forall (m :: * -> *) a. Monad m => HasEta' (m a) -> m (HasEta' a)
$csequence :: forall (m :: * -> *) a. Monad m => HasEta' (m a) -> m (HasEta' a)
mapM :: forall (m :: * -> *) a b.
Monad m =>
(a -> m b) -> HasEta' a -> m (HasEta' b)
$cmapM :: forall (m :: * -> *) a b.
Monad m =>
(a -> m b) -> HasEta' a -> m (HasEta' b)
sequenceA :: forall (f :: * -> *) a.
Applicative f =>
HasEta' (f a) -> f (HasEta' a)
$csequenceA :: forall (f :: * -> *) a.
Applicative f =>
HasEta' (f a) -> f (HasEta' a)
traverse :: 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)
Traversable)

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

instance KillRange a => KillRange (HasEta' a) where
  killRange :: KillRangeT (HasEta' a)
killRange = forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap 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) = 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 -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [PatternOrCopattern] -> ShowS
$cshowList :: [PatternOrCopattern] -> ShowS
show :: PatternOrCopattern -> String
$cshow :: PatternOrCopattern -> String
showsPrec :: Int -> PatternOrCopattern -> ShowS
$cshowsPrec :: Int -> PatternOrCopattern -> ShowS
Show, PatternOrCopattern -> PatternOrCopattern -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: PatternOrCopattern -> PatternOrCopattern -> Bool
$c/= :: PatternOrCopattern -> PatternOrCopattern -> Bool
== :: PatternOrCopattern -> PatternOrCopattern -> Bool
$c== :: PatternOrCopattern -> PatternOrCopattern -> Bool
Eq, Eq 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
min :: PatternOrCopattern -> PatternOrCopattern -> PatternOrCopattern
$cmin :: PatternOrCopattern -> PatternOrCopattern -> PatternOrCopattern
max :: PatternOrCopattern -> PatternOrCopattern -> PatternOrCopattern
$cmax :: PatternOrCopattern -> PatternOrCopattern -> PatternOrCopattern
>= :: PatternOrCopattern -> PatternOrCopattern -> Bool
$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
compare :: PatternOrCopattern -> PatternOrCopattern -> Ordering
$ccompare :: PatternOrCopattern -> PatternOrCopattern -> Ordering
Ord, Int -> PatternOrCopattern
PatternOrCopattern -> Int
PatternOrCopattern -> [PatternOrCopattern]
PatternOrCopattern -> PatternOrCopattern
PatternOrCopattern -> PatternOrCopattern -> [PatternOrCopattern]
PatternOrCopattern
-> PatternOrCopattern -> PatternOrCopattern -> [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
enumFromThenTo :: PatternOrCopattern
-> PatternOrCopattern -> PatternOrCopattern -> [PatternOrCopattern]
$cenumFromThenTo :: PatternOrCopattern
-> PatternOrCopattern -> PatternOrCopattern -> [PatternOrCopattern]
enumFromTo :: PatternOrCopattern -> PatternOrCopattern -> [PatternOrCopattern]
$cenumFromTo :: PatternOrCopattern -> PatternOrCopattern -> [PatternOrCopattern]
enumFromThen :: PatternOrCopattern -> PatternOrCopattern -> [PatternOrCopattern]
$cenumFromThen :: PatternOrCopattern -> PatternOrCopattern -> [PatternOrCopattern]
enumFrom :: PatternOrCopattern -> [PatternOrCopattern]
$cenumFrom :: PatternOrCopattern -> [PatternOrCopattern]
fromEnum :: PatternOrCopattern -> Int
$cfromEnum :: PatternOrCopattern -> Int
toEnum :: Int -> PatternOrCopattern
$ctoEnum :: Int -> PatternOrCopattern
pred :: PatternOrCopattern -> PatternOrCopattern
$cpred :: PatternOrCopattern -> PatternOrCopattern
succ :: PatternOrCopattern -> PatternOrCopattern
$csucc :: PatternOrCopattern -> PatternOrCopattern
Enum, PatternOrCopattern
forall a. a -> a -> Bounded a
maxBound :: PatternOrCopattern
$cmaxBound :: PatternOrCopattern
minBound :: PatternOrCopattern
$cminBound :: PatternOrCopattern
Bounded)

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

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

instance KillRange PatternOrCopattern where
  killRange :: PatternOrCopattern -> PatternOrCopattern
killRange = 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 = (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 -> 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 = (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 -> forall a. CopatternMatchingAllowed a => a -> Bool
copatternMatchingAllowed PatternOrCopattern
p

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

-- | @Inductive < Coinductive@
data Induction = Inductive | CoInductive  -- Keep in this order!
  deriving (Induction -> Induction -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Induction -> Induction -> Bool
$c/= :: Induction -> Induction -> Bool
== :: Induction -> Induction -> Bool
$c== :: Induction -> Induction -> Bool
Eq, Eq Induction
Induction -> Induction -> Bool
Induction -> Induction -> Ordering
Induction -> Induction -> Induction
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
min :: Induction -> Induction -> Induction
$cmin :: Induction -> Induction -> Induction
max :: Induction -> Induction -> Induction
$cmax :: Induction -> Induction -> Induction
>= :: Induction -> Induction -> Bool
$c>= :: Induction -> Induction -> Bool
> :: Induction -> Induction -> Bool
$c> :: Induction -> Induction -> Bool
<= :: Induction -> Induction -> Bool
$c<= :: Induction -> Induction -> Bool
< :: Induction -> Induction -> Bool
$c< :: Induction -> Induction -> Bool
compare :: Induction -> Induction -> Ordering
$ccompare :: Induction -> Induction -> Ordering
Ord, Int -> Induction -> ShowS
[Induction] -> ShowS
Induction -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Induction] -> ShowS
$cshowList :: [Induction] -> ShowS
show :: Induction -> String
$cshow :: Induction -> String
showsPrec :: Int -> Induction -> ShowS
$cshowsPrec :: Int -> Induction -> ShowS
Show)

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
_ = forall a. Range' a
noRange

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

instance NFData Induction where
  rnf :: Induction -> ()
rnf Induction
Inductive   = ()
  rnf Induction
CoInductive = ()

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

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

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

data Hiding  = Hidden | Instance Overlappable | NotHidden
  deriving (Int -> Hiding -> ShowS
[Hiding] -> ShowS
Hiding -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Hiding] -> ShowS
$cshowList :: [Hiding] -> ShowS
show :: Hiding -> String
$cshow :: Hiding -> String
showsPrec :: Int -> Hiding -> ShowS
$cshowsPrec :: Int -> Hiding -> ShowS
Show, Hiding -> Hiding -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Hiding -> Hiding -> Bool
$c/= :: Hiding -> Hiding -> Bool
== :: Hiding -> Hiding -> Bool
$c== :: Hiding -> Hiding -> Bool
Eq, Eq 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
min :: Hiding -> Hiding -> Hiding
$cmin :: Hiding -> Hiding -> Hiding
max :: Hiding -> Hiding -> Hiding
$cmax :: Hiding -> Hiding -> Hiding
>= :: Hiding -> Hiding -> Bool
$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
compare :: Hiding -> Hiding -> Ordering
$ccompare :: Hiding -> Hiding -> Ordering
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
_          = 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 forall a. Semigroup a => a -> a -> a
<> Overlappable
o')
  Hiding
_          <> Hiding
_           = forall a. HasCallStack => a
__IMPOSSIBLE__

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

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

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

instance KillRange Hiding where
  killRange :: Hiding -> Hiding
killRange = 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) = 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
forall a. Eq a => WithHiding a -> WithHiding a -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: WithHiding a -> WithHiding a -> Bool
$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
Eq, WithHiding a -> WithHiding a -> Bool
WithHiding a -> WithHiding a -> Ordering
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
min :: WithHiding a -> WithHiding a -> WithHiding a
$cmin :: forall a. Ord a => WithHiding a -> WithHiding a -> WithHiding a
max :: WithHiding a -> WithHiding a -> WithHiding a
$cmax :: forall a. Ord a => WithHiding a -> WithHiding a -> WithHiding a
>= :: 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
$c< :: forall a. Ord a => WithHiding a -> WithHiding a -> Bool
compare :: WithHiding a -> WithHiding a -> Ordering
$ccompare :: forall a. Ord a => WithHiding a -> WithHiding a -> Ordering
Ord, Int -> WithHiding a -> ShowS
forall a. Show a => Int -> WithHiding a -> ShowS
forall a. Show a => [WithHiding a] -> ShowS
forall a. Show a => WithHiding a -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [WithHiding a] -> ShowS
$cshowList :: forall a. Show a => [WithHiding a] -> ShowS
show :: WithHiding a -> String
$cshow :: forall a. Show a => WithHiding a -> String
showsPrec :: Int -> WithHiding a -> ShowS
$cshowsPrec :: forall a. Show a => Int -> WithHiding a -> ShowS
Show, 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
<$ :: forall a b. a -> WithHiding b -> WithHiding a
$c<$ :: forall a b. a -> WithHiding b -> WithHiding a
fmap :: forall a b. (a -> b) -> WithHiding a -> WithHiding b
$cfmap :: forall a b. (a -> b) -> WithHiding a -> WithHiding b
Functor, 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
product :: forall a. Num a => WithHiding a -> a
$cproduct :: forall a. Num a => WithHiding a -> a
sum :: forall a. Num a => WithHiding a -> a
$csum :: forall a. Num a => WithHiding a -> a
minimum :: forall a. Ord a => WithHiding a -> a
$cminimum :: forall a. Ord a => WithHiding a -> a
maximum :: forall a. Ord a => WithHiding a -> a
$cmaximum :: forall a. Ord a => WithHiding a -> a
elem :: forall a. Eq a => a -> WithHiding a -> Bool
$celem :: forall a. Eq a => a -> WithHiding a -> Bool
length :: forall a. WithHiding a -> Int
$clength :: forall a. WithHiding a -> Int
null :: forall a. WithHiding a -> Bool
$cnull :: forall a. WithHiding a -> Bool
toList :: forall a. WithHiding a -> [a]
$ctoList :: forall a. WithHiding a -> [a]
foldl1 :: forall a. (a -> a -> a) -> WithHiding a -> a
$cfoldl1 :: forall a. (a -> a -> a) -> WithHiding a -> a
foldr1 :: forall a. (a -> a -> a) -> WithHiding a -> a
$cfoldr1 :: forall a. (a -> a -> a) -> WithHiding a -> a
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
$cfoldl :: forall b a. (b -> a -> 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
$cfoldr :: forall a b. (a -> b -> b) -> b -> WithHiding a -> b
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
$cfoldMap :: forall m a. Monoid m => (a -> m) -> WithHiding a -> m
fold :: forall m. Monoid m => WithHiding m -> m
$cfold :: forall m. Monoid m => WithHiding m -> m
Foldable, Functor WithHiding
Foldable 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)
sequence :: forall (m :: * -> *) a.
Monad m =>
WithHiding (m a) -> m (WithHiding a)
$csequence :: forall (m :: * -> *) a.
Monad m =>
WithHiding (m a) -> m (WithHiding a)
mapM :: forall (m :: * -> *) a b.
Monad m =>
(a -> m b) -> WithHiding a -> m (WithHiding b)
$cmapM :: forall (m :: * -> *) a b.
Monad m =>
(a -> m b) -> WithHiding a -> m (WithHiding b)
sequenceA :: forall (f :: * -> *) a.
Applicative f =>
WithHiding (f a) -> f (WithHiding a)
$csequenceA :: forall (f :: * -> *) a.
Applicative f =>
WithHiding (f a) -> f (WithHiding a)
traverse :: 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)
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) = forall a. Hiding -> a -> WithHiding a
WithHiding Hiding
h 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 = forall a. Hiding -> a -> WithHiding a
WithHiding 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 = forall a. Hiding -> a -> WithHiding a
WithHiding (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 = forall a. HasRange a => a -> Range
getRange forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (t :: * -> *) a. Decoration t => t a -> a
dget

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

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

instance NFData a => NFData (WithHiding a) where
  rnf :: WithHiding a -> ()
rnf (WithHiding Hiding
_ 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 = forall a. LensHiding a => (Hiding -> Hiding) -> a -> a
mapHiding (forall a b. a -> b -> a
const Hiding
h)

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

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

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

instance LensHiding Hiding where
  getHiding :: Hiding -> Hiding
getHiding = forall a. a -> a
id
  setHiding :: Hiding -> Hiding -> Hiding
setHiding = forall a b. a -> b -> a
const
  mapHiding :: (Hiding -> Hiding) -> Hiding -> Hiding
mapHiding = 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) = 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) = 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 = forall a. LensHiding a => a -> Hiding
getHiding forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall name a. Named name a -> a
namedThing
  setHiding :: Hiding -> Named nm a -> Named nm a
setHiding = forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. LensHiding a => Hiding -> a -> a
setHiding
  mapHiding :: (Hiding -> Hiding) -> Named nm a -> Named nm a
mapHiding = forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap forall b c a. (b -> c) -> (a -> b) -> a -> c
. 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) = forall a. LensHiding a => (Hiding -> Hiding) -> a -> a
mapHiding (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 = forall a. LensHiding a => a -> Hiding
getHiding a
a 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 = forall a. LensHiding a => a -> Hiding
getHiding a
a 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 = forall a. LensHiding a => a -> Hiding
getHiding a
a forall a. Eq a => a -> a -> Bool
== Hiding
Hidden

hide :: LensHiding a => a -> a
hide :: forall a. LensHiding a => a -> a
hide = 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 forall a. LensHiding a => a -> Hiding
getHiding a
x of
    Hiding
Hidden     -> a
x
    Instance{} -> a
x
    Hiding
NotHidden  -> 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 = 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 = 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 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 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 (forall a. LensHiding a => a -> Hiding
getHiding a
x, forall a. LensHiding a => a -> Hiding
getHiding b
y) of
    (Instance{}, Instance{}) -> Bool
True
    (Hiding
hx, Hiding
hy)                 -> Hiding
hx 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
forall t. Show t => Int -> UnderAddition t -> ShowS
forall t. Show t => [UnderAddition t] -> ShowS
forall t. Show t => UnderAddition t -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [UnderAddition t] -> ShowS
$cshowList :: forall t. Show t => [UnderAddition t] -> ShowS
show :: UnderAddition t -> String
$cshow :: forall t. Show t => UnderAddition t -> String
showsPrec :: Int -> UnderAddition t -> ShowS
$cshowsPrec :: forall t. Show t => Int -> UnderAddition t -> ShowS
Show, 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
<$ :: forall a b. a -> UnderAddition b -> UnderAddition a
$c<$ :: forall a b. a -> UnderAddition b -> UnderAddition a
fmap :: forall a b. (a -> b) -> UnderAddition a -> UnderAddition b
$cfmap :: forall a b. (a -> b) -> UnderAddition a -> UnderAddition b
Functor, UnderAddition t -> UnderAddition t -> Bool
forall t. Eq t => UnderAddition t -> UnderAddition t -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: UnderAddition t -> UnderAddition t -> Bool
$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
Eq, 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
min :: UnderAddition t -> UnderAddition t -> UnderAddition t
$cmin :: forall t.
Ord t =>
UnderAddition t -> UnderAddition t -> UnderAddition t
max :: UnderAddition t -> UnderAddition t -> UnderAddition t
$cmax :: forall t.
Ord t =>
UnderAddition t -> UnderAddition t -> UnderAddition t
>= :: 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
$c< :: forall t. Ord t => UnderAddition t -> UnderAddition t -> Bool
compare :: UnderAddition t -> UnderAddition t -> Ordering
$ccompare :: forall t. Ord t => UnderAddition t -> UnderAddition t -> Ordering
Ord, Comparable (UnderAddition t)
forall t. PartialOrd t => Comparable (UnderAddition t)
forall a. Comparable a -> PartialOrd a
comparable :: Comparable (UnderAddition t)
$ccomparable :: forall t. PartialOrd t => Comparable (UnderAddition t)
PartialOrd)

instance Applicative UnderAddition where
  pure :: forall a. a -> UnderAddition a
pure = forall a. a -> UnderAddition a
UnderAddition
  <*> :: forall a b.
UnderAddition (a -> b) -> UnderAddition a -> UnderAddition b
(<*>) (UnderAddition a -> b
f) (UnderAddition a
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
forall t. Show t => Int -> UnderComposition t -> ShowS
forall t. Show t => [UnderComposition t] -> ShowS
forall t. Show t => UnderComposition t -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [UnderComposition t] -> ShowS
$cshowList :: forall t. Show t => [UnderComposition t] -> ShowS
show :: UnderComposition t -> String
$cshow :: forall t. Show t => UnderComposition t -> String
showsPrec :: Int -> UnderComposition t -> ShowS
$cshowsPrec :: forall t. Show t => Int -> UnderComposition t -> ShowS
Show, 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
<$ :: forall a b. a -> UnderComposition b -> UnderComposition a
$c<$ :: forall a b. a -> UnderComposition b -> UnderComposition a
fmap :: forall a b. (a -> b) -> UnderComposition a -> UnderComposition b
$cfmap :: forall a b. (a -> b) -> UnderComposition a -> UnderComposition b
Functor, UnderComposition t -> UnderComposition t -> Bool
forall t. Eq t => UnderComposition t -> UnderComposition t -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: UnderComposition t -> UnderComposition t -> Bool
$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
Eq, 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
min :: UnderComposition t -> UnderComposition t -> UnderComposition t
$cmin :: forall t.
Ord t =>
UnderComposition t -> UnderComposition t -> UnderComposition t
max :: UnderComposition t -> UnderComposition t -> UnderComposition t
$cmax :: forall t.
Ord t =>
UnderComposition t -> UnderComposition t -> UnderComposition t
>= :: 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
$c< :: forall t. Ord t => UnderComposition t -> UnderComposition t -> Bool
compare :: UnderComposition t -> UnderComposition t -> Ordering
$ccompare :: forall t.
Ord t =>
UnderComposition t -> UnderComposition t -> Ordering
Ord, Comparable (UnderComposition t)
forall t. PartialOrd t => Comparable (UnderComposition t)
forall a. Comparable a -> PartialOrd a
comparable :: Comparable (UnderComposition t)
$ccomparable :: forall t. PartialOrd t => Comparable (UnderComposition t)
PartialOrd)

instance Applicative UnderComposition where
  pure :: forall a. a -> UnderComposition a
pure = forall a. a -> UnderComposition a
UnderComposition
  <*> :: forall a b.
UnderComposition (a -> b)
-> UnderComposition a -> UnderComposition b
(<*>) (UnderComposition a -> b
f) (UnderComposition a
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
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Modality -> Modality -> Bool
$c/= :: Modality -> Modality -> Bool
== :: Modality -> Modality -> Bool
$c== :: Modality -> Modality -> Bool
Eq, Eq 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
min :: Modality -> Modality -> Modality
$cmin :: Modality -> Modality -> Modality
max :: Modality -> Modality -> Modality
$cmax :: Modality -> Modality -> Modality
>= :: Modality -> Modality -> Bool
$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
compare :: Modality -> Modality -> Ordering
$ccompare :: Modality -> Modality -> Ordering
Ord, Int -> Modality -> ShowS
[Modality] -> ShowS
Modality -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Modality] -> ShowS
$cshowList :: [Modality] -> ShowS
show :: Modality -> String
$cshow :: Modality -> String
showsPrec :: Int -> Modality -> ShowS
$cshowsPrec :: Int -> Modality -> ShowS
Show, 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
$cto :: forall x. Rep Modality x -> Modality
$cfrom :: forall x. Modality -> Rep Modality x
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') = 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
(<>) = 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  = forall (f :: * -> *) a. Applicative f => a -> f a
pure Modality
unitModality
  mappend :: UnderComposition Modality
-> UnderComposition Modality -> UnderComposition Modality
mappend = 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 = 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
(<>) = 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  = forall (f :: * -> *) a. Applicative f => a -> f a
pure Modality
zeroModality
  mappend :: UnderAddition Modality
-> UnderAddition Modality -> UnderAddition Modality
mappend = 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' = 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 = forall a. LensRelevance a => a -> Bool
usableRelevance Modality
m Bool -> Bool -> Bool
&& forall a. LensQuantity a => a -> Bool
usableQuantity Modality
m
  where m :: Modality
m = 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 = 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 =
  forall a. LensModality a => (Modality -> Modality) -> a -> a
mapModality (Modality
m' Modality -> Modality -> Modality
`inverseComposeModality`)
  where
  m' :: Modality
m' = 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 (forall a. LensModality a => a -> Modality
getModality a
x , 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) = 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) = forall a b c d.
(KillRange a, KillRange b, KillRange c) =>
(a -> b -> c -> d) -> a -> b -> c -> d
killRange3 Relevance -> Quantity -> Cohesion -> Modality
Modality Relevance
r Quantity
q Cohesion
c

instance NFData Modality where

-- Lens stuff

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

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

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

class LensModality a where

  getModality :: a -> Modality

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

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

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

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

instance LensModality Modality where
  getModality :: Modality -> Modality
getModality = forall a. a -> a
id
  setModality :: Modality -> Modality -> Modality
setModality = forall a b. a -> b -> a
const
  mapModality :: (Modality -> Modality) -> Modality -> Modality
mapModality = 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 :: Relevance
modRelevance = Relevance
h }
  mapRelevance :: (Relevance -> Relevance) -> Modality -> Modality
mapRelevance Relevance -> Relevance
f Modality
m = Modality
m { modRelevance :: Relevance
modRelevance = Relevance -> Relevance
f (Modality -> Relevance
modRelevance Modality
m) }

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

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

-- default accessors for Relevance

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

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

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

-- default accessors for Quantity

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

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

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

-- default accessors for Cohesion

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

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

mapCohesionMod :: LensModality a => LensMap Cohesion a
mapCohesionMod :: forall a. LensModality a => LensMap Cohesion a
mapCohesionMod = forall a. LensModality a => (Modality -> Modality) -> a -> a
mapModality forall b c a. (b -> c) -> (a -> b) -> a -> c
. 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 -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Q0Origin] -> ShowS
$cshowList :: [Q0Origin] -> ShowS
show :: Q0Origin -> String
$cshow :: Q0Origin -> String
showsPrec :: Int -> Q0Origin -> ShowS
$cshowsPrec :: Int -> Q0Origin -> ShowS
Show, 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
$cto :: forall x. Rep Q0Origin x -> Q0Origin
$cfrom :: forall x. Q0Origin -> Rep Q0Origin x
Generic, Q0Origin -> Q0Origin -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Q0Origin -> Q0Origin -> Bool
$c/= :: Q0Origin -> Q0Origin -> Bool
== :: Q0Origin -> Q0Origin -> Bool
$c== :: Q0Origin -> Q0Origin -> Bool
Eq, Eq 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
min :: Q0Origin -> Q0Origin -> Q0Origin
$cmin :: Q0Origin -> Q0Origin -> Q0Origin
max :: Q0Origin -> Q0Origin -> Q0Origin
$cmax :: Q0Origin -> Q0Origin -> Q0Origin
>= :: Q0Origin -> Q0Origin -> Bool
$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
compare :: Q0Origin -> Q0Origin -> Ordering
$ccompare :: Q0Origin -> Q0Origin -> Ordering
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 -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Q1Origin] -> ShowS
$cshowList :: [Q1Origin] -> ShowS
show :: Q1Origin -> String
$cshow :: Q1Origin -> String
showsPrec :: Int -> Q1Origin -> ShowS
$cshowsPrec :: Int -> Q1Origin -> ShowS
Show, 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
$cto :: forall x. Rep Q1Origin x -> Q1Origin
$cfrom :: forall x. Q1Origin -> Rep Q1Origin x
Generic, Q1Origin -> Q1Origin -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Q1Origin -> Q1Origin -> Bool
$c/= :: Q1Origin -> Q1Origin -> Bool
== :: Q1Origin -> Q1Origin -> Bool
$c== :: Q1Origin -> Q1Origin -> Bool
Eq, Eq 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
min :: Q1Origin -> Q1Origin -> Q1Origin
$cmin :: Q1Origin -> Q1Origin -> Q1Origin
max :: Q1Origin -> Q1Origin -> Q1Origin
$cmax :: Q1Origin -> Q1Origin -> Q1Origin
>= :: Q1Origin -> Q1Origin -> Bool
$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
compare :: Q1Origin -> Q1Origin -> Ordering
$ccompare :: Q1Origin -> Q1Origin -> Ordering
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 -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [QωOrigin] -> ShowS
$cshowList :: [QωOrigin] -> ShowS
show :: QωOrigin -> String
$cshow :: QωOrigin -> String
showsPrec :: Int -> QωOrigin -> ShowS
$cshowsPrec :: Int -> QωOrigin -> ShowS
Show, 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
$cto :: forall x. Rep QωOrigin x -> QωOrigin
$cfrom :: forall x. QωOrigin -> Rep QωOrigin x
Generic, QωOrigin -> QωOrigin -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: QωOrigin -> QωOrigin -> Bool
$c/= :: QωOrigin -> QωOrigin -> Bool
== :: QωOrigin -> QωOrigin -> Bool
$c== :: QωOrigin -> QωOrigin -> Bool
Eq, Eq 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
min :: QωOrigin -> QωOrigin -> QωOrigin
$cmin :: QωOrigin -> QωOrigin -> QωOrigin
max :: QωOrigin -> QωOrigin -> QωOrigin
$cmax :: QωOrigin -> QωOrigin -> QωOrigin
>= :: 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
$c< :: QωOrigin -> QωOrigin -> Bool
compare :: QωOrigin -> QωOrigin -> Ordering
$ccompare :: QωOrigin -> QωOrigin -> Ordering
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
(<>) = forall a b c. ((a, b) -> c) -> a -> b -> c
curry 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 forall a b. (a -> b) -> a -> b
$ forall u t. (HasRange u, HasRange t) => u -> t -> Range
fuseRange Q0Origin
o Range
r
    (Q0Origin
o, Q0Erased Range
r) -> Range -> Q0Origin
Q0 forall a b. (a -> b) -> a -> b
$ 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 = forall a. Semigroup a => a -> a -> a
(<>)

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

instance HasRange Q0Origin where
  getRange :: Q0Origin -> Range
getRange = \case
    Q0Origin
Q0Inferred -> 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       forall a. Range' a
noRange
    Q0Erased Range
_ -> Range -> Q0Origin
Q0Erased 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
(<>) = forall a b c. ((a, b) -> c) -> a -> b -> c
curry 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 forall a b. (a -> b) -> a -> b
$ forall u t. (HasRange u, HasRange t) => u -> t -> Range
fuseRange Q1Origin
o Range
r
    (Q1Origin
o, Q1Linear Range
r) -> Range -> Q1Origin
Q1 forall a b. (a -> b) -> a -> b
$ 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 = forall a. Semigroup a => a -> a -> a
(<>)

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

instance HasRange Q1Origin where
  getRange :: Q1Origin -> Range
getRange = \case
    Q1Origin
Q1Inferred -> 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       forall a. Range' a
noRange
    Q1Linear Range
_ -> Range -> Q1Origin
Q1Linear 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
(<>) = forall a b c. ((a, b) -> c) -> a -> b -> c
curry 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
 forall a b. (a -> b) -> a -> b
$ 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
 forall a b. (a -> b) -> a -> b
$ 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 = forall a. Semigroup a => a -> a -> a
(<>)

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

instance HasRange QωOrigin where
  getRange :: QωOrigin -> Range
getRange = \case
    QωOrigin
QωInferred -> 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
       forall a. Range' a
noRange
    QωPlenty Range
_ -> Range -> QωOrigin
QωPlenty 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 -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Quantity] -> ShowS
$cshowList :: [Quantity] -> ShowS
show :: Quantity -> String
$cshow :: Quantity -> String
showsPrec :: Int -> Quantity -> ShowS
$cshowsPrec :: Int -> Quantity -> ShowS
Show, 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
$cto :: forall x. Rep Quantity x -> Quantity
$cfrom :: forall x. Quantity -> Rep Quantity x
Generic, Quantity -> Quantity -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Quantity -> Quantity -> Bool
$c/= :: Quantity -> Quantity -> Bool
== :: Quantity -> Quantity -> Bool
$c== :: Quantity -> Quantity -> Bool
Eq, Eq 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
min :: Quantity -> Quantity -> Quantity
$cmin :: Quantity -> Quantity -> Quantity
max :: Quantity -> Quantity -> Quantity
$cmax :: Quantity -> Quantity -> Quantity
>= :: Quantity -> Quantity -> Bool
$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
compare :: Quantity -> Quantity -> Ordering
$ccompare :: Quantity -> Quantity -> Ordering
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 = forall a b c. ((a, b) -> c) -> a -> b -> c
curry 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
(<>) = 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  = forall (f :: * -> *) a. Applicative f => a -> f a
pure Quantity
unitQuantity
  mappend :: UnderComposition Quantity
-> UnderComposition Quantity -> UnderComposition Quantity
mappend = 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 = 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
(<>) = 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  = forall (f :: * -> *) a. Applicative f => a -> f a
pure Quantity
zeroQuantity
  mappend :: UnderAddition Quantity
-> UnderAddition Quantity -> UnderAddition Quantity
mappend = 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 = forall a b c. ((a, b) -> c) -> a -> b -> c
curry 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 = forall a b c. ((a, b) -> c) -> a -> b -> c
curry 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 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ω forall a. Monoid a => a
mempty

-- | Absorptive element is ω.
topQuantity :: Quantity
topQuantity :: Quantity
topQuantity = QωOrigin -> Quantity
Quantityω 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' = 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 = forall a b c. ((a, b) -> c) -> a -> b -> c
curry forall a b. (a -> b) -> a -> b
$ \case
  (Quantity1 Q1Origin
o, Quantity1 Q1Origin
o') -> Q1Origin -> Quantity
Quantity1 (Q1Origin
o 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 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 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 = 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 = forall a b c. ((a, b) -> c) -> a -> b -> c
curry 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 = 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{} <- 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{} <- 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ω{} <- 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 forall a. LensQuantity a => a -> Quantity
getQuantity a
a of
  Quantity0 Q0Origin
o -> forall a. Null a => a -> Bool
null Q0Origin
o
  Quantity1 Q1Origin
o -> forall a. Null a => a -> Bool
null Q1Origin
o
  Quantityω QωOrigin
o -> 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 forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. LensQuantity a => a -> Bool
hasQuantity0

-- boilerplate instances

class LensQuantity a where

  getQuantity :: a -> Quantity

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

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

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

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

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

instance HasRange Quantity where
  getRange :: Quantity -> Range
getRange = \case
    Quantity0 Q0Origin
o -> forall a. HasRange a => a -> Range
getRange Q0Origin
o
    Quantity1 Q1Origin
o -> forall a. HasRange a => a -> Range
getRange Q1Origin
o
    Quantityω QωOrigin
o -> 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 forall a b. (a -> b) -> a -> b
$ forall a. SetRange a => Range -> a -> a
setRange Range
r Q0Origin
o
    Quantity1 Q1Origin
o -> Q1Origin -> Quantity
Quantity1 forall a b. (a -> b) -> a -> b
$ forall a. SetRange a => Range -> a -> a
setRange Range
r Q1Origin
o
    Quantityω QωOrigin
o -> QωOrigin -> Quantity
Quantityω forall a b. (a -> b) -> a -> b
$ 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 forall a b. (a -> b) -> a -> b
$ forall a. KillRange a => KillRangeT a
killRange Q0Origin
o
    Quantity1 Q1Origin
o -> Q1Origin -> Quantity
Quantity1 forall a b. (a -> b) -> a -> b
$ forall a. KillRange a => KillRangeT a
killRange Q1Origin
o
    Quantityω QωOrigin
o -> QωOrigin -> Quantity
Quantityω forall a b. (a -> b) -> a -> b
$ forall a. KillRange a => KillRangeT a
killRange QωOrigin
o

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

-- ** Erased.

-- | A special case of 'Quantity': erased or not.

data Erased
  = Erased Q0Origin
  | NotErased QωOrigin
  deriving (Int -> Erased -> ShowS
[Erased] -> ShowS
Erased -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Erased] -> ShowS
$cshowList :: [Erased] -> ShowS
show :: Erased -> String
$cshow :: Erased -> String
showsPrec :: Int -> Erased -> ShowS
$cshowsPrec :: Int -> Erased -> ShowS
Show, Erased -> Erased -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Erased -> Erased -> Bool
$c/= :: Erased -> Erased -> Bool
== :: Erased -> Erased -> Bool
$c== :: Erased -> Erased -> Bool
Eq, 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
$cto :: forall x. Rep Erased x -> Erased
$cfrom :: forall x. Erased -> Rep Erased x
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{} -> forall a. Maybe a
Nothing
  Quantity0 Q0Origin
o -> forall a. a -> Maybe a
Just forall a b. (a -> b) -> a -> b
$ Q0Origin -> Erased
Erased    Q0Origin
o
  Quantityω QωOrigin
o -> forall a. a -> Maybe a
Just 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 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 = forall a. LensQuantity a => a -> Bool
hasQuantity0 forall b c a. (b -> c) -> (a -> b) -> a -> c
. Erased -> Quantity
asQuantity

instance NFData Erased

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

instance KillRange Erased where
  killRange :: KillRangeT Erased
killRange = \case
    Erased Q0Origin
o    -> Q0Origin -> Erased
Erased forall a b. (a -> b) -> a -> b
$ forall a. KillRange a => KillRangeT a
killRange Q0Origin
o
    NotErased QωOrigin
o -> QωOrigin -> Erased
NotErased forall a b. (a -> b) -> a -> b
$ 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 -> KillRangeT Erased
composeErased = forall a b c. ((a, b) -> c) -> a -> b -> c
curry forall a b. (a -> b) -> a -> b
$ \case
  (Erased Q0Origin
o,    Erased Q0Origin
o')    -> Q0Origin -> Erased
Erased (Q0Origin
o 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 forall a. Semigroup a => a -> a -> a
<> QωOrigin
o')

instance Semigroup (UnderComposition Erased) where
  <> :: UnderComposition Erased
-> UnderComposition Erased -> UnderComposition Erased
(<>) = forall (f :: * -> *) a b c.
Applicative f =>
(a -> b -> c) -> f a -> f b -> f c
liftA2 Erased -> KillRangeT 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.
  | Irrelevant  -- ^ The argument is irrelevant at compile- and runtime.
    deriving (Int -> Relevance -> ShowS
[Relevance] -> ShowS
Relevance -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Relevance] -> ShowS
$cshowList :: [Relevance] -> ShowS
show :: Relevance -> String
$cshow :: Relevance -> String
showsPrec :: Int -> Relevance -> ShowS
$cshowsPrec :: Int -> Relevance -> ShowS
Show, Relevance -> Relevance -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Relevance -> Relevance -> Bool
$c/= :: Relevance -> Relevance -> Bool
== :: Relevance -> Relevance -> Bool
$c== :: Relevance -> Relevance -> Bool
Eq, Int -> Relevance
Relevance -> Int
Relevance -> [Relevance]
Relevance -> Relevance
Relevance -> Relevance -> [Relevance]
Relevance -> Relevance -> Relevance -> [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
enumFromThenTo :: Relevance -> Relevance -> Relevance -> [Relevance]
$cenumFromThenTo :: Relevance -> Relevance -> Relevance -> [Relevance]
enumFromTo :: Relevance -> Relevance -> [Relevance]
$cenumFromTo :: Relevance -> Relevance -> [Relevance]
enumFromThen :: Relevance -> Relevance -> [Relevance]
$cenumFromThen :: Relevance -> Relevance -> [Relevance]
enumFrom :: Relevance -> [Relevance]
$cenumFrom :: Relevance -> [Relevance]
fromEnum :: Relevance -> Int
$cfromEnum :: Relevance -> Int
toEnum :: Int -> Relevance
$ctoEnum :: Int -> Relevance
pred :: Relevance -> Relevance
$cpred :: Relevance -> Relevance
succ :: Relevance -> Relevance
$csucc :: Relevance -> Relevance
Enum, Relevance
forall a. a -> a -> Bounded a
maxBound :: Relevance
$cmaxBound :: Relevance
minBound :: Relevance
$cminBound :: Relevance
Bounded, 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
$cto :: forall x. Rep Relevance x -> Relevance
$cfrom :: forall x. Relevance -> Rep Relevance x
Generic)

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

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

instance SetRange Relevance where
  setRange :: Range -> Relevance -> Relevance
setRange Range
_ = 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 = forall a. LensRelevance a => (Relevance -> Relevance) -> a -> a
mapRelevance (forall a b. a -> b -> a
const Relevance
h)

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

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

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

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

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

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

isNonStrict :: LensRelevance a => a -> Bool
isNonStrict :: forall a. LensRelevance a => a -> Bool
isNonStrict a
a = forall a. LensRelevance a => a -> Relevance
getRelevance a
a 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 = forall a. Ord a => a -> a -> Bool
(<=)

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

-- | More relevant is smaller.
instance Ord Relevance where
  compare :: Relevance -> Relevance -> Ordering
compare = forall a b c. ((a, b) -> c) -> a -> b -> c
curry forall a b. (a -> b) -> a -> b
$ \case
    (Relevance
r, Relevance
r') | Relevance
r 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 = 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 = 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 = 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 = 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
(<>) = 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  = forall (f :: * -> *) a. Applicative f => a -> f a
pure Relevance
unitRelevance
  mappend :: UnderComposition Relevance
-> UnderComposition Relevance -> UnderComposition Relevance
mappend = 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 = 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
(<>) = 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  = forall (f :: * -> *) a. Applicative f => a -> f a
pure Relevance
zeroRelevance
  mappend :: UnderAddition Relevance
-> UnderAddition Relevance -> UnderAddition Relevance
mappend = 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 = 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
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Annotation -> Annotation -> Bool
$c/= :: Annotation -> Annotation -> Bool
== :: Annotation -> Annotation -> Bool
$c== :: Annotation -> Annotation -> Bool
Eq, Eq 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
min :: Annotation -> Annotation -> Annotation
$cmin :: Annotation -> Annotation -> Annotation
max :: Annotation -> Annotation -> Annotation
$cmax :: Annotation -> Annotation -> Annotation
>= :: Annotation -> Annotation -> Bool
$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
compare :: Annotation -> Annotation -> Ordering
$ccompare :: Annotation -> Annotation -> Ordering
Ord, Int -> Annotation -> ShowS
[Annotation] -> ShowS
Annotation -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Annotation] -> ShowS
$cshowList :: [Annotation] -> ShowS
show :: Annotation -> String
$cshow :: Annotation -> String
showsPrec :: Int -> Annotation -> ShowS
$cshowsPrec :: Int -> Annotation -> ShowS
Show, 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
$cto :: forall x. Rep Annotation x -> Annotation
$cfrom :: forall x. Annotation -> Rep Annotation x
Generic)

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

instance KillRange Annotation where
  killRange :: Annotation -> Annotation
killRange = 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) = 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 = forall a. LensAnnotation a => Annotation -> a -> a
setAnnotation (Annotation -> Annotation
f forall a b. (a -> b) -> a -> b
$ forall a. LensAnnotation a => a -> Annotation
getAnnotation a
a) a
a

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

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

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

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


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

data Lock = IsNotLock
          | IsLock -- ^ In the future there might be different kinds of them.
                   --   For now we assume lock weakening.
  deriving (Int -> Lock -> ShowS
[Lock] -> ShowS
Lock -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Lock] -> ShowS
$cshowList :: [Lock] -> ShowS
show :: Lock -> String
$cshow :: Lock -> String
showsPrec :: Int -> Lock -> ShowS
$cshowsPrec :: Int -> Lock -> ShowS
Show, 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
$cto :: forall x. Rep Lock x -> Lock
$cfrom :: forall x. Lock -> Rep Lock x
Generic, Lock -> Lock -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Lock -> Lock -> Bool
$c/= :: Lock -> Lock -> Bool
== :: Lock -> Lock -> Bool
$c== :: Lock -> Lock -> Bool
Eq, Int -> Lock
Lock -> Int
Lock -> [Lock]
Lock -> Lock
Lock -> Lock -> [Lock]
Lock -> Lock -> Lock -> [Lock]
forall a.
(a -> a)
-> (a -> a)
-> (Int -> a)
-> (a -> Int)
-> (a -> [a])
-> (a -> a -> [a])
-> (a -> a -> [a])
-> (a -> a -> a -> [a])
-> Enum a
enumFromThenTo :: Lock -> Lock -> Lock -> [Lock]
$cenumFromThenTo :: Lock -> Lock -> Lock -> [Lock]
enumFromTo :: Lock -> Lock -> [Lock]
$cenumFromTo :: Lock -> Lock -> [Lock]
enumFromThen :: Lock -> Lock -> [Lock]
$cenumFromThen :: Lock -> Lock -> [Lock]
enumFrom :: Lock -> [Lock]
$cenumFrom :: Lock -> [Lock]
fromEnum :: Lock -> Int
$cfromEnum :: Lock -> Int
toEnum :: Int -> Lock
$ctoEnum :: Int -> Lock
pred :: Lock -> Lock
$cpred :: Lock -> Lock
succ :: Lock -> Lock
$csucc :: Lock -> Lock
Enum, Lock
forall a. a -> a -> Bounded a
maxBound :: Lock
$cmaxBound :: Lock
minBound :: Lock
$cminBound :: Lock
Bounded, Eq 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
min :: Lock -> Lock -> Lock
$cmin :: Lock -> Lock -> Lock
max :: Lock -> Lock -> Lock
$cmax :: Lock -> Lock -> Lock
>= :: Lock -> Lock -> Bool
$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
compare :: Lock -> Lock -> Ordering
$ccompare :: Lock -> Lock -> Ordering
Ord)

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

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

class LensLock a where

  getLock :: a -> Lock

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

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

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

instance LensLock ArgInfo where
  getLock :: ArgInfo -> Lock
getLock = Annotation -> Lock
annLock 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 :: Annotation
argInfoAnnotation = (ArgInfo -> Annotation
argInfoAnnotation ArgInfo
info){ annLock :: Lock
annLock = Lock
l } }

instance LensLock (Arg t) where
  getLock :: Arg t -> Lock
getLock = forall a. LensLock a => a -> Lock
getLock forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. LensArgInfo a => a -> ArgInfo
getArgInfo
  setLock :: Lock -> Arg t -> Arg t
setLock = forall a. LensArgInfo a => (ArgInfo -> ArgInfo) -> a -> a
mapArgInfo forall b c a. (b -> c) -> (a -> b) -> a -> c
. 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 -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Cohesion] -> ShowS
$cshowList :: [Cohesion] -> ShowS
show :: Cohesion -> String
$cshow :: Cohesion -> String
showsPrec :: Int -> Cohesion -> ShowS
$cshowsPrec :: Int -> Cohesion -> ShowS
Show, Cohesion -> Cohesion -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Cohesion -> Cohesion -> Bool
$c/= :: Cohesion -> Cohesion -> Bool
== :: Cohesion -> Cohesion -> Bool
$c== :: Cohesion -> Cohesion -> Bool
Eq, Int -> Cohesion
Cohesion -> Int
Cohesion -> [Cohesion]
Cohesion -> Cohesion
Cohesion -> Cohesion -> [Cohesion]
Cohesion -> Cohesion -> Cohesion -> [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
enumFromThenTo :: Cohesion -> Cohesion -> Cohesion -> [Cohesion]
$cenumFromThenTo :: Cohesion -> Cohesion -> Cohesion -> [Cohesion]
enumFromTo :: Cohesion -> Cohesion -> [Cohesion]
$cenumFromTo :: Cohesion -> Cohesion -> [Cohesion]
enumFromThen :: Cohesion -> Cohesion -> [Cohesion]
$cenumFromThen :: Cohesion -> Cohesion -> [Cohesion]
enumFrom :: Cohesion -> [Cohesion]
$cenumFrom :: Cohesion -> [Cohesion]
fromEnum :: Cohesion -> Int
$cfromEnum :: Cohesion -> Int
toEnum :: Int -> Cohesion
$ctoEnum :: Int -> Cohesion
pred :: Cohesion -> Cohesion
$cpred :: Cohesion -> Cohesion
succ :: Cohesion -> Cohesion
$csucc :: Cohesion -> Cohesion
Enum, Cohesion
forall a. a -> a -> Bounded a
maxBound :: Cohesion
$cmaxBound :: Cohesion
minBound :: Cohesion
$cminBound :: Cohesion
Bounded, 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
$cto :: forall x. Rep Cohesion x -> Cohesion
$cfrom :: forall x. Cohesion -> Rep Cohesion x
Generic)

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

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

instance SetRange Cohesion where
  setRange :: Range -> Cohesion -> Cohesion
setRange Range
_ = 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 = forall a. LensCohesion a => (Cohesion -> Cohesion) -> a -> a
mapCohesion (forall a b. a -> b -> a
const Cohesion
h)

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

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

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

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

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

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

-- | Order is given by implication: flatter is smaller.
instance Ord Cohesion where
  compare :: Cohesion -> Cohesion -> Ordering
compare = forall a b c. ((a, b) -> c) -> a -> b -> c
curry forall a b. (a -> b) -> a -> b
$ \case
    (Cohesion
r, Cohesion
r') | Cohesion
r 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 = 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 = 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 = 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
Squash     -- artificial case, should not be needed.
    (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 = 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
(<>) = 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  = forall (f :: * -> *) a. Applicative f => a -> f a
pure Cohesion
unitCohesion
  mappend :: UnderComposition Cohesion
-> UnderComposition Cohesion -> UnderComposition Cohesion
mappend = 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 = 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
(<>) = 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  = forall (f :: * -> *) a. Applicative f => a -> f a
pure Cohesion
zeroCohesion
  mappend :: UnderAddition Cohesion
-> UnderAddition Cohesion -> UnderAddition Cohesion
mappend = 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 = 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"
  deriving (Int -> Origin -> ShowS
[Origin] -> ShowS
Origin -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Origin] -> ShowS
$cshowList :: [Origin] -> ShowS
show :: Origin -> String
$cshow :: Origin -> String
showsPrec :: Int -> Origin -> ShowS
$cshowsPrec :: Int -> Origin -> ShowS
Show, Origin -> Origin -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Origin -> Origin -> Bool
$c/= :: Origin -> Origin -> Bool
== :: Origin -> Origin -> Bool
$c== :: Origin -> Origin -> Bool
Eq, Eq 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
min :: Origin -> Origin -> Origin
$cmin :: Origin -> Origin -> Origin
max :: Origin -> Origin -> Origin
$cmax :: Origin -> Origin -> Origin
>= :: Origin -> Origin -> Bool
$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
compare :: Origin -> Origin -> Ordering
$ccompare :: Origin -> Origin -> Ordering
Ord)

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

instance KillRange Origin where
  killRange :: Origin -> Origin
killRange = 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 = ()

-- | 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
forall a. Eq a => WithOrigin a -> WithOrigin a -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: WithOrigin a -> WithOrigin a -> Bool
$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
Eq, WithOrigin a -> WithOrigin a -> Bool
WithOrigin a -> WithOrigin a -> Ordering
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
min :: WithOrigin a -> WithOrigin a -> WithOrigin a
$cmin :: forall a. Ord a => WithOrigin a -> WithOrigin a -> WithOrigin a
max :: WithOrigin a -> WithOrigin a -> WithOrigin a
$cmax :: forall a. Ord a => WithOrigin a -> WithOrigin a -> WithOrigin a
>= :: 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
$c< :: forall a. Ord a => WithOrigin a -> WithOrigin a -> Bool
compare :: WithOrigin a -> WithOrigin a -> Ordering
$ccompare :: forall a. Ord a => WithOrigin a -> WithOrigin a -> Ordering
Ord, Int -> WithOrigin a -> ShowS
forall a. Show a => Int -> WithOrigin a -> ShowS
forall a. Show a => [WithOrigin a] -> ShowS
forall a. Show a => WithOrigin a -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [WithOrigin a] -> ShowS
$cshowList :: forall a. Show a => [WithOrigin a] -> ShowS
show :: WithOrigin a -> String
$cshow :: forall a. Show a => WithOrigin a -> String
showsPrec :: Int -> WithOrigin a -> ShowS
$cshowsPrec :: forall a. Show a => Int -> WithOrigin a -> ShowS
Show, 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
<$ :: forall a b. a -> WithOrigin b -> WithOrigin a
$c<$ :: forall a b. a -> WithOrigin b -> WithOrigin a
fmap :: forall a b. (a -> b) -> WithOrigin a -> WithOrigin b
$cfmap :: forall a b. (a -> b) -> WithOrigin a -> WithOrigin b
Functor, 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
product :: forall a. Num a => WithOrigin a -> a
$cproduct :: forall a. Num a => WithOrigin a -> a
sum :: forall a. Num a => WithOrigin a -> a
$csum :: forall a. Num a => WithOrigin a -> a
minimum :: forall a. Ord a => WithOrigin a -> a
$cminimum :: forall a. Ord a => WithOrigin a -> a
maximum :: forall a. Ord a => WithOrigin a -> a
$cmaximum :: forall a. Ord a => WithOrigin a -> a
elem :: forall a. Eq a => a -> WithOrigin a -> Bool
$celem :: forall a. Eq a => a -> WithOrigin a -> Bool
length :: forall a. WithOrigin a -> Int
$clength :: forall a. WithOrigin a -> Int
null :: forall a. WithOrigin a -> Bool
$cnull :: forall a. WithOrigin a -> Bool
toList :: forall a. WithOrigin a -> [a]
$ctoList :: forall a. WithOrigin a -> [a]
foldl1 :: forall a. (a -> a -> a) -> WithOrigin a -> a
$cfoldl1 :: forall a. (a -> a -> a) -> WithOrigin a -> a
foldr1 :: forall a. (a -> a -> a) -> WithOrigin a -> a
$cfoldr1 :: forall a. (a -> a -> a) -> WithOrigin a -> a
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
$cfoldl :: forall b a. (b -> a -> 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
$cfoldr :: forall a b. (a -> b -> b) -> b -> WithOrigin a -> b
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
$cfoldMap :: forall m a. Monoid m => (a -> m) -> WithOrigin a -> m
fold :: forall m. Monoid m => WithOrigin m -> m
$cfold :: forall m. Monoid m => WithOrigin m -> m
Foldable, Functor WithOrigin
Foldable 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)
sequence :: forall (m :: * -> *) a.
Monad m =>
WithOrigin (m a) -> m (WithOrigin a)
$csequence :: forall (m :: * -> *) a.
Monad m =>
WithOrigin (m a) -> m (WithOrigin a)
mapM :: forall (m :: * -> *) a b.
Monad m =>
(a -> m b) -> WithOrigin a -> m (WithOrigin b)
$cmapM :: forall (m :: * -> *) a b.
Monad m =>
(a -> m b) -> WithOrigin a -> m (WithOrigin b)
sequenceA :: forall (f :: * -> *) a.
Applicative f =>
WithOrigin (f a) -> f (WithOrigin a)
$csequenceA :: forall (f :: * -> *) a.
Applicative f =>
WithOrigin (f a) -> f (WithOrigin a)
traverse :: 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)
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) = forall a. Origin -> a -> WithOrigin a
WithOrigin Origin
h 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 = forall a. Pretty a => Int -> a -> Doc
prettyPrec Int
p forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. WithOrigin a -> a
woThing

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

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

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

instance NFData a => NFData (WithOrigin a) where
  rnf :: WithOrigin a -> ()
rnf (WithOrigin Origin
_ 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 = forall a. LensOrigin a => (Origin -> Origin) -> a -> a
mapOrigin (forall a b. a -> b -> a
const Origin
o)

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

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

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

instance LensOrigin Origin where
  getOrigin :: Origin -> Origin
getOrigin = forall a. a -> a
id
  setOrigin :: Origin -> Origin -> Origin
setOrigin = forall a b. a -> b -> a
const
  mapOrigin :: (Origin -> Origin) -> Origin -> Origin
mapOrigin = 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) = 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) = 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
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: FreeVariables -> FreeVariables -> Bool
$c/= :: FreeVariables -> FreeVariables -> Bool
== :: FreeVariables -> FreeVariables -> Bool
$c== :: FreeVariables -> FreeVariables -> Bool
Eq, Eq 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
min :: FreeVariables -> FreeVariables -> FreeVariables
$cmin :: FreeVariables -> FreeVariables -> FreeVariables
max :: FreeVariables -> FreeVariables -> FreeVariables
$cmax :: FreeVariables -> FreeVariables -> FreeVariables
>= :: FreeVariables -> FreeVariables -> Bool
$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
compare :: FreeVariables -> FreeVariables -> Ordering
$ccompare :: FreeVariables -> FreeVariables -> Ordering
Ord, Int -> FreeVariables -> ShowS
[FreeVariables] -> ShowS
FreeVariables -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [FreeVariables] -> ShowS
$cshowList :: [FreeVariables] -> ShowS
show :: FreeVariables -> String
$cshow :: FreeVariables -> String
showsPrec :: Int -> FreeVariables -> ShowS
$cshowsPrec :: Int -> 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 = forall a. Semigroup a => a -> a -> a
(<>)

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

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

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

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

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

freeVariablesFromList :: [Int] -> FreeVariables
freeVariablesFromList :: [Int] -> FreeVariables
freeVariablesFromList = forall a. Monoid a => [a] -> a
mconcat forall b c a. (b -> c) -> (a -> b) -> a -> c
. 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 = forall a.
LensFreeVariables a =>
(FreeVariables -> FreeVariables) -> a -> a
mapFreeVariables (forall a b. a -> b -> a
const FreeVariables
o)

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

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

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

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

hasNoFreeVariables :: LensFreeVariables a => a -> Bool
hasNoFreeVariables :: forall a. LensFreeVariables a => a -> Bool
hasNoFreeVariables a
x =
  case 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
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: ArgInfo -> ArgInfo -> Bool
$c/= :: ArgInfo -> ArgInfo -> Bool
== :: ArgInfo -> ArgInfo -> Bool
$c== :: ArgInfo -> ArgInfo -> Bool
Eq, Eq 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
min :: ArgInfo -> ArgInfo -> ArgInfo
$cmin :: ArgInfo -> ArgInfo -> ArgInfo
max :: ArgInfo -> ArgInfo -> ArgInfo
$cmax :: ArgInfo -> ArgInfo -> ArgInfo
>= :: ArgInfo -> ArgInfo -> Bool
$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
compare :: ArgInfo -> ArgInfo -> Ordering
$ccompare :: ArgInfo -> ArgInfo -> Ordering
Ord, Int -> ArgInfo -> ShowS
[ArgInfo] -> ShowS
ArgInfo -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [ArgInfo] -> ShowS
$cshowList :: [ArgInfo] -> ShowS
show :: ArgInfo -> String
$cshow :: ArgInfo -> String
showsPrec :: Int -> ArgInfo -> ShowS
$cshowsPrec :: Int -> ArgInfo -> ShowS
Show)

instance HasRange ArgInfo where
  getRange :: ArgInfo -> Range
getRange (ArgInfo Hiding
h Modality
m Origin
o FreeVariables
_fv Annotation
a) = 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) = forall a b c d e f.
(KillRange a, KillRange b, KillRange c, KillRange d,
 KillRange e) =>
(a -> b -> c -> d -> e -> f) -> a -> b -> c -> d -> e -> f
killRange5 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 = forall a. LensArgInfo a => (ArgInfo -> ArgInfo) -> a -> a
mapArgInfo (forall a b. a -> b -> a
const ArgInfo
ai)
  mapArgInfo :: (ArgInfo -> ArgInfo) -> a -> a
  mapArgInfo ArgInfo -> ArgInfo
f a
a = forall a. LensArgInfo a => ArgInfo -> a -> a
setArgInfo (ArgInfo -> ArgInfo
f forall a b. (a -> b) -> a -> b
$ forall a. LensArgInfo a => a -> ArgInfo
getArgInfo a
a) a
a

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

instance NFData ArgInfo where
  rnf :: ArgInfo -> ()
rnf (ArgInfo Hiding
a Modality
b Origin
c FreeVariables
d Annotation
e) = forall a. NFData a => a -> ()
rnf Hiding
a seq :: forall a b. a -> b -> b
`seq` forall a. NFData a => a -> ()
rnf Modality
b seq :: forall a b. a -> b -> b
`seq` forall a. NFData a => a -> ()
rnf Origin
c seq :: forall a b. a -> b -> b
`seq` forall a. NFData a => a -> ()
rnf FreeVariables
d seq :: forall a b. a -> b -> b
`seq` 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 :: Hiding
argInfoHiding = Hiding
h }
  mapHiding :: (Hiding -> Hiding) -> ArgInfo -> ArgInfo
mapHiding Hiding -> Hiding
f ArgInfo
ai = ArgInfo
ai { argInfoHiding :: Hiding
argInfoHiding = Hiding -> Hiding
f (ArgInfo -> Hiding
argInfoHiding ArgInfo
ai) }

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

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

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

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

-- inherited instances

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

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

instance LensCohesion ArgInfo where
  getCohesion :: ArgInfo -> Cohesion
getCohesion = forall a. LensModality a => LensGet Cohesion a
getCohesionMod
  setCohesion :: Cohesion -> ArgInfo -> ArgInfo
setCohesion = forall a. LensModality a => LensSet Cohesion a
setCohesionMod
  mapCohesion :: (Cohesion -> Cohesion) -> ArgInfo -> ArgInfo
mapCohesion = forall a. LensModality a => LensMap Cohesion a
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 Hiding a
getHidingArgInfo :: forall a. LensArgInfo a => LensGet Hiding a
getHidingArgInfo = forall a. LensHiding a => a -> Hiding
getHiding forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. LensArgInfo a => a -> ArgInfo
getArgInfo

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

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

-- default accessors for Modality

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

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

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

-- default accessors for Origin

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

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

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

-- default accessors for FreeVariables

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

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

mapFreeVariablesArgInfo :: LensArgInfo a => LensMap FreeVariables a
mapFreeVariablesArgInfo :: forall a. LensArgInfo a => LensMap FreeVariables a
mapFreeVariablesArgInfo = forall a. LensArgInfo a => (ArgInfo -> ArgInfo) -> a -> a
mapArgInfo forall b c a. (b -> c) -> (a -> b) -> a -> c
. 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 = forall a. LensHiding a => a -> Hiding
getHiding a
a forall a. Eq a => a -> a -> Bool
== Hiding
Hidden Bool -> Bool -> Bool
&& forall a. LensOrigin a => a -> Origin
getOrigin a
a 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
forall e. Eq e => Arg e -> Arg e -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Arg e -> Arg e -> Bool
$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
Eq, Arg e -> Arg e -> Bool
Arg e -> Arg e -> Ordering
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
min :: Arg e -> Arg e -> Arg e
$cmin :: forall e. Ord e => Arg e -> Arg e -> Arg e
max :: Arg e -> Arg e -> Arg e
$cmax :: forall e. Ord e => Arg e -> Arg e -> Arg e
>= :: 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
$c< :: forall e. Ord e => Arg e -> Arg e -> Bool
compare :: Arg e -> Arg e -> Ordering
$ccompare :: forall e. Ord e => Arg e -> Arg e -> Ordering
Ord, Int -> Arg e -> ShowS
forall e. Show e => Int -> Arg e -> ShowS
forall e. Show e => [Arg e] -> ShowS
forall e. Show e => Arg e -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Arg e] -> ShowS
$cshowList :: forall e. Show e => [Arg e] -> ShowS
show :: Arg e -> String
$cshow :: forall e. Show e => Arg e -> String
showsPrec :: Int -> Arg e -> ShowS
$cshowsPrec :: forall e. Show e => Int -> Arg e -> ShowS
Show, 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
<$ :: forall a b. a -> Arg b -> Arg a
$c<$ :: forall a b. a -> Arg b -> Arg a
fmap :: forall a b. (a -> b) -> Arg a -> Arg b
$cfmap :: forall a b. (a -> b) -> Arg a -> Arg b
Functor, 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
product :: forall a. Num a => Arg a -> a
$cproduct :: forall a. Num a => Arg a -> a
sum :: forall a. Num a => Arg a -> a
$csum :: forall a. Num a => Arg a -> a
minimum :: forall a. Ord a => Arg a -> a
$cminimum :: forall a. Ord a => Arg a -> a
maximum :: forall a. Ord a => Arg a -> a
$cmaximum :: forall a. Ord a => Arg a -> a
elem :: forall a. Eq a => a -> Arg a -> Bool
$celem :: forall a. Eq a => a -> Arg a -> Bool
length :: forall a. Arg a -> Int
$clength :: forall a. Arg a -> Int
null :: forall a. Arg a -> Bool
$cnull :: forall a. Arg a -> Bool
toList :: forall a. Arg a -> [a]
$ctoList :: forall a. Arg a -> [a]
foldl1 :: forall a. (a -> a -> a) -> Arg a -> a
$cfoldl1 :: forall a. (a -> a -> a) -> Arg a -> a
foldr1 :: forall a. (a -> a -> a) -> Arg a -> a
$cfoldr1 :: forall a. (a -> a -> a) -> Arg a -> a
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
$cfoldl :: forall b a. (b -> a -> 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
$cfoldr :: forall a b. (a -> b -> b) -> b -> Arg a -> b
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
$cfoldMap :: forall m a. Monoid m => (a -> m) -> Arg a -> m
fold :: forall m. Monoid m => Arg m -> m
$cfold :: forall m. Monoid m => Arg m -> m
Foldable, Functor Arg
Foldable 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)
sequence :: forall (m :: * -> *) a. Monad m => Arg (m a) -> m (Arg a)
$csequence :: forall (m :: * -> *) a. Monad m => Arg (m a) -> m (Arg a)
mapM :: forall (m :: * -> *) a b.
Monad m =>
(a -> m b) -> Arg a -> m (Arg b)
$cmapM :: forall (m :: * -> *) a b.
Monad m =>
(a -> m b) -> Arg a -> m (Arg b)
sequenceA :: forall (f :: * -> *) a. Applicative f => Arg (f a) -> f (Arg a)
$csequenceA :: forall (f :: * -> *) a. Applicative f => Arg (f a) -> f (Arg a)
traverse :: 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)
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) = forall e. ArgInfo -> e -> Arg e
Arg ArgInfo
ai 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 = forall a. HasRange a => a -> Range
getRange forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall e. Arg e -> e
unArg

instance SetRange a => SetRange (Arg a) where
  setRange :: Range -> Arg a -> Arg a
setRange Range
r = forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap forall a b. (a -> b) -> a -> b
$ 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) = forall a b c.
(KillRange a, KillRange b) =>
(a -> b -> c) -> a -> b -> c
killRange2 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) = forall a. NFData a => a -> ()
rnf ArgInfo
a seq :: forall a b. a -> b -> b
`seq` forall a. NFData a => a -> ()
rnf e
b

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

-- The other lenses are defined through LensArgInfo

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

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

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

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

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

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

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

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

defaultArg :: a -> Arg a
defaultArg :: forall a. a -> Arg a
defaultArg = 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 =
  forall a b c. (a -> b -> c) -> [a] -> [b] -> [c]
zipWith (\a
x Arg b
arg -> forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (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 =
  forall a b c. (a -> b -> c) -> [a] -> [b] -> [c]
zipWith (\a
x -> forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (a
x 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 = (forall a. Eq a => a -> a -> Bool
== forall a. Underscore a => a
underscore)

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

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

instance Underscore Doc where
  underscore :: Doc
underscore = String -> Doc
text 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
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
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
$c== :: forall name a.
(Eq name, Eq a) =>
Named name a -> Named name a -> Bool
Eq, Named name a -> Named name a -> Bool
Named name a -> Named name a -> Ordering
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
min :: 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
max :: Named name a -> Named name a -> Named name a
$cmax :: forall name a.
(Ord name, Ord a) =>
Named name a -> Named name a -> Named name a
>= :: 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
$c< :: forall name a.
(Ord name, Ord a) =>
Named name a -> Named name a -> Bool
compare :: Named name a -> Named name a -> Ordering
$ccompare :: forall name a.
(Ord name, Ord a) =>
Named name a -> Named name a -> Ordering
Ord, Int -> Named name a -> ShowS
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([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 -> String
showList :: [Named name a] -> ShowS
$cshowList :: forall name a. (Show name, Show a) => [Named name a] -> ShowS
show :: Named name a -> String
$cshow :: forall name a. (Show name, Show a) => Named name a -> String
showsPrec :: Int -> Named name a -> ShowS
$cshowsPrec :: forall name a. (Show name, Show a) => Int -> Named name a -> ShowS
Show, 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
<$ :: forall a b. a -> Named name b -> Named name a
$c<$ :: forall name a b. a -> Named name b -> Named name a
fmap :: forall a b. (a -> b) -> Named name a -> Named name b
$cfmap :: forall name a b. (a -> b) -> Named name a -> Named name b
Functor, forall a. Named name a -> Bool
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 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
product :: forall a. Num a => Named name a -> a
$cproduct :: forall name a. Num a => Named name a -> a
sum :: forall a. Num a => Named name a -> a
$csum :: forall name a. Num a => Named name a -> a
minimum :: forall a. Ord a => Named name a -> a
$cminimum :: forall name a. Ord a => Named name a -> a
maximum :: forall a. Ord a => Named name a -> a
$cmaximum :: forall name a. Ord a => Named name a -> a
elem :: forall a. Eq a => a -> Named name a -> Bool
$celem :: forall name a. Eq a => a -> Named name a -> Bool
length :: forall a. Named name a -> Int
$clength :: forall name a. Named name a -> Int
null :: forall a. Named name a -> Bool
$cnull :: forall name a. Named name a -> Bool
toList :: forall a. Named name a -> [a]
$ctoList :: forall name a. Named name a -> [a]
foldl1 :: forall a. (a -> a -> a) -> Named name a -> a
$cfoldl1 :: forall name a. (a -> a -> a) -> Named name a -> a
foldr1 :: forall a. (a -> a -> a) -> Named name a -> a
$cfoldr1 :: forall name a. (a -> a -> a) -> Named name a -> a
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
$cfoldl :: forall name b a. (b -> a -> 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
$cfoldr :: forall name a b. (a -> b -> b) -> b -> Named name a -> b
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
$cfoldMap :: forall name m a. Monoid m => (a -> m) -> Named name a -> m
fold :: forall m. Monoid m => Named name m -> m
$cfold :: forall name m. Monoid m => Named name m -> m
Foldable, 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 (f :: * -> *) a b.
Applicative f =>
(a -> f b) -> Named name a -> f (Named name b)
sequence :: forall (m :: * -> *) a.
Monad m =>
Named name (m a) -> m (Named name a)
$csequence :: forall name (m :: * -> *) a.
Monad m =>
Named name (m a) -> m (Named name a)
mapM :: forall (m :: * -> *) a b.
Monad m =>
(a -> m b) -> Named name a -> m (Named name b)
$cmapM :: forall name (m :: * -> *) a b.
Monad m =>
(a -> m b) -> Named name a -> m (Named name b)
sequenceA :: forall (f :: * -> *) a.
Applicative f =>
Named name (f a) -> f (Named name a)
$csequenceA :: forall name (f :: * -> *) a.
Applicative f =>
Named name (f a) -> f (Named name a)
traverse :: 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)
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 = forall a. Eq a => a -> a -> Bool
(==) forall b c a. (b -> b -> c) -> (a -> b) -> a -> a -> c
`on` (forall a. Ranged a -> a
rangedThing forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. WithOrigin a -> a
woThing)

unnamed :: a -> Named name a
unnamed :: forall a name. a -> Named name a
unnamed = forall name a. Maybe name -> a -> Named name a
Named 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 -> forall a. a -> Maybe a
Just a
a
  Named Just{}  a
a -> forall a. Maybe a
Nothing

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

userNamed :: Ranged ArgName -> a -> Named_ a
userNamed :: forall a. Ranged String -> a -> Named_ a
userNamed = forall name a. Maybe name -> a -> Named name a
Named forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. a -> Maybe a
Just forall b c a. (b -> c) -> (a -> b) -> a -> c
. 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' (Maybe (NameOf a)) a

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

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

  lensNamed :: Lens' (Maybe (NameOf (Named name a))) (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
mn forall (m :: * -> *) a b. Functor m => m a -> (a -> b) -> m b
<&> \ Maybe name
mn' -> 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 forall o i. o -> Lens' i o -> i
^. forall a. LensNamed a => Lens' (Maybe (NameOf a)) a
lensNamed

setNameOf :: LensNamed a => Maybe (NameOf a) -> a -> a
setNameOf :: forall a. LensNamed a => Maybe (NameOf a) -> a -> a
setNameOf = forall i o. Lens' i o -> LensSet i o
set forall a. LensNamed a => Lens' (Maybe (NameOf a)) 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 = forall i o. Lens' i o -> LensMap i o
over forall a. LensNamed a => Lens' (Maybe (NameOf a)) a
lensNamed
bareNameOf :: (LensNamed a, NameOf a ~ NamedName) => a -> Maybe ArgName
bareNameOf :: forall a. (LensNamed a, NameOf a ~ NamedName) => a -> Maybe String
bareNameOf a
a = forall a. Ranged a -> a
rangedThing forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. WithOrigin a -> a
woThing forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> 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) =>
String -> a -> String
bareNameWithDefault String
x a
a = forall b a. b -> (a -> b) -> Maybe a -> b
maybe String
x (forall a. Ranged a -> a
rangedThing forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. WithOrigin a -> a
woThing) forall a b. (a -> b) -> a -> b
$ 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 (forall a. LensNamed a => a -> Maybe (NameOf a)
getNameOf a
a, 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 forall a b. (a -> b) -> a -> b
$ forall a b. (LensHiding a, LensHiding b) => a -> b -> Bool
sameHiding arg
arg dom
dom = Maybe Bool
no
    | forall a. LensHiding a => a -> Bool
visible arg
arg              = Maybe Bool
yes
    | Bool
otherwise =
        forall a b. Maybe a -> b -> (a -> b) -> b
caseMaybe (forall a. (LensNamed a, NameOf a ~ NamedName) => a -> Maybe String
bareNameOf arg
arg) Maybe Bool
yes        forall a b. (a -> b) -> a -> b
$ \ String
x ->
        forall a b. Maybe a -> b -> (a -> b) -> b
caseMaybe (forall a. (LensNamed a, NameOf a ~ NamedName) => a -> Maybe String
bareNameOf dom
dom) forall a. Maybe a
impossible forall a b. (a -> b) -> a -> b
$ \ String
y ->
        forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ String
x forall a. Eq a => a -> a -> Bool
== String
y
  where
    yes :: Maybe Bool
yes = forall (m :: * -> *) a. Monad m => a -> m a
return Bool
True
    no :: Maybe Bool
no  = forall (m :: * -> *) a. Monad m => a -> m a
return Bool
False
    impossible :: Maybe a
impossible = 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) = forall name a. Maybe name -> a -> Named name a
Named Maybe name
n 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 = forall a. HasRange a => a -> Range
getRange forall b c a. (b -> c) -> (a -> b) -> a -> c
. 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 = forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap forall a b. (a -> b) -> a -> b
$ 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) = forall name a. Maybe name -> a -> Named name a
Named (forall a. KillRange a => KillRangeT a
killRange Maybe name
n) (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) = forall a. NFData a => a -> ()
rnf Maybe name
a seq :: forall a b. a -> b -> b
`seq` 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 = forall name a. Named name a -> a
namedThing forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall e. Arg e -> e
unArg

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

unnamedArg :: ArgInfo -> a -> NamedArg a
unnamedArg :: forall a. ArgInfo -> a -> NamedArg a
unnamedArg ArgInfo
info = forall e. ArgInfo -> e -> Arg e
Arg ArgInfo
info forall b c a. (b -> c) -> (a -> b) -> a -> c
. 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 = forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap forall b c a. (b -> c) -> (a -> b) -> a -> c
. 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 = forall (t :: * -> *) (f :: * -> *) a b.
(Traversable t, Applicative f) =>
(a -> f b) -> t a -> f (t b)
traverse forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (t :: * -> *) (f :: * -> *) a b.
(Traversable t, Applicative f) =>
(a -> f b) -> t a -> f (t 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 forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$) 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 = forall a. a -> a
id

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

appendArgNames :: ArgName -> ArgName -> ArgName
appendArgNames :: String -> ShowS
appendArgNames = 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
forall a. Show a => Int -> Ranged a -> ShowS
forall a. Show a => [Ranged a] -> ShowS
forall a. Show a => Ranged a -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Ranged a] -> ShowS
$cshowList :: forall a. Show a => [Ranged a] -> ShowS
show :: Ranged a -> String
$cshow :: forall a. Show a => Ranged a -> String
showsPrec :: Int -> Ranged a -> ShowS
$cshowsPrec :: forall a. Show a => Int -> Ranged a -> ShowS
Show, 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
<$ :: forall a b. a -> Ranged b -> Ranged a
$c<$ :: forall a b. a -> Ranged b -> Ranged a
fmap :: forall a b. (a -> b) -> Ranged a -> Ranged b
$cfmap :: forall a b. (a -> b) -> Ranged a -> Ranged b
Functor, 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
product :: forall a. Num a => Ranged a -> a
$cproduct :: forall a. Num a => Ranged a -> a
sum :: forall a. Num a => Ranged a -> a
$csum :: forall a. Num a => Ranged a -> a
minimum :: forall a. Ord a => Ranged a -> a
$cminimum :: forall a. Ord a => Ranged a -> a
maximum :: forall a. Ord a => Ranged a -> a
$cmaximum :: forall a. Ord a => Ranged a -> a
elem :: forall a. Eq a => a -> Ranged a -> Bool
$celem :: forall a. Eq a => a -> Ranged a -> Bool
length :: forall a. Ranged a -> Int
$clength :: forall a. Ranged a -> Int
null :: forall a. Ranged a -> Bool
$cnull :: forall a. Ranged a -> Bool
toList :: forall a. Ranged a -> [a]
$ctoList :: forall a. Ranged a -> [a]
foldl1 :: forall a. (a -> a -> a) -> Ranged a -> a
$cfoldl1 :: forall a. (a -> a -> a) -> Ranged a -> a
foldr1 :: forall a. (a -> a -> a) -> Ranged a -> a
$cfoldr1 :: forall a. (a -> a -> a) -> Ranged a -> a
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
$cfoldl :: forall b a. (b -> a -> 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
$cfoldr :: forall a b. (a -> b -> b) -> b -> Ranged a -> b
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
$cfoldMap :: forall m a. Monoid m => (a -> m) -> Ranged a -> m
fold :: forall m. Monoid m => Ranged m -> m
$cfold :: forall m. Monoid m => Ranged m -> m
Foldable, Functor Ranged
Foldable 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)
sequence :: forall (m :: * -> *) a. Monad m => Ranged (m a) -> m (Ranged a)
$csequence :: forall (m :: * -> *) a. Monad m => Ranged (m a) -> m (Ranged a)
mapM :: forall (m :: * -> *) a b.
Monad m =>
(a -> m b) -> Ranged a -> m (Ranged b)
$cmapM :: forall (m :: * -> *) a b.
Monad m =>
(a -> m b) -> Ranged a -> m (Ranged b)
sequenceA :: forall (f :: * -> *) a.
Applicative f =>
Ranged (f a) -> f (Ranged a)
$csequenceA :: forall (f :: * -> *) a.
Applicative f =>
Ranged (f a) -> f (Ranged a)
traverse :: 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)
Traversable)

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

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

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

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

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

instance KillRange (Ranged a) where
  killRange :: KillRangeT (Ranged a)
killRange (Ranged Range
_ a
x) = forall a. Range -> a -> Ranged a
Ranged 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) = forall a. Range -> a -> Ranged a
Ranged Range
r 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) = 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 = forall a. a -> a
id

stringToRawName :: String -> RawName
stringToRawName :: ShowS
stringToRawName = 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 -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [ConOrigin] -> ShowS
$cshowList :: [ConOrigin] -> ShowS
show :: ConOrigin -> String
$cshow :: ConOrigin -> String
showsPrec :: Int -> ConOrigin -> ShowS
$cshowsPrec :: Int -> ConOrigin -> ShowS
Show, ConOrigin -> ConOrigin -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: ConOrigin -> ConOrigin -> Bool
$c/= :: ConOrigin -> ConOrigin -> Bool
== :: ConOrigin -> ConOrigin -> Bool
$c== :: ConOrigin -> ConOrigin -> Bool
Eq, Eq 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
min :: ConOrigin -> ConOrigin -> ConOrigin
$cmin :: ConOrigin -> ConOrigin -> ConOrigin
max :: ConOrigin -> ConOrigin -> ConOrigin
$cmax :: ConOrigin -> ConOrigin -> ConOrigin
>= :: ConOrigin -> ConOrigin -> Bool
$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
compare :: ConOrigin -> ConOrigin -> Ordering
$ccompare :: ConOrigin -> ConOrigin -> Ordering
Ord, Int -> ConOrigin
ConOrigin -> Int
ConOrigin -> [ConOrigin]
ConOrigin -> ConOrigin
ConOrigin -> ConOrigin -> [ConOrigin]
ConOrigin -> ConOrigin -> ConOrigin -> [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
enumFromThenTo :: ConOrigin -> ConOrigin -> ConOrigin -> [ConOrigin]
$cenumFromThenTo :: ConOrigin -> ConOrigin -> ConOrigin -> [ConOrigin]
enumFromTo :: ConOrigin -> ConOrigin -> [ConOrigin]
$cenumFromTo :: ConOrigin -> ConOrigin -> [ConOrigin]
enumFromThen :: ConOrigin -> ConOrigin -> [ConOrigin]
$cenumFromThen :: ConOrigin -> ConOrigin -> [ConOrigin]
enumFrom :: ConOrigin -> [ConOrigin]
$cenumFrom :: ConOrigin -> [ConOrigin]
fromEnum :: ConOrigin -> Int
$cfromEnum :: ConOrigin -> Int
toEnum :: Int -> ConOrigin
$ctoEnum :: Int -> ConOrigin
pred :: ConOrigin -> ConOrigin
$cpred :: ConOrigin -> ConOrigin
succ :: ConOrigin -> ConOrigin
$csucc :: ConOrigin -> ConOrigin
Enum, ConOrigin
forall a. a -> a -> Bounded a
maxBound :: ConOrigin
$cmaxBound :: ConOrigin
minBound :: ConOrigin
$cminBound :: ConOrigin
Bounded, 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
$cto :: forall x. Rep ConOrigin x -> ConOrigin
$cfrom :: forall x. ConOrigin -> Rep ConOrigin x
Generic)

instance NFData ConOrigin

instance KillRange ConOrigin where
  killRange :: ConOrigin -> ConOrigin
killRange = 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 -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [ProjOrigin] -> ShowS
$cshowList :: [ProjOrigin] -> ShowS
show :: ProjOrigin -> String
$cshow :: ProjOrigin -> String
showsPrec :: Int -> ProjOrigin -> ShowS
$cshowsPrec :: Int -> ProjOrigin -> ShowS
Show, ProjOrigin -> ProjOrigin -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: ProjOrigin -> ProjOrigin -> Bool
$c/= :: ProjOrigin -> ProjOrigin -> Bool
== :: ProjOrigin -> ProjOrigin -> Bool
$c== :: ProjOrigin -> ProjOrigin -> Bool
Eq, Eq 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
min :: ProjOrigin -> ProjOrigin -> ProjOrigin
$cmin :: ProjOrigin -> ProjOrigin -> ProjOrigin
max :: ProjOrigin -> ProjOrigin -> ProjOrigin
$cmax :: ProjOrigin -> ProjOrigin -> ProjOrigin
>= :: ProjOrigin -> ProjOrigin -> Bool
$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
compare :: ProjOrigin -> ProjOrigin -> Ordering
$ccompare :: ProjOrigin -> ProjOrigin -> Ordering
Ord, Int -> ProjOrigin
ProjOrigin -> Int
ProjOrigin -> [ProjOrigin]
ProjOrigin -> ProjOrigin
ProjOrigin -> ProjOrigin -> [ProjOrigin]
ProjOrigin -> ProjOrigin -> ProjOrigin -> [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
enumFromThenTo :: ProjOrigin -> ProjOrigin -> ProjOrigin -> [ProjOrigin]
$cenumFromThenTo :: ProjOrigin -> ProjOrigin -> ProjOrigin -> [ProjOrigin]
enumFromTo :: ProjOrigin -> ProjOrigin -> [ProjOrigin]
$cenumFromTo :: ProjOrigin -> ProjOrigin -> [ProjOrigin]
enumFromThen :: ProjOrigin -> ProjOrigin -> [ProjOrigin]
$cenumFromThen :: ProjOrigin -> ProjOrigin -> [ProjOrigin]
enumFrom :: ProjOrigin -> [ProjOrigin]
$cenumFrom :: ProjOrigin -> [ProjOrigin]
fromEnum :: ProjOrigin -> Int
$cfromEnum :: ProjOrigin -> Int
toEnum :: Int -> ProjOrigin
$ctoEnum :: Int -> ProjOrigin
pred :: ProjOrigin -> ProjOrigin
$cpred :: ProjOrigin -> ProjOrigin
succ :: ProjOrigin -> ProjOrigin
$csucc :: ProjOrigin -> ProjOrigin
Enum, ProjOrigin
forall a. a -> a -> Bounded a
maxBound :: ProjOrigin
$cmaxBound :: ProjOrigin
minBound :: ProjOrigin
$cminBound :: ProjOrigin
Bounded, 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
$cto :: forall x. Rep ProjOrigin x -> ProjOrigin
$cfrom :: forall x. ProjOrigin -> Rep ProjOrigin x
Generic)

instance NFData ProjOrigin

instance KillRange ProjOrigin where
  killRange :: ProjOrigin -> ProjOrigin
killRange = 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 -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [IsInfix] -> ShowS
$cshowList :: [IsInfix] -> ShowS
show :: IsInfix -> String
$cshow :: IsInfix -> String
showsPrec :: Int -> IsInfix -> ShowS
$cshowsPrec :: Int -> IsInfix -> ShowS
Show, IsInfix -> IsInfix -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: IsInfix -> IsInfix -> Bool
$c/= :: IsInfix -> IsInfix -> Bool
== :: IsInfix -> IsInfix -> Bool
$c== :: IsInfix -> IsInfix -> Bool
Eq, Eq 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
min :: IsInfix -> IsInfix -> IsInfix
$cmin :: IsInfix -> IsInfix -> IsInfix
max :: IsInfix -> IsInfix -> IsInfix
$cmax :: IsInfix -> IsInfix -> IsInfix
>= :: IsInfix -> IsInfix -> Bool
$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
compare :: IsInfix -> IsInfix -> Ordering
$ccompare :: IsInfix -> IsInfix -> Ordering
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 -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Access] -> ShowS
$cshowList :: [Access] -> ShowS
show :: Access -> String
$cshow :: Access -> String
showsPrec :: Int -> Access -> ShowS
$cshowsPrec :: Int -> Access -> ShowS
Show, Access -> Access -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Access -> Access -> Bool
$c/= :: Access -> Access -> Bool
== :: Access -> Access -> Bool
$c== :: Access -> Access -> Bool
Eq, Eq 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
min :: Access -> Access -> Access
$cmin :: Access -> Access -> Access
max :: Access -> Access -> Access
$cmax :: Access -> Access -> Access
>= :: Access -> Access -> Bool
$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
compare :: Access -> Access -> Ordering
$ccompare :: Access -> Access -> Ordering
Ord)

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

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

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

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

-- ** abstract blocks

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

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

instance NFData IsAbstract

class LensIsAbstract a where
  lensIsAbstract :: Lens' IsAbstract a

instance LensIsAbstract IsAbstract where
  lensIsAbstract :: Lens' IsAbstract IsAbstract
lensIsAbstract = 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 = forall (t :: * -> *) m a.
(Foldable t, Monoid m) =>
(a -> m) -> t a -> m
Fold.foldMap forall a. AnyIsAbstract a => a -> IsAbstract
anyIsAbstract

instance AnyIsAbstract IsAbstract where
  anyIsAbstract :: IsAbstract -> IsAbstract
anyIsAbstract = 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 -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [IsInstance] -> ShowS
$cshowList :: [IsInstance] -> ShowS
show :: IsInstance -> String
$cshow :: IsInstance -> String
showsPrec :: Int -> IsInstance -> ShowS
$cshowsPrec :: Int -> IsInstance -> ShowS
Show, IsInstance -> IsInstance -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: IsInstance -> IsInstance -> Bool
$c/= :: IsInstance -> IsInstance -> Bool
== :: IsInstance -> IsInstance -> Bool
$c== :: IsInstance -> IsInstance -> Bool
Eq, Eq 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
min :: IsInstance -> IsInstance -> IsInstance
$cmin :: IsInstance -> IsInstance -> IsInstance
max :: IsInstance -> IsInstance -> IsInstance
$cmax :: IsInstance -> IsInstance -> IsInstance
>= :: IsInstance -> IsInstance -> Bool
$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
compare :: IsInstance -> IsInstance -> Ordering
$ccompare :: IsInstance -> IsInstance -> Ordering
Ord)

instance KillRange IsInstance where
  killRange :: IsInstance -> IsInstance
killRange = \case
    InstanceDef Range
_    -> Range -> IsInstance
InstanceDef 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 -> 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 -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [IsMacro] -> ShowS
$cshowList :: [IsMacro] -> ShowS
show :: IsMacro -> String
$cshow :: IsMacro -> String
showsPrec :: Int -> IsMacro -> ShowS
$cshowsPrec :: Int -> IsMacro -> ShowS
Show, IsMacro -> IsMacro -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: IsMacro -> IsMacro -> Bool
$c/= :: IsMacro -> IsMacro -> Bool
== :: IsMacro -> IsMacro -> Bool
$c== :: IsMacro -> IsMacro -> Bool
Eq, Eq 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
min :: IsMacro -> IsMacro -> IsMacro
$cmin :: IsMacro -> IsMacro -> IsMacro
max :: IsMacro -> IsMacro -> IsMacro
$cmax :: IsMacro -> IsMacro -> IsMacro
>= :: IsMacro -> IsMacro -> Bool
$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
compare :: IsMacro -> IsMacro -> Ordering
$ccompare :: IsMacro -> IsMacro -> Ordering
Ord, 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
$cto :: forall x. Rep IsMacro x -> IsMacro
$cfrom :: forall x. IsMacro -> Rep IsMacro x
Generic)

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

instance NFData IsMacro

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

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

instance HasTag ModuleNameHash where
  type Tag ModuleNameHash = ModuleNameHash
  tag :: ModuleNameHash -> Maybe (Tag ModuleNameHash)
tag = forall a. a -> Maybe a
Just forall b c a. (b -> c) -> (a -> b) -> a -> c
. 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 forall a. Ord a => a -> a -> Bool
> Int
0) forall a b. (a -> b) -> a -> b
$
    String -> ShowS
showString String
"ModuleNameHash " forall b c a. (b -> c) -> (a -> b) -> a -> c
. 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
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: NameId -> NameId -> Bool
$c/= :: NameId -> NameId -> Bool
== :: NameId -> NameId -> Bool
$c== :: NameId -> NameId -> Bool
Eq, Eq 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
min :: NameId -> NameId -> NameId
$cmin :: NameId -> NameId -> NameId
max :: NameId -> NameId -> NameId
$cmax :: NameId -> NameId -> NameId
>= :: NameId -> NameId -> Bool
$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
compare :: NameId -> NameId -> Ordering
$ccompare :: NameId -> NameId -> Ordering
Ord, 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
$cto :: forall x. Rep NameId x -> NameId
$cfrom :: forall x. NameId -> Rep NameId x
Generic, Int -> NameId -> ShowS
[NameId] -> ShowS
NameId -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [NameId] -> ShowS
$cshowList :: [NameId] -> ShowS
show :: NameId -> String
$cshow :: NameId -> String
showsPrec :: Int -> NameId -> ShowS
$cshowsPrec :: Int -> NameId -> ShowS
Show)

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

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

instance Enum NameId where
  succ :: NameId -> NameId
succ (NameId Word64
n ModuleNameHash
m)     = Word64 -> ModuleNameHash -> NameId
NameId (Word64
n 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 forall a. Num a => a -> a -> a
- Word64
1) ModuleNameHash
m
  toEnum :: Int -> NameId
toEnum Int
n              = forall a. HasCallStack => a
__IMPOSSIBLE__  -- should not be used
  fromEnum :: NameId -> Int
fromEnum (NameId Word64
n ModuleNameHash
_) = 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)) = 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
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: MetaId -> MetaId -> Bool
$c/= :: MetaId -> MetaId -> Bool
== :: MetaId -> MetaId -> Bool
$c== :: MetaId -> MetaId -> Bool
Eq, Eq 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
min :: MetaId -> MetaId -> MetaId
$cmin :: MetaId -> MetaId -> MetaId
max :: MetaId -> MetaId -> MetaId
$cmax :: MetaId -> MetaId -> MetaId
>= :: MetaId -> MetaId -> Bool
$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
compare :: MetaId -> MetaId -> Ordering
$ccompare :: MetaId -> MetaId -> Ordering
Ord, 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
$cto :: forall x. Rep MetaId x -> MetaId
$cfrom :: forall x. MetaId -> Rep MetaId x
Generic)

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

instance Enum MetaId where
  succ :: MetaId -> MetaId
succ MetaId{Word64
ModuleNameHash
metaModule :: ModuleNameHash
metaId :: Word64
metaModule :: MetaId -> ModuleNameHash
metaId :: MetaId -> Word64
..} = MetaId { metaId :: Word64
metaId = forall a. Enum a => a -> a
succ Word64
metaId, ModuleNameHash
metaModule :: ModuleNameHash
metaModule :: ModuleNameHash
.. }
  pred :: MetaId -> MetaId
pred MetaId{Word64
ModuleNameHash
metaModule :: ModuleNameHash
metaId :: Word64
metaModule :: MetaId -> ModuleNameHash
metaId :: MetaId -> Word64
..} = MetaId { metaId :: Word64
metaId = 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   = forall a. HasCallStack => a
__IMPOSSIBLE__
  fromEnum :: MetaId -> Int
fromEnum = 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 forall a. Ord a => a -> a -> Bool
> Int
0) forall a b. (a -> b) -> a -> b
$
    String -> ShowS
showString String
"MetaId " forall b c a. (b -> c) -> (a -> b) -> a -> c
.
    forall a. Show a => Int -> a -> ShowS
showsPrec Int
11 Word64
n forall b c a. (b -> c) -> (a -> b) -> a -> c
.
    String -> ShowS
showString String
" " forall b c a. (b -> c) -> (a -> b) -> a -> c
.
    forall a. Show a => Int -> a -> ShowS
showsPrec Int
11 ModuleNameHash
m

instance NFData MetaId where
  rnf :: MetaId -> ()
rnf (MetaId Word64
x ModuleNameHash
y) = forall a. NFData a => a -> ()
rnf Word64
x seq :: forall a b. a -> b -> b
`seq` 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) = 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
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: ProblemId -> ProblemId -> Bool
$c/= :: ProblemId -> ProblemId -> Bool
== :: ProblemId -> ProblemId -> Bool
$c== :: ProblemId -> ProblemId -> Bool
Eq, Eq 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
min :: ProblemId -> ProblemId -> ProblemId
$cmin :: ProblemId -> ProblemId -> ProblemId
max :: ProblemId -> ProblemId -> ProblemId
$cmax :: ProblemId -> ProblemId -> ProblemId
>= :: ProblemId -> ProblemId -> Bool
$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
compare :: ProblemId -> ProblemId -> Ordering
$ccompare :: ProblemId -> ProblemId -> Ordering
Ord, Int -> ProblemId
ProblemId -> Int
ProblemId -> [ProblemId]
ProblemId -> ProblemId
ProblemId -> ProblemId -> [ProblemId]
ProblemId -> ProblemId -> ProblemId -> [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
enumFromThenTo :: ProblemId -> ProblemId -> ProblemId -> [ProblemId]
$cenumFromThenTo :: ProblemId -> ProblemId -> ProblemId -> [ProblemId]
enumFromTo :: ProblemId -> ProblemId -> [ProblemId]
$cenumFromTo :: ProblemId -> ProblemId -> [ProblemId]
enumFromThen :: ProblemId -> ProblemId -> [ProblemId]
$cenumFromThen :: ProblemId -> ProblemId -> [ProblemId]
enumFrom :: ProblemId -> [ProblemId]
$cenumFrom :: ProblemId -> [ProblemId]
fromEnum :: ProblemId -> Int
$cfromEnum :: ProblemId -> Int
toEnum :: Int -> ProblemId
$ctoEnum :: Int -> ProblemId
pred :: ProblemId -> ProblemId
$cpred :: ProblemId -> ProblemId
succ :: ProblemId -> ProblemId
$csucc :: ProblemId -> ProblemId
Enum, Num ProblemId
Ord ProblemId
ProblemId -> Rational
forall a. Num a -> Ord a -> (a -> Rational) -> Real a
toRational :: ProblemId -> Rational
$ctoRational :: ProblemId -> Rational
Real, Enum ProblemId
Real 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
toInteger :: ProblemId -> Integer
$ctoInteger :: ProblemId -> Integer
divMod :: ProblemId -> ProblemId -> (ProblemId, ProblemId)
$cdivMod :: ProblemId -> ProblemId -> (ProblemId, ProblemId)
quotRem :: ProblemId -> ProblemId -> (ProblemId, ProblemId)
$cquotRem :: ProblemId -> ProblemId -> (ProblemId, ProblemId)
mod :: ProblemId -> ProblemId -> ProblemId
$cmod :: ProblemId -> ProblemId -> ProblemId
div :: ProblemId -> ProblemId -> ProblemId
$cdiv :: ProblemId -> ProblemId -> ProblemId
rem :: ProblemId -> ProblemId -> ProblemId
$crem :: ProblemId -> ProblemId -> ProblemId
quot :: ProblemId -> ProblemId -> ProblemId
$cquot :: ProblemId -> ProblemId -> ProblemId
Integral, Integer -> ProblemId
ProblemId -> ProblemId
ProblemId -> ProblemId -> ProblemId
forall a.
(a -> a -> a)
-> (a -> a -> a)
-> (a -> a -> a)
-> (a -> a)
-> (a -> a)
-> (a -> a)
-> (Integer -> a)
-> Num a
fromInteger :: Integer -> ProblemId
$cfromInteger :: Integer -> ProblemId
signum :: ProblemId -> ProblemId
$csignum :: ProblemId -> ProblemId
abs :: ProblemId -> ProblemId
$cabs :: ProblemId -> ProblemId
negate :: ProblemId -> ProblemId
$cnegate :: ProblemId -> ProblemId
* :: ProblemId -> ProblemId -> ProblemId
$c* :: ProblemId -> ProblemId -> ProblemId
- :: ProblemId -> ProblemId -> ProblemId
$c- :: ProblemId -> ProblemId -> ProblemId
+ :: ProblemId -> ProblemId -> ProblemId
$c+ :: ProblemId -> ProblemId -> ProblemId
Num, ProblemId -> ()
forall a. (a -> ()) -> NFData a
rnf :: ProblemId -> ()
$crnf :: ProblemId -> ()
NFData)

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

------------------------------------------------------------------------
-- * 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 -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [PositionInName] -> ShowS
$cshowList :: [PositionInName] -> ShowS
show :: PositionInName -> String
$cshow :: PositionInName -> String
showsPrec :: Int -> PositionInName -> ShowS
$cshowsPrec :: Int -> PositionInName -> ShowS
Show, PositionInName -> PositionInName -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: PositionInName -> PositionInName -> Bool
$c/= :: PositionInName -> PositionInName -> Bool
== :: PositionInName -> PositionInName -> Bool
$c== :: PositionInName -> PositionInName -> Bool
Eq, Eq 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
min :: PositionInName -> PositionInName -> PositionInName
$cmin :: PositionInName -> PositionInName -> PositionInName
max :: PositionInName -> PositionInName -> PositionInName
$cmax :: PositionInName -> PositionInName -> PositionInName
>= :: PositionInName -> PositionInName -> Bool
$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
compare :: PositionInName -> PositionInName -> Ordering
$ccompare :: PositionInName -> PositionInName -> Ordering
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
forall e. Eq e => MaybePlaceholder e -> MaybePlaceholder e -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: MaybePlaceholder e -> MaybePlaceholder e -> Bool
$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
Eq, MaybePlaceholder e -> MaybePlaceholder e -> Bool
MaybePlaceholder e -> MaybePlaceholder e -> Ordering
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
min :: MaybePlaceholder e -> MaybePlaceholder e -> MaybePlaceholder e
$cmin :: forall e.
Ord e =>
MaybePlaceholder e -> MaybePlaceholder e -> MaybePlaceholder e
max :: MaybePlaceholder e -> MaybePlaceholder e -> MaybePlaceholder e
$cmax :: forall e.
Ord e =>
MaybePlaceholder e -> MaybePlaceholder e -> MaybePlaceholder e
>= :: 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
$c< :: forall e. Ord e => MaybePlaceholder e -> MaybePlaceholder e -> Bool
compare :: MaybePlaceholder e -> MaybePlaceholder e -> Ordering
$ccompare :: forall e.
Ord e =>
MaybePlaceholder e -> MaybePlaceholder e -> Ordering
Ord, 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
<$ :: forall a b. a -> MaybePlaceholder b -> MaybePlaceholder a
$c<$ :: forall a b. a -> MaybePlaceholder b -> MaybePlaceholder a
fmap :: forall a b. (a -> b) -> MaybePlaceholder a -> MaybePlaceholder b
$cfmap :: forall a b. (a -> b) -> MaybePlaceholder a -> MaybePlaceholder b
Functor, 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
product :: forall a. Num a => MaybePlaceholder a -> a
$cproduct :: forall a. Num a => MaybePlaceholder a -> a
sum :: forall a. Num a => MaybePlaceholder a -> a
$csum :: forall a. Num a => MaybePlaceholder a -> a
minimum :: forall a. Ord a => MaybePlaceholder a -> a
$cminimum :: forall a. Ord a => MaybePlaceholder a -> a
maximum :: forall a. Ord a => MaybePlaceholder a -> a
$cmaximum :: forall a. Ord a => MaybePlaceholder a -> a
elem :: forall a. Eq a => a -> MaybePlaceholder a -> Bool
$celem :: forall a. Eq a => a -> MaybePlaceholder a -> Bool
length :: forall a. MaybePlaceholder a -> Int
$clength :: forall a. MaybePlaceholder a -> Int
null :: forall a. MaybePlaceholder a -> Bool
$cnull :: forall a. MaybePlaceholder a -> Bool
toList :: forall a. MaybePlaceholder a -> [a]
$ctoList :: forall a. MaybePlaceholder a -> [a]
foldl1 :: forall a. (a -> a -> a) -> MaybePlaceholder a -> a
$cfoldl1 :: forall a. (a -> a -> a) -> MaybePlaceholder a -> a
foldr1 :: forall a. (a -> a -> a) -> MaybePlaceholder a -> a
$cfoldr1 :: forall a. (a -> a -> a) -> MaybePlaceholder a -> a
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
$cfoldl :: forall b a. (b -> a -> 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
$cfoldr :: forall a b. (a -> b -> b) -> b -> MaybePlaceholder a -> b
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
$cfoldMap :: forall m a. Monoid m => (a -> m) -> MaybePlaceholder a -> m
fold :: forall m. Monoid m => MaybePlaceholder m -> m
$cfold :: forall m. Monoid m => MaybePlaceholder m -> m
Foldable, Functor MaybePlaceholder
Foldable 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)
sequence :: forall (m :: * -> *) a.
Monad m =>
MaybePlaceholder (m a) -> m (MaybePlaceholder a)
$csequence :: forall (m :: * -> *) a.
Monad m =>
MaybePlaceholder (m a) -> m (MaybePlaceholder a)
mapM :: forall (m :: * -> *) a b.
Monad m =>
(a -> m b) -> MaybePlaceholder a -> m (MaybePlaceholder b)
$cmapM :: forall (m :: * -> *) a b.
Monad m =>
(a -> m b) -> MaybePlaceholder a -> m (MaybePlaceholder b)
sequenceA :: forall (f :: * -> *) a.
Applicative f =>
MaybePlaceholder (f a) -> f (MaybePlaceholder a)
$csequenceA :: forall (f :: * -> *) a.
Applicative f =>
MaybePlaceholder (f a) -> f (MaybePlaceholder a)
traverse :: 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)
Traversable, Int -> MaybePlaceholder e -> ShowS
forall e. Show e => Int -> MaybePlaceholder e -> ShowS
forall e. Show e => [MaybePlaceholder e] -> ShowS
forall e. Show e => MaybePlaceholder e -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [MaybePlaceholder e] -> ShowS
$cshowList :: forall e. Show e => [MaybePlaceholder e] -> ShowS
show :: MaybePlaceholder e -> String
$cshow :: forall e. Show e => MaybePlaceholder e -> String
showsPrec :: Int -> MaybePlaceholder e -> ShowS
$cshowsPrec :: forall e. Show e => Int -> MaybePlaceholder e -> ShowS
Show)

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

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

instance HasRange a => HasRange (MaybePlaceholder a) where
  getRange :: MaybePlaceholder a -> Range
getRange Placeholder{}       = forall a. Range' a
noRange
  getRange (NoPlaceholder Maybe PositionInName
_ a
e) = 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) = forall a b. KillRange a => (a -> b) -> a -> b
killRange1 (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) = forall a. NFData a => a -> ()
rnf a
a

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

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

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

instance KillRange InteractionId where killRange :: InteractionId -> InteractionId
killRange = 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
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: FixityLevel -> FixityLevel -> Bool
$c/= :: FixityLevel -> FixityLevel -> Bool
== :: FixityLevel -> FixityLevel -> Bool
$c== :: FixityLevel -> FixityLevel -> Bool
Eq, Eq 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
min :: FixityLevel -> FixityLevel -> FixityLevel
$cmin :: FixityLevel -> FixityLevel -> FixityLevel
max :: FixityLevel -> FixityLevel -> FixityLevel
$cmax :: FixityLevel -> FixityLevel -> FixityLevel
>= :: FixityLevel -> FixityLevel -> Bool
$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
compare :: FixityLevel -> FixityLevel -> Ordering
$ccompare :: FixityLevel -> FixityLevel -> Ordering
Ord, Int -> FixityLevel -> ShowS
[FixityLevel] -> ShowS
FixityLevel -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [FixityLevel] -> ShowS
$cshowList :: [FixityLevel] -> ShowS
show :: FixityLevel -> String
$cshow :: FixityLevel -> String
showsPrec :: Int -> FixityLevel -> ShowS
$cshowsPrec :: Int -> 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
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Associativity -> Associativity -> Bool
$c/= :: Associativity -> Associativity -> Bool
== :: Associativity -> Associativity -> Bool
$c== :: Associativity -> Associativity -> Bool
Eq, Eq 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
min :: Associativity -> Associativity -> Associativity
$cmin :: Associativity -> Associativity -> Associativity
max :: Associativity -> Associativity -> Associativity
$cmax :: Associativity -> Associativity -> Associativity
>= :: Associativity -> Associativity -> Bool
$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
compare :: Associativity -> Associativity -> Ordering
$ccompare :: Associativity -> Associativity -> Ordering
Ord, Int -> Associativity -> ShowS
[Associativity] -> ShowS
Associativity -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Associativity] -> ShowS
$cshowList :: [Associativity] -> ShowS
show :: Associativity -> String
$cshow :: Associativity -> String
showsPrec :: Int -> Associativity -> ShowS
$cshowsPrec :: Int -> 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 -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Fixity] -> ShowS
$cshowList :: [Fixity] -> ShowS
show :: Fixity -> String
$cshow :: Fixity -> String
showsPrec :: Int -> Fixity -> ShowS
$cshowsPrec :: Int -> Fixity -> ShowS
Show

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

defaultFixity :: Fixity
defaultFixity :: Fixity
defaultFixity = Range -> FixityLevel -> Associativity -> Fixity
Fixity 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 = forall a. Ord a => a -> a -> Ordering
compare Fixity
f1 Fixity
f2 forall a. Eq a => a -> a -> Bool
== Ordering
EQ

instance Ord Fixity where
  compare :: Fixity -> Fixity -> Ordering
compare = forall a. Ord a => a -> a -> Ordering
compare forall b c a. (b -> b -> c) -> (a -> b) -> a -> a -> c
`on` (Fixity -> FixityLevel
fixityLevel 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  = forall a. Null a => a -> Bool
null 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 :: Range
fixityRange = forall a. Range' a
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' -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Fixity'] -> ShowS
$cshowList :: [Fixity'] -> ShowS
show :: Fixity' -> String
$cshow :: Fixity' -> String
showsPrec :: Int -> Fixity' -> ShowS
$cshowsPrec :: Int -> Fixity' -> ShowS
Show

noFixity' :: Fixity'
noFixity' :: Fixity'
noFixity' = Fixity -> Notation -> Range -> Fixity'
Fixity' Fixity
noFixity Notation
noNotation 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 forall a. Eq a => a -> a -> Bool
== Fixity
f' Bool -> Bool -> Bool
&& Notation
n forall a. Eq a => a -> a -> Bool
== Notation
n'

instance Null Fixity' where
  null :: Fixity' -> Bool
null (Fixity' Fixity
f Notation
n Range
_) = forall a. Null a => a -> Bool
null Fixity
f Bool -> Bool -> 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
_) = forall a. NFData a => a -> ()
rnf Notation
a

instance KillRange Fixity' where
  killRange :: KillRangeT Fixity'
killRange (Fixity' Fixity
f Notation
n Range
r) = forall a b c d.
(KillRange a, KillRange b, KillRange c) =>
(a -> b -> c -> d) -> a -> b -> c -> d
killRange3 Fixity -> Notation -> Range -> Fixity'
Fixity' Fixity
f Notation
n Range
r

-- lenses

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

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

-- Lens focusing on Fixity

class LensFixity a where
  lensFixity :: Lens' Fixity a

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

-- Lens focusing on Fixity'

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

instance LensFixity' Fixity' where
  lensFixity' :: Lens' Fixity' Fixity'
lensFixity' = 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
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
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
$c== :: forall n m.
(Eq m, Eq n) =>
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 = 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 = forall u t. (HasRange u, HasRange t) => u -> t -> Range
fuseRange ImportDirective' n m
i1 ImportDirective' n m
i2
    , using :: Using' n m
using          = forall n m. ImportDirective' n m -> Using' n m
using ImportDirective' n m
i1 forall a. Semigroup a => a -> a -> a
<> forall n m. ImportDirective' n m -> Using' n m
using ImportDirective' n m
i2
    , hiding :: HidingDirective' n m
hiding         = forall n m. ImportDirective' n m -> HidingDirective' n m
hiding ImportDirective' n m
i1 forall a. [a] -> [a] -> [a]
++ forall n m. ImportDirective' n m -> HidingDirective' n m
hiding ImportDirective' n m
i2
    , impRenaming :: RenamingDirective' n m
impRenaming    = forall n m. ImportDirective' n m -> RenamingDirective' n m
impRenaming ImportDirective' n m
i1 forall a. [a] -> [a] -> [a]
++ forall n m. ImportDirective' n m -> RenamingDirective' n m
impRenaming ImportDirective' n m
i2
    , publicOpen :: Maybe Range
publicOpen     = forall n m. ImportDirective' n m -> Maybe Range
publicOpen ImportDirective' n m
i1 forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> 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  = forall a. Null a => a
empty
  mappend :: ImportDirective' n m
-> ImportDirective' n m -> ImportDirective' n m
mappend = 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 = forall n m.
Range
-> Using' n m
-> HidingDirective' n m
-> RenamingDirective' n m
-> Maybe Range
-> ImportDirective' n m
ImportDirective forall a. Range' a
noRange forall n m. Using' n m
UseEverything [] [] 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 = forall a. Null a => a -> Bool
null ImportDirective' n m
dir Bool -> Bool -> Bool
&& forall a. Null a => a -> Bool
null (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
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
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
$c== :: forall n m. (Eq m, Eq n) => 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      = forall n m. [ImportedName' n m] -> Using' n m
Using ([ImportedName' n m]
xs forall a. [a] -> [a] -> [a]
++ [ImportedName' n m]
ys)

instance Monoid (Using' n m) where
  mempty :: Using' n m
mempty  = forall n m. Using' n m
UseEverything
  mappend :: Using' n m -> Using' n m -> Using' n m
mappend = 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 = 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 -> forall n m. Using' n m
UseEverything
  Using [ImportedName' n1 m1]
xs      -> forall n m. [ImportedName' n m] -> Using' n m
Using 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
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
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
$c== :: forall n m.
(Eq m, Eq n) =>
ImportedName' n m -> ImportedName' n m -> Bool
Eq, ImportedName' n m -> ImportedName' n m -> Bool
ImportedName' n m -> ImportedName' n m -> Ordering
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
min :: 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
max :: ImportedName' n m -> ImportedName' n m -> ImportedName' n m
$cmax :: forall n m.
(Ord m, Ord n) =>
ImportedName' n m -> ImportedName' n m -> ImportedName' n m
>= :: 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
$c< :: forall n m.
(Ord m, Ord n) =>
ImportedName' n m -> ImportedName' n m -> Bool
compare :: ImportedName' n m -> ImportedName' n m -> Ordering
$ccompare :: forall n m.
(Ord m, Ord n) =>
ImportedName' n m -> ImportedName' n m -> Ordering
Ord, Int -> ImportedName' n m -> ShowS
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([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 -> String
showList :: [ImportedName' n m] -> ShowS
$cshowList :: forall n m. (Show m, Show n) => [ImportedName' n m] -> ShowS
show :: ImportedName' n m -> String
$cshow :: forall n m. (Show m, Show n) => ImportedName' n m -> String
showsPrec :: Int -> ImportedName' n m -> ShowS
$cshowsPrec :: forall n m. (Show m, Show n) => Int -> 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 = forall n m. n -> ImportedName' n m
ImportedName   a
y
setImportedName (ImportedModule a
x) a
y = 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 = forall a b c. (a -> b -> c) -> b -> a -> c
flip forall (t :: * -> *) a b.
Foldable t =>
(a -> b -> b) -> b -> t a -> b
foldr ([], []) forall a b. (a -> b) -> a -> b
$ \case
  ImportedName   n
n -> forall (p :: * -> * -> *) a b c.
Bifunctor p =>
(a -> b) -> p a c -> p b c
first  (n
nforall a. a -> [a] -> [a]
:)
  ImportedModule m
m -> forall (p :: * -> * -> *) b c a.
Bifunctor p =>
(b -> c) -> p a b -> p a c
second (m
mforall 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
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
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
$c== :: forall n m. (Eq m, Eq n) => 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 = 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) = forall a. HasRange a => a -> Range
getRange [ImportedName' a b]
xs
  getRange Using' a b
UseEverything = 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 = forall a. HasRange a => a -> Range
getRange (forall n m. Renaming' n m -> ImportedName' n m
renFrom Renaming' a b
r, 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) = forall a. HasRange a => a -> Range
getRange a
x
  getRange (ImportedModule b
x) = 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) =
    forall a b c d.
(KillRange a, KillRange b, KillRange c) =>
(a -> b -> c -> d) -> a -> b -> c -> d
killRange3 (\Using' a b
u HidingDirective' a b
h RenamingDirective' a b
r -> forall n m.
Range
-> Using' n m
-> HidingDirective' n m
-> RenamingDirective' n m
-> Maybe Range
-> ImportDirective' n m
ImportDirective 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) = forall a b. KillRange a => (a -> b) -> a -> b
killRange1 forall n m. [ImportedName' n m] -> Using' n m
Using  [ImportedName' a b]
i
  killRange Using' a b
UseEverything = 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) = forall a b c d.
(KillRange a, KillRange b, KillRange c) =>
(a -> b -> c -> d) -> a -> b -> c -> d
killRange3 (\ ImportedName' a b
i ImportedName' a b
n Maybe Fixity
mf -> 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 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) = forall a b. KillRange a => (a -> b) -> a -> b
killRange1 forall n m. m -> ImportedName' n m
ImportedModule b
n
  killRange (ImportedName   a
n) = forall a b. KillRange a => (a -> b) -> a -> b
killRange1 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
_) = forall a. NFData a => a -> ()
rnf Using' a b
a seq :: forall a b. a -> b -> b
`seq` forall a. NFData a => a -> ()
rnf HidingDirective' a b
b seq :: forall a b. a -> b -> b
`seq` 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)     = 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
_) = forall a. NFData a => a -> ()
rnf ImportedName' a b
a seq :: forall a b. a -> b -> b
`seq` forall a. NFData a => a -> ()
rnf ImportedName' a b
b seq :: forall a b. a -> b -> b
`seq` 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) = forall a. NFData a => a -> ()
rnf b
a
  rnf (ImportedName 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
forall m. Show m => Int -> TerminationCheck m -> ShowS
forall m. Show m => [TerminationCheck m] -> ShowS
forall m. Show m => TerminationCheck m -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [TerminationCheck m] -> ShowS
$cshowList :: forall m. Show m => [TerminationCheck m] -> ShowS
show :: TerminationCheck m -> String
$cshow :: forall m. Show m => TerminationCheck m -> String
showsPrec :: Int -> TerminationCheck m -> ShowS
$cshowsPrec :: forall m. Show m => Int -> TerminationCheck m -> ShowS
Show, TerminationCheck m -> TerminationCheck m -> Bool
forall m. Eq m => TerminationCheck m -> TerminationCheck m -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: TerminationCheck m -> TerminationCheck m -> Bool
$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
Eq, 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
<$ :: forall a b. a -> TerminationCheck b -> TerminationCheck a
$c<$ :: forall a b. a -> TerminationCheck b -> TerminationCheck a
fmap :: forall a b. (a -> b) -> TerminationCheck a -> TerminationCheck b
$cfmap :: forall a b. (a -> b) -> TerminationCheck a -> TerminationCheck b
Functor)

instance KillRange m => KillRange (TerminationCheck m) where
  killRange :: KillRangeT (TerminationCheck m)
killRange (TerminationMeasure Range
_ m
m) = forall m. Range -> m -> TerminationCheck m
TerminationMeasure forall a. Range' a
noRange (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) = forall a. NFData a => a -> ()
rnf a
a

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

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

instance KillRange PositivityCheck where
  killRange :: PositivityCheck -> PositivityCheck
killRange = 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 = 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
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: UniverseCheck -> UniverseCheck -> Bool
$c/= :: UniverseCheck -> UniverseCheck -> Bool
== :: UniverseCheck -> UniverseCheck -> Bool
$c== :: UniverseCheck -> UniverseCheck -> Bool
Eq, Eq 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
min :: UniverseCheck -> UniverseCheck -> UniverseCheck
$cmin :: UniverseCheck -> UniverseCheck -> UniverseCheck
max :: UniverseCheck -> UniverseCheck -> UniverseCheck
$cmax :: UniverseCheck -> UniverseCheck -> UniverseCheck
>= :: UniverseCheck -> UniverseCheck -> Bool
$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
compare :: UniverseCheck -> UniverseCheck -> Ordering
$ccompare :: UniverseCheck -> UniverseCheck -> Ordering
Ord, Int -> UniverseCheck -> ShowS
[UniverseCheck] -> ShowS
UniverseCheck -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [UniverseCheck] -> ShowS
$cshowList :: [UniverseCheck] -> ShowS
show :: UniverseCheck -> String
$cshow :: UniverseCheck -> String
showsPrec :: Int -> UniverseCheck -> ShowS
$cshowsPrec :: Int -> UniverseCheck -> ShowS
Show, UniverseCheck
forall a. a -> a -> Bounded a
maxBound :: UniverseCheck
$cmaxBound :: UniverseCheck
minBound :: UniverseCheck
$cminBound :: UniverseCheck
Bounded, Int -> UniverseCheck
UniverseCheck -> Int
UniverseCheck -> [UniverseCheck]
UniverseCheck -> UniverseCheck
UniverseCheck -> UniverseCheck -> [UniverseCheck]
UniverseCheck -> UniverseCheck -> UniverseCheck -> [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
enumFromThenTo :: UniverseCheck -> UniverseCheck -> UniverseCheck -> [UniverseCheck]
$cenumFromThenTo :: UniverseCheck -> UniverseCheck -> UniverseCheck -> [UniverseCheck]
enumFromTo :: UniverseCheck -> UniverseCheck -> [UniverseCheck]
$cenumFromTo :: UniverseCheck -> UniverseCheck -> [UniverseCheck]
enumFromThen :: UniverseCheck -> UniverseCheck -> [UniverseCheck]
$cenumFromThen :: UniverseCheck -> UniverseCheck -> [UniverseCheck]
enumFrom :: UniverseCheck -> [UniverseCheck]
$cenumFrom :: UniverseCheck -> [UniverseCheck]
fromEnum :: UniverseCheck -> Int
$cfromEnum :: UniverseCheck -> Int
toEnum :: Int -> UniverseCheck
$ctoEnum :: Int -> UniverseCheck
pred :: UniverseCheck -> UniverseCheck
$cpred :: UniverseCheck -> UniverseCheck
succ :: UniverseCheck -> UniverseCheck
$csucc :: UniverseCheck -> UniverseCheck
Enum, 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
$cto :: forall x. Rep UniverseCheck x -> UniverseCheck
$cfrom :: forall x. UniverseCheck -> Rep UniverseCheck x
Generic)

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

instance NFData UniverseCheck

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

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

instance KillRange CoverageCheck where
  killRange :: CoverageCheck -> CoverageCheck
killRange = 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 = 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
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
forall qn nm p e.
(Eq qn, Eq e, 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 qn, Eq e, 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 qn, Eq e, Eq nm, Eq p) =>
RewriteEqn' qn nm p e -> RewriteEqn' qn nm p e -> Bool
Eq, Int -> RewriteEqn' qn nm p e -> ShowS
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
forall qn nm p e.
(Show qn, Show e, Show nm, Show p) =>
Int -> RewriteEqn' qn nm p e -> ShowS
forall qn nm p e.
(Show qn, Show e, Show nm, Show p) =>
[RewriteEqn' qn nm p e] -> ShowS
forall qn nm p e.
(Show qn, Show e, Show nm, Show p) =>
RewriteEqn' qn nm p e -> String
showList :: [RewriteEqn' qn nm p e] -> ShowS
$cshowList :: forall qn nm p e.
(Show qn, Show e, Show nm, Show p) =>
[RewriteEqn' qn nm p e] -> ShowS
show :: RewriteEqn' qn nm p e -> String
$cshow :: forall qn nm p e.
(Show qn, Show e, Show nm, Show p) =>
RewriteEqn' qn nm p e -> String
showsPrec :: Int -> RewriteEqn' qn nm p e -> ShowS
$cshowsPrec :: forall qn nm p e.
(Show qn, Show e, Show nm, Show p) =>
Int -> RewriteEqn' qn nm p e -> ShowS
Show, 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
<$ :: forall a b. a -> RewriteEqn' qn nm p b -> RewriteEqn' qn nm p a
$c<$ :: forall qn nm p a b.
a -> RewriteEqn' qn nm p b -> RewriteEqn' qn nm p a
fmap :: forall a b.
(a -> b) -> RewriteEqn' qn nm p a -> RewriteEqn' qn nm p b
$cfmap :: forall qn nm p a b.
(a -> b) -> RewriteEqn' qn nm p a -> RewriteEqn' qn nm p b
Functor, forall a. RewriteEqn' qn nm p a -> Bool
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 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
product :: forall a. Num a => RewriteEqn' qn nm p a -> a
$cproduct :: forall qn nm p a. Num a => RewriteEqn' qn nm p a -> a
sum :: forall a. Num a => RewriteEqn' qn nm p a -> a
$csum :: forall qn nm p a. Num a => RewriteEqn' qn nm p a -> a
minimum :: forall a. Ord a => RewriteEqn' qn nm p a -> a
$cminimum :: forall qn nm p a. Ord a => RewriteEqn' qn nm p a -> a
maximum :: forall a. Ord a => RewriteEqn' qn nm p a -> a
$cmaximum :: forall qn nm p a. Ord a => RewriteEqn' qn nm p a -> a
elem :: forall a. Eq a => a -> RewriteEqn' qn nm p a -> Bool
$celem :: forall qn nm p a. Eq a => a -> RewriteEqn' qn nm p a -> Bool
length :: forall a. RewriteEqn' qn nm p a -> Int
$clength :: forall qn nm p a. RewriteEqn' qn nm p a -> Int
null :: forall a. RewriteEqn' qn nm p a -> Bool
$cnull :: forall qn nm p a. RewriteEqn' qn nm p a -> Bool
toList :: forall a. RewriteEqn' qn nm p a -> [a]
$ctoList :: forall qn nm p a. RewriteEqn' qn nm p a -> [a]
foldl1 :: 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
foldr1 :: forall a. (a -> a -> a) -> RewriteEqn' qn nm p a -> a
$cfoldr1 :: forall qn nm p a. (a -> a -> a) -> RewriteEqn' qn nm p a -> a
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
$cfoldl :: forall qn nm p b a.
(b -> a -> 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
$cfoldr :: forall qn nm p a b.
(a -> b -> b) -> b -> RewriteEqn' qn nm p a -> b
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
$cfoldMap :: forall qn nm p m a.
Monoid m =>
(a -> m) -> RewriteEqn' qn nm p a -> m
fold :: forall m. Monoid m => RewriteEqn' qn nm p m -> m
$cfold :: forall qn nm p m. Monoid m => RewriteEqn' qn nm p m -> m
Foldable, 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 (f :: * -> *) a b.
Applicative f =>
(a -> f b) -> RewriteEqn' qn nm p a -> f (RewriteEqn' qn nm p b)
sequence :: forall (m :: * -> *) a.
Monad m =>
RewriteEqn' qn nm p (m a) -> m (RewriteEqn' qn nm p a)
$csequence :: forall qn nm p (m :: * -> *) a.
Monad m =>
RewriteEqn' qn nm p (m a) -> m (RewriteEqn' qn nm p a)
mapM :: forall (m :: * -> *) a b.
Monad m =>
(a -> m b) -> RewriteEqn' qn nm p a -> m (RewriteEqn' qn nm p b)
$cmapM :: forall qn nm p (m :: * -> *) a b.
Monad m =>
(a -> m b) -> RewriteEqn' qn nm p a -> m (RewriteEqn' qn nm p b)
sequenceA :: forall (f :: * -> *) a.
Applicative f =>
RewriteEqn' qn nm p (f a) -> f (RewriteEqn' qn nm p a)
$csequenceA :: forall qn nm p (f :: * -> *) a.
Applicative f =>
RewriteEqn' qn nm p (f a) -> f (RewriteEqn' qn nm p a)
traverse :: 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)
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    -> forall a. NFData a => a -> ()
rnf List1 (qn, e)
es
    Invert qn
qn List1 (Named nm (p, e))
pes -> 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 (String -> Doc
text String
"rewrite") forall a b. (a -> b) -> a -> b
$ forall l. IsList l => l -> [Item l]
List1.toList (forall a. Pretty a => a -> Doc
pretty forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a b. (a, b) -> b
snd 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 (String -> Doc
text String
"invert") forall a b. (a -> b) -> a -> b
$ forall l. IsList l => l -> [Item l]
List1.toList (forall {a} {a} {a}.
(Pretty a, Pretty a, Pretty a) =>
Named a (a, a) -> Doc
namedWith 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 = forall a. Pretty a => a -> Doc
pretty a
p Doc -> Doc -> Doc
<+> Doc
"<-" Doc -> Doc -> Doc
<+> forall a. Pretty a => a -> Doc
pretty a
e in
        case Maybe a
nm of
          Maybe a
Nothing -> Doc
patexp
          Just a
nm -> forall a. Pretty a => a -> Doc
pretty a
nm Doc -> Doc -> Doc
<+> Doc
":" Doc -> Doc -> Doc
<+> 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    -> forall a. HasRange a => a -> Range
getRange List1 (qn, e)
es
    Invert qn
qn List1 (Named nm (p, e))
pes -> 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    -> forall a b. KillRange a => (a -> b) -> a -> b
killRange1 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 -> forall a b c.
(KillRange a, KillRange b) =>
(a -> b -> c) -> a -> b -> c
killRange2 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 -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [ExpandedEllipsis] -> ShowS
$cshowList :: [ExpandedEllipsis] -> ShowS
show :: ExpandedEllipsis -> String
$cshow :: ExpandedEllipsis -> String
showsPrec :: Int -> ExpandedEllipsis -> ShowS
$cshowsPrec :: Int -> ExpandedEllipsis -> ShowS
Show, ExpandedEllipsis -> ExpandedEllipsis -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: ExpandedEllipsis -> ExpandedEllipsis -> Bool
$c/= :: ExpandedEllipsis -> ExpandedEllipsis -> Bool
== :: ExpandedEllipsis -> ExpandedEllipsis -> Bool
$c== :: ExpandedEllipsis -> ExpandedEllipsis -> Bool
Eq)

instance Null ExpandedEllipsis where
  null :: ExpandedEllipsis -> Bool
null  = (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 forall a. Semigroup a => a -> a -> a
<> Range
r2) (Int
k1 forall a. Num a => a -> a -> a
+ Int
k2)

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

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

instance NFData ExpandedEllipsis where
  rnf :: ExpandedEllipsis -> ()
rnf (ExpandedEllipsis Range
_ Int
a) = 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
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: BoundVariablePosition -> BoundVariablePosition -> Bool
$c/= :: BoundVariablePosition -> BoundVariablePosition -> Bool
== :: BoundVariablePosition -> BoundVariablePosition -> Bool
$c== :: BoundVariablePosition -> BoundVariablePosition -> Bool
Eq, Eq 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
min :: BoundVariablePosition
-> BoundVariablePosition -> BoundVariablePosition
$cmin :: BoundVariablePosition
-> BoundVariablePosition -> BoundVariablePosition
max :: BoundVariablePosition
-> BoundVariablePosition -> BoundVariablePosition
$cmax :: BoundVariablePosition
-> BoundVariablePosition -> BoundVariablePosition
>= :: BoundVariablePosition -> BoundVariablePosition -> Bool
$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
compare :: BoundVariablePosition -> BoundVariablePosition -> Ordering
$ccompare :: BoundVariablePosition -> BoundVariablePosition -> Ordering
Ord, Int -> BoundVariablePosition -> ShowS
[BoundVariablePosition] -> ShowS
BoundVariablePosition -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [BoundVariablePosition] -> ShowS
$cshowList :: [BoundVariablePosition] -> ShowS
show :: BoundVariablePosition -> String
$cshow :: BoundVariablePosition -> String
showsPrec :: Int -> BoundVariablePosition -> ShowS
$cshowsPrec :: Int -> 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 -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: Notation -> ShowS
$cshowList :: Notation -> ShowS
show :: NotationPart -> String
$cshow :: NotationPart -> String
showsPrec :: Int -> NotationPart -> ShowS
$cshowsPrec :: Int -> NotationPart -> ShowS
Show

instance Eq NotationPart where
  VarPart Range
_ Ranged BoundVariablePosition
i  == :: NotationPart -> NotationPart -> Bool
== VarPart Range
_ Ranged BoundVariablePosition
j  = Ranged BoundVariablePosition
i 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 forall a. Eq a => a -> a -> Bool
== NamedArg (Ranged Int)
y
  WildPart Ranged BoundVariablePosition
i   == WildPart Ranged BoundVariablePosition
j   = Ranged BoundVariablePosition
i forall a. Eq a => a -> a -> Bool
== Ranged BoundVariablePosition
j
  IdPart Ranged String
x     == IdPart Ranged String
y     = Ranged String
x forall a. Eq a => a -> a -> Bool
== Ranged String
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 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 forall a. Ord a => a -> a -> Ordering
`compare` NamedArg (Ranged Int)
y
  WildPart Ranged BoundVariablePosition
i   `compare` WildPart Ranged BoundVariablePosition
j   = Ranged BoundVariablePosition
i forall a. Ord a => a -> a -> Ordering
`compare` Ranged BoundVariablePosition
j
  IdPart Ranged String
x     `compare` IdPart Ranged String
y     = Ranged String
x forall a. Ord a => a -> a -> Ordering
`compare` Ranged String
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 String
x     -> forall a. HasRange a => a -> Range
getRange Ranged String
x
    VarPart Range
r Ranged BoundVariablePosition
_  -> Range
r
    WildPart Ranged BoundVariablePosition
i   -> 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 String
x     -> Ranged String -> NotationPart
IdPart Ranged String
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 String
x     -> Ranged String -> NotationPart
IdPart forall a b. (a -> b) -> a -> b
$ forall a. KillRange a => KillRangeT a
killRange Ranged String
x
    VarPart Range
_ Ranged BoundVariablePosition
i  -> Range -> Ranged BoundVariablePosition -> NotationPart
VarPart forall a. Range' a
noRange forall a b. (a -> b) -> a -> b
$ forall a. KillRange a => KillRangeT a
killRange Ranged BoundVariablePosition
i
    WildPart Ranged BoundVariablePosition
i   -> Ranged BoundVariablePosition -> NotationPart
WildPart forall a b. (a -> b) -> a -> b
$ forall a. KillRange a => KillRangeT a
killRange Ranged BoundVariablePosition
i
    HolePart Range
_ NamedArg (Ranged Int)
x -> Range -> NamedArg (Ranged Int) -> NotationPart
HolePart forall a. Range' a
noRange forall a b. (a -> b) -> a -> b
$ forall a. KillRange a => KillRangeT a
killRange NamedArg (Ranged Int)
x

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

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