{-|
Module      : Idris.AbsSyntaxTree
Description : Core data definitions used in Idris.

License     : BSD3
Maintainer  : The Idris Community.
-}

{-# LANGUAGE CPP, DeriveDataTypeable, DeriveFoldable, DeriveFunctor,
             DeriveGeneric, DeriveTraversable, FlexibleContexts,
             FlexibleInstances, MultiParamTypeClasses, PatternGuards,
             TypeSynonymInstances #-}

module Idris.AbsSyntaxTree where

import Idris.Core.Elaborate hiding (Tactic(..))
import Idris.Core.Evaluate
import Idris.Core.TT
import Idris.Docstrings
import Idris.Options
import IRTS.CodegenCommon
import IRTS.Lang
import Util.DynamicLinker
import Util.Pretty

import Idris.Colours

import System.IO
#if (MIN_VERSION_base(4,11,0))
import Prelude hiding (Foldable, Traversable, (<$>), (<>))
#else
import Prelude hiding (Foldable, Traversable, (<$>))
#endif

import Control.Applicative ((<|>))
import qualified Control.Monad.Trans.Class as Trans (lift)
import Control.Monad.Trans.Except
import Control.Monad.Trans.State.Strict
import Data.Char
import Data.Data (Data)

import Data.Foldable (Foldable)
import Data.Function (on)
import Data.Generics.Uniplate.Data (children, universe)
import Data.List hiding (group)
import qualified Data.Map.Strict as M
import Data.Maybe (mapMaybe, maybeToList)
import qualified Data.Set as S
import qualified Data.Text as T
import Data.Traversable (Traversable)
import Data.Typeable
import GHC.Generics (Generic)

data ElabWhat = ETypes | EDefns | EAll
  deriving (Int -> ElabWhat -> ShowS
[ElabWhat] -> ShowS
ElabWhat -> String
(Int -> ElabWhat -> ShowS)
-> (ElabWhat -> String) -> ([ElabWhat] -> ShowS) -> Show ElabWhat
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> ElabWhat -> ShowS
showsPrec :: Int -> ElabWhat -> ShowS
$cshow :: ElabWhat -> String
show :: ElabWhat -> String
$cshowList :: [ElabWhat] -> ShowS
showList :: [ElabWhat] -> ShowS
Show, ElabWhat -> ElabWhat -> Bool
(ElabWhat -> ElabWhat -> Bool)
-> (ElabWhat -> ElabWhat -> Bool) -> Eq ElabWhat
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: ElabWhat -> ElabWhat -> Bool
== :: ElabWhat -> ElabWhat -> Bool
$c/= :: ElabWhat -> ElabWhat -> Bool
/= :: ElabWhat -> ElabWhat -> Bool
Eq)

-- | Data to pass to recursively called elaborators; e.g. for where blocks,
-- paramaterised declarations, etc.
--
-- rec_elabDecl is used to pass the top level elaborator into other elaborators,
-- so that we can have mutually recursive elaborators in separate modules without
-- having to muck about with cyclic modules.
data ElabInfo = EInfo {
    ElabInfo -> [(Name, PTerm)]
params    :: [(Name, PTerm)]
  , ElabInfo -> Ctxt [Name]
inblock   :: Ctxt [Name]      -- ^ names in the block, and their params
  , ElabInfo -> Name -> Name
liftname  :: Name -> Name
  , ElabInfo -> [String]
namespace :: [String]
  , ElabInfo -> Maybe FC
elabFC    :: Maybe FC
  , ElabInfo -> String
constraintNS :: String        -- ^ filename for adding to constraint variables
  , ElabInfo -> Int
pe_depth  :: Int
  , ElabInfo -> [Name]
noCaseLift :: [Name]         -- ^ types which shouldn't be made arguments to case
  -- | We may, recursively, collect transformations to do on the rhs,
  -- e.g. rewriting recursive calls to functions defined by 'with'
  , ElabInfo -> PTerm -> PTerm
rhs_trans :: PTerm -> PTerm
  , ElabInfo -> ElabWhat -> ElabInfo -> PDecl' PTerm -> Idris ()
rec_elabDecl :: ElabWhat -> ElabInfo -> PDecl -> Idris ()
  }

toplevel :: ElabInfo
toplevel :: ElabInfo
toplevel = [(Name, PTerm)]
-> Ctxt [Name]
-> (Name -> Name)
-> [String]
-> Maybe FC
-> String
-> Int
-> [Name]
-> (PTerm -> PTerm)
-> (ElabWhat -> ElabInfo -> PDecl' PTerm -> Idris ())
-> ElabInfo
EInfo [] Ctxt [Name]
forall {k} {a}. Map k a
emptyContext Name -> Name
forall a. a -> a
id [] Maybe FC
forall a. Maybe a
Nothing String
"(toplevel)" Int
0 [] PTerm -> PTerm
forall a. a -> a
id (\ElabWhat
_ ElabInfo
_ PDecl' PTerm
_ -> String -> Idris ()
forall a. String -> StateT IState (ExceptT Err IO) a
forall (m :: * -> *) a. MonadFail m => String -> m a
fail String
"Not implemented")

toplevelWith :: String -> ElabInfo
toplevelWith :: String -> ElabInfo
toplevelWith String
ns = [(Name, PTerm)]
-> Ctxt [Name]
-> (Name -> Name)
-> [String]
-> Maybe FC
-> String
-> Int
-> [Name]
-> (PTerm -> PTerm)
-> (ElabWhat -> ElabInfo -> PDecl' PTerm -> Idris ())
-> ElabInfo
EInfo [] Ctxt [Name]
forall {k} {a}. Map k a
emptyContext Name -> Name
forall a. a -> a
id [] Maybe FC
forall a. Maybe a
Nothing String
ns Int
0 [] PTerm -> PTerm
forall a. a -> a
id (\ElabWhat
_ ElabInfo
_ PDecl' PTerm
_ -> String -> Idris ()
forall a. String -> StateT IState (ExceptT Err IO) a
forall (m :: * -> *) a. MonadFail m => String -> m a
fail String
"Not implemented")

eInfoNames :: ElabInfo -> [Name]
eInfoNames :: ElabInfo -> [Name]
eInfoNames ElabInfo
info = ((Name, PTerm) -> Name) -> [(Name, PTerm)] -> [Name]
forall a b. (a -> b) -> [a] -> [b]
map (Name, PTerm) -> Name
forall a b. (a, b) -> a
fst (ElabInfo -> [(Name, PTerm)]
params ElabInfo
info) [Name] -> [Name] -> [Name]
forall a. [a] -> [a] -> [a]
++ Ctxt [Name] -> [Name]
forall k a. Map k a -> [k]
M.keys (ElabInfo -> Ctxt [Name]
inblock ElabInfo
info)

data IOption = IOption {
    IOption -> Int
opt_logLevel     :: Int
  , IOption -> [LogCat]
opt_logcats      :: [LogCat]      -- ^ List of logging categories.
  , IOption -> Bool
opt_typecase     :: Bool
  , IOption -> Bool
opt_typeintype   :: Bool
  , IOption -> Bool
opt_coverage     :: Bool
  , IOption -> Bool
opt_showimp      :: Bool          -- ^ show implicits
  , IOption -> Bool
opt_errContext   :: Bool
  , IOption -> Bool
opt_repl         :: Bool
  , IOption -> Int
opt_verbose      :: Int
  , IOption -> Bool
opt_nobanner     :: Bool
  , IOption -> Bool
opt_quiet        :: Bool
  , IOption -> Codegen
opt_codegen      :: Codegen
  , IOption -> OutputType
opt_outputTy     :: OutputType
  , IOption -> String
opt_ibcsubdir    :: FilePath
  , IOption -> [String]
opt_importdirs   :: [FilePath]
  , IOption -> [String]
opt_sourcedirs   :: [FilePath]
  , IOption -> String
opt_triple       :: String
  , IOption -> String
opt_cpu          :: String
  , IOption -> [Opt]
opt_cmdline      :: [Opt]          -- ^ remember whole command line
  , IOption -> Bool
opt_origerr      :: Bool
  , IOption -> Bool
opt_autoSolve    :: Bool           -- ^ automatically apply "solve" tactic in prover
  , IOption -> [String]
opt_autoImport   :: [FilePath]     -- ^ List of modules to auto import i.e. `Builtins+Prelude`
  , IOption -> [Optimisation]
opt_optimise     :: [Optimisation]
  , IOption -> Maybe Int
opt_printdepth   :: Maybe Int
  , IOption -> Bool
opt_evaltypes    :: Bool           -- ^ normalise types in `:t`
  , IOption -> Bool
opt_desugarnats  :: Bool
  , IOption -> Bool
opt_autoimpls    :: Bool
  } deriving (Int -> IOption -> ShowS
[IOption] -> ShowS
IOption -> String
(Int -> IOption -> ShowS)
-> (IOption -> String) -> ([IOption] -> ShowS) -> Show IOption
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> IOption -> ShowS
showsPrec :: Int -> IOption -> ShowS
$cshow :: IOption -> String
show :: IOption -> String
$cshowList :: [IOption] -> ShowS
showList :: [IOption] -> ShowS
Show, IOption -> IOption -> Bool
(IOption -> IOption -> Bool)
-> (IOption -> IOption -> Bool) -> Eq IOption
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: IOption -> IOption -> Bool
== :: IOption -> IOption -> Bool
$c/= :: IOption -> IOption -> Bool
/= :: IOption -> IOption -> Bool
Eq, (forall x. IOption -> Rep IOption x)
-> (forall x. Rep IOption x -> IOption) -> Generic IOption
forall x. Rep IOption x -> IOption
forall x. IOption -> Rep IOption x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cfrom :: forall x. IOption -> Rep IOption x
from :: forall x. IOption -> Rep IOption x
$cto :: forall x. Rep IOption x -> IOption
to :: forall x. Rep IOption x -> IOption
Generic)

defaultOpts :: IOption
defaultOpts :: IOption
defaultOpts = IOption { opt_logLevel :: Int
opt_logLevel   = Int
0
                      , opt_logcats :: [LogCat]
opt_logcats    = []
                      , opt_typecase :: Bool
opt_typecase   = Bool
False
                      , opt_typeintype :: Bool
opt_typeintype = Bool
False
                      , opt_coverage :: Bool
opt_coverage   = Bool
True
                      , opt_showimp :: Bool
opt_showimp    = Bool
False
                      , opt_errContext :: Bool
opt_errContext = Bool
False
                      , opt_repl :: Bool
opt_repl       = Bool
True
                      , opt_verbose :: Int
opt_verbose    = Int
0
                      , opt_nobanner :: Bool
opt_nobanner   = Bool
False
                      , opt_quiet :: Bool
opt_quiet      = Bool
False
                      , opt_codegen :: Codegen
opt_codegen    = IRFormat -> String -> Codegen
Via IRFormat
IBCFormat String
"c"
                      , opt_outputTy :: OutputType
opt_outputTy   = OutputType
Executable
                      , opt_ibcsubdir :: String
opt_ibcsubdir  = String
""
                      , opt_importdirs :: [String]
opt_importdirs = []
                      , opt_sourcedirs :: [String]
opt_sourcedirs = []
                      , opt_triple :: String
opt_triple     = String
""
                      , opt_cpu :: String
opt_cpu        = String
""
                      , opt_cmdline :: [Opt]
opt_cmdline    = []
                      , opt_origerr :: Bool
opt_origerr    = Bool
False
                      , opt_autoSolve :: Bool
opt_autoSolve  = Bool
True
                      , opt_autoImport :: [String]
opt_autoImport = []
                      , opt_optimise :: [Optimisation]
opt_optimise   = [Optimisation]
defaultOptimise
                      , opt_printdepth :: Maybe Int
opt_printdepth = Int -> Maybe Int
forall a. a -> Maybe a
Just Int
5000
                      , opt_evaltypes :: Bool
opt_evaltypes  = Bool
True
                      , opt_desugarnats :: Bool
opt_desugarnats = Bool
False
                      , opt_autoimpls :: Bool
opt_autoimpls  = Bool
True
                      }

data PPOption = PPOption {
    PPOption -> Bool
ppopt_impl        :: Bool -- ^ whether to show implicits
  , PPOption -> Bool
ppopt_desugarnats :: Bool
  , PPOption -> Bool
ppopt_pinames     :: Bool -- ^ whether to show names in pi bindings
  , PPOption -> Maybe Int
ppopt_depth       :: Maybe Int
  , PPOption -> Bool
ppopt_displayrig  :: Bool -- ^ whether to display multiplicities in binders
  } deriving (Int -> PPOption -> ShowS
[PPOption] -> ShowS
PPOption -> String
(Int -> PPOption -> ShowS)
-> (PPOption -> String) -> ([PPOption] -> ShowS) -> Show PPOption
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> PPOption -> ShowS
showsPrec :: Int -> PPOption -> ShowS
$cshow :: PPOption -> String
show :: PPOption -> String
$cshowList :: [PPOption] -> ShowS
showList :: [PPOption] -> ShowS
Show)



defaultOptimise :: [Optimisation]
defaultOptimise :: [Optimisation]
defaultOptimise = []

-- | Pretty printing options with default verbosity.
defaultPPOption :: PPOption
defaultPPOption :: PPOption
defaultPPOption = PPOption {
    ppopt_impl :: Bool
ppopt_impl = Bool
False
  , ppopt_desugarnats :: Bool
ppopt_desugarnats = Bool
False
  , ppopt_pinames :: Bool
ppopt_pinames = Bool
False
  , ppopt_depth :: Maybe Int
ppopt_depth = Maybe Int
forall a. Maybe a
Nothing
  , ppopt_displayrig :: Bool
ppopt_displayrig = Bool
False
  }

-- | Pretty printing options with the most verbosity.
verbosePPOption :: PPOption
verbosePPOption :: PPOption
verbosePPOption = PPOption {
    ppopt_impl :: Bool
ppopt_impl = Bool
True
  , ppopt_desugarnats :: Bool
ppopt_desugarnats = Bool
True
  , ppopt_pinames :: Bool
ppopt_pinames = Bool
True
  , ppopt_depth :: Maybe Int
ppopt_depth = Maybe Int
forall a. Maybe a
Nothing
  , ppopt_displayrig :: Bool
ppopt_displayrig = Bool
False
  }

-- | Get pretty printing options from the big options record.
ppOption :: IOption -> PPOption
ppOption :: IOption -> PPOption
ppOption IOption
opt = PPOption {
    ppopt_impl :: Bool
ppopt_impl = IOption -> Bool
opt_showimp IOption
opt
  , ppopt_pinames :: Bool
ppopt_pinames = Bool
False
  , ppopt_depth :: Maybe Int
ppopt_depth = IOption -> Maybe Int
opt_printdepth IOption
opt
  , ppopt_desugarnats :: Bool
ppopt_desugarnats = IOption -> Bool
opt_desugarnats IOption
opt
  , ppopt_displayrig :: Bool
ppopt_displayrig = Bool
False
  }

-- | Get pretty printing options from an idris state record.
ppOptionIst :: IState -> PPOption
ppOptionIst :: IState -> PPOption
ppOptionIst = IOption -> PPOption
ppOption (IOption -> PPOption) -> (IState -> IOption) -> IState -> PPOption
forall b c a. (b -> c) -> (a -> b) -> a -> c
. IState -> IOption
idris_options


-- | The output mode in use
data OutputMode = RawOutput Handle       -- ^ Print user output directly to the handle
                | IdeMode Integer Handle -- ^ Send IDE output for some request ID to the handle
                deriving Int -> OutputMode -> ShowS
[OutputMode] -> ShowS
OutputMode -> String
(Int -> OutputMode -> ShowS)
-> (OutputMode -> String)
-> ([OutputMode] -> ShowS)
-> Show OutputMode
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> OutputMode -> ShowS
showsPrec :: Int -> OutputMode -> ShowS
$cshow :: OutputMode -> String
show :: OutputMode -> String
$cshowList :: [OutputMode] -> ShowS
showList :: [OutputMode] -> ShowS
Show


-- | If a function has no totality annotation, what do we assume?
data DefaultTotality = DefaultCheckingTotal    -- ^ Total
                     | DefaultCheckingPartial  -- ^ Partial
                     | DefaultCheckingCovering -- ^Total coverage, but may diverge
  deriving (Int -> DefaultTotality -> ShowS
[DefaultTotality] -> ShowS
DefaultTotality -> String
(Int -> DefaultTotality -> ShowS)
-> (DefaultTotality -> String)
-> ([DefaultTotality] -> ShowS)
-> Show DefaultTotality
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> DefaultTotality -> ShowS
showsPrec :: Int -> DefaultTotality -> ShowS
$cshow :: DefaultTotality -> String
show :: DefaultTotality -> String
$cshowList :: [DefaultTotality] -> ShowS
showList :: [DefaultTotality] -> ShowS
Show, DefaultTotality -> DefaultTotality -> Bool
(DefaultTotality -> DefaultTotality -> Bool)
-> (DefaultTotality -> DefaultTotality -> Bool)
-> Eq DefaultTotality
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: DefaultTotality -> DefaultTotality -> Bool
== :: DefaultTotality -> DefaultTotality -> Bool
$c/= :: DefaultTotality -> DefaultTotality -> Bool
/= :: DefaultTotality -> DefaultTotality -> Bool
Eq, (forall x. DefaultTotality -> Rep DefaultTotality x)
-> (forall x. Rep DefaultTotality x -> DefaultTotality)
-> Generic DefaultTotality
forall x. Rep DefaultTotality x -> DefaultTotality
forall x. DefaultTotality -> Rep DefaultTotality x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cfrom :: forall x. DefaultTotality -> Rep DefaultTotality x
from :: forall x. DefaultTotality -> Rep DefaultTotality x
$cto :: forall x. Rep DefaultTotality x -> DefaultTotality
to :: forall x. Rep DefaultTotality x -> DefaultTotality
Generic)

-- | Configuration options for interactive editing.
data InteractiveOpts = InteractiveOpts {
    InteractiveOpts -> Int
interactiveOpts_indentWith :: Int
  , InteractiveOpts -> Int
interactiveOpts_indentClause :: Int
} deriving (Int -> InteractiveOpts -> ShowS
[InteractiveOpts] -> ShowS
InteractiveOpts -> String
(Int -> InteractiveOpts -> ShowS)
-> (InteractiveOpts -> String)
-> ([InteractiveOpts] -> ShowS)
-> Show InteractiveOpts
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> InteractiveOpts -> ShowS
showsPrec :: Int -> InteractiveOpts -> ShowS
$cshow :: InteractiveOpts -> String
show :: InteractiveOpts -> String
$cshowList :: [InteractiveOpts] -> ShowS
showList :: [InteractiveOpts] -> ShowS
Show, (forall x. InteractiveOpts -> Rep InteractiveOpts x)
-> (forall x. Rep InteractiveOpts x -> InteractiveOpts)
-> Generic InteractiveOpts
forall x. Rep InteractiveOpts x -> InteractiveOpts
forall x. InteractiveOpts -> Rep InteractiveOpts x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cfrom :: forall x. InteractiveOpts -> Rep InteractiveOpts x
from :: forall x. InteractiveOpts -> Rep InteractiveOpts x
$cto :: forall x. Rep InteractiveOpts x -> InteractiveOpts
to :: forall x. Rep InteractiveOpts x -> InteractiveOpts
Generic)

-- | The global state used in the Idris monad
data IState = IState {
    IState -> Context
tt_ctxt            :: Context            -- ^ All the currently defined names and their terms
  , IState -> Set ConstraintFC
idris_constraints  :: S.Set ConstraintFC -- ^ A list of universe constraints and their corresponding source locations
  , IState -> [FixDecl]
idris_infixes      :: [FixDecl]          -- ^ Currently defined infix operators
  , IState -> Ctxt [PArg]
idris_implicits    :: Ctxt [PArg]
  , IState -> Ctxt [Bool]
idris_statics      :: Ctxt [Bool]
  , IState -> Ctxt InterfaceInfo
idris_interfaces   :: Ctxt InterfaceInfo
  , IState -> [Name]
idris_openimpls    :: [Name]             -- ^ Privileged implementations, will resolve immediately
  , IState -> Ctxt RecordInfo
idris_records      :: Ctxt RecordInfo
  , IState -> Ctxt DSL
idris_dsls         :: Ctxt DSL
  , IState -> Ctxt OptInfo
idris_optimisation :: Ctxt OptInfo
  , IState -> Ctxt TypeInfo
idris_datatypes    :: Ctxt TypeInfo
  , IState -> Ctxt [Name]
idris_namehints    :: Ctxt [Name]

  -- | list of lhs/rhs, and a list of missing clauses. These are not
  -- exported.
  , IState -> Ctxt ([([(Name, Term)], Term, Term)], [PTerm])
idris_patdefs       :: Ctxt ([([(Name, Term)], Term, Term)], [PTerm])
  , IState -> Ctxt [FnOpt]
idris_flags         :: Ctxt [FnOpt]
  , IState -> Ctxt CGInfo
idris_callgraph     :: Ctxt CGInfo  -- ^ name, args used in each pos
  , IState -> Ctxt (Docstring DocTerm, [(Name, Docstring DocTerm)])
idris_docstrings    :: Ctxt (Docstring DocTerm, [(Name, Docstring DocTerm)])

  -- | module documentation is saved in a special MN so the context
  -- mechanism can be used for disambiguation.
  , IState -> Ctxt (Docstring DocTerm)
idris_moduledocs    :: Ctxt (Docstring DocTerm)
  , IState -> Ctxt TIData
idris_tyinfodata    :: Ctxt TIData
  , IState -> Ctxt FnInfo
idris_fninfo        :: Ctxt FnInfo
  , IState -> Ctxt [(Term, Term)]
idris_transforms    :: Ctxt [(Term, Term)]
  , IState -> Ctxt [Name]
idris_autohints     :: Ctxt [Name]
  , IState -> [(FC, Name)]
idris_totcheck      :: [(FC, Name)] -- ^ names to check totality on
  , IState -> [(FC, Name)]
idris_defertotcheck :: [(FC, Name)] -- ^ names to check at the end
  , IState -> [(FC, String)]
idris_totcheckfail  :: [(FC, String)]
  , IState -> IOption
idris_options       :: IOption
  , IState -> Int
idris_name          :: Int
  , IState -> [((String, Int), PTerm)]
idris_lineapps      :: [((FilePath, Int), PTerm)] -- ^ Full application LHS on source line

  -- | The currently defined but not proven metavariables. The Int is
  -- the number of vars to display as a context, the Maybe Name is its
  -- top-level function, the [Name] is the list of local variables
  -- available for proof search and the Bools are whether :p is
  -- allowed, and whether the variable is definable at all
  -- (Metavariables are not definable if they are applied in a term
  -- which still has hole bindings)
  , IState -> [(Name, (Maybe Name, Int, [Name], Bool, Bool))]
idris_metavars      :: [(Name, (Maybe Name, Int, [Name], Bool, Bool))]
  , IState -> [Name]
idris_coercions              :: [Name]
  , IState -> [(Term, Term)]
idris_errRev                 :: [(Term, Term)]
  , IState -> [Name]
idris_errReduce              :: [Name]
  , IState -> SyntaxRules
syntax_rules                 :: SyntaxRules
  , IState -> [String]
syntax_keywords              :: [String]
  , IState -> [String]
imported                     :: [FilePath]                    -- ^ The imported modules
  , IState -> [(Name, (Int, PrimFn))]
idris_scprims                :: [(Name, (Int, PrimFn))]
  , IState -> [(Codegen, String)]
idris_objs                   :: [(Codegen, FilePath)]
  , IState -> [(Codegen, String)]
idris_libs                   :: [(Codegen, String)]
  , IState -> [(Codegen, String)]
idris_cgflags                :: [(Codegen, String)]
  , IState -> [(Codegen, String)]
idris_hdrs                   :: [(Codegen, String)]
  , IState -> [(String, Bool)]
idris_imported               :: [(FilePath, Bool)]            -- ^ Imported ibc file names, whether public
  , IState -> [(Name, (Bool, [String]))]
proof_list                   :: [(Name, (Bool, [String]))]
  , IState -> Maybe FC
errSpan                      :: Maybe FC
  , IState -> [(FC, Err)]
parserWarnings               :: [(FC, Err)]
  , IState -> Maybe Name
lastParse                    :: Maybe Name
  , IState -> [Int]
indent_stack                 :: [Int]
  , IState -> [Maybe Int]
brace_stack                  :: [Maybe Int]
  , IState -> Maybe FC
idris_parsedSpan             :: Maybe FC
  , IState -> Ctxt Accessibility
hide_list                    :: Ctxt Accessibility
  , IState -> Accessibility
default_access               :: Accessibility
  , IState -> DefaultTotality
default_total                :: DefaultTotality
  , IState -> [IBCWrite]
ibc_write                    :: [IBCWrite]
  , IState -> Maybe String
compiled_so                  :: Maybe String
  , IState -> [DynamicLib]
idris_dynamic_libs           :: [DynamicLib]
  , IState -> [LanguageExt]
idris_language_extensions    :: [LanguageExt]
  , IState -> OutputMode
idris_outputmode             :: OutputMode
  , IState -> Bool
idris_colourRepl             :: Bool
  , IState -> ColourTheme
idris_colourTheme            :: ColourTheme
  , IState -> [Name]
idris_errorhandlers          :: [Name]                         -- ^ Global error handlers
  , IState -> (Int, Ctxt (Int, Name))
idris_nameIdx                :: (Int, Ctxt (Int, Name))
  , IState -> Ctxt (Map Name (Set Name))
idris_function_errorhandlers :: Ctxt (M.Map Name (S.Set Name)) -- ^ Specific error handlers
  , IState -> Map [Text] [Text]
module_aliases               :: M.Map [T.Text] [T.Text]
  , IState -> ConsoleWidth
idris_consolewidth           :: ConsoleWidth                   -- ^ How many chars wide is the console?
  , IState -> Set Name
idris_postulates             :: S.Set Name
  , IState -> Set (Name, Int)
idris_externs                :: S.Set (Name, Int)
  , IState -> [(Name, Int)]
idris_erasureUsed            :: [(Name, Int)]                  -- ^ Function/constructor name, argument position is used

  -- | List of names that were defined in the repl, and can be re-/un-defined
  , IState -> [Name]
idris_repl_defs              :: [Name]

  -- | Stack of names currently being elaborated, Bool set if it's an
  -- implementation (implementations appear twice; also as a function name)
  , IState -> [(Name, Bool)]
elab_stack                   :: [(Name, Bool)]


  , IState -> Map Name Name
idris_symbols                :: M.Map Name Name           -- ^ Symbol table (preserves sharing of names)
  , IState -> [Name]
idris_exports                :: [Name]                    -- ^ Functions with ExportList
  , IState -> Set (FC', OutputAnnotation)
idris_highlightedRegions     :: S.Set (FC', OutputAnnotation)  -- ^ Highlighting information to output
  , IState -> Set (FC', OutputAnnotation)
idris_parserHighlights       :: S.Set (FC', OutputAnnotation)  -- ^ Highlighting information from the parser
  , IState -> Ctxt String
idris_deprecated             :: Ctxt String               -- ^ Deprecated names and explanation
  , IState -> Set Name
idris_inmodule               :: S.Set Name                -- ^ Names defined in current module
  , IState -> Map Term (Int, Term)
idris_ttstats                :: M.Map Term (Int, Term)
  , IState -> Ctxt String
idris_fragile                :: Ctxt String               -- ^ Fragile names and explanation.
  , IState -> InteractiveOpts
idris_interactiveOpts        :: InteractiveOpts
  } deriving (forall x. IState -> Rep IState x)
-> (forall x. Rep IState x -> IState) -> Generic IState
forall x. Rep IState x -> IState
forall x. IState -> Rep IState x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cfrom :: forall x. IState -> Rep IState x
from :: forall x. IState -> Rep IState x
$cto :: forall x. Rep IState x -> IState
to :: forall x. Rep IState x -> IState
Generic

-- Required for parsers library, and therefore trifecta
instance Show IState where
  show :: IState -> String
show = String -> IState -> String
forall a b. a -> b -> a
const String
"{internal state}"

data SizeChange = Smaller | Same | Bigger | Unknown
    deriving (Int -> SizeChange -> ShowS
[SizeChange] -> ShowS
SizeChange -> String
(Int -> SizeChange -> ShowS)
-> (SizeChange -> String)
-> ([SizeChange] -> ShowS)
-> Show SizeChange
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> SizeChange -> ShowS
showsPrec :: Int -> SizeChange -> ShowS
$cshow :: SizeChange -> String
show :: SizeChange -> String
$cshowList :: [SizeChange] -> ShowS
showList :: [SizeChange] -> ShowS
Show, SizeChange -> SizeChange -> Bool
(SizeChange -> SizeChange -> Bool)
-> (SizeChange -> SizeChange -> Bool) -> Eq SizeChange
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: SizeChange -> SizeChange -> Bool
== :: SizeChange -> SizeChange -> Bool
$c/= :: SizeChange -> SizeChange -> Bool
/= :: SizeChange -> SizeChange -> Bool
Eq, (forall x. SizeChange -> Rep SizeChange x)
-> (forall x. Rep SizeChange x -> SizeChange) -> Generic SizeChange
forall x. Rep SizeChange x -> SizeChange
forall x. SizeChange -> Rep SizeChange x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cfrom :: forall x. SizeChange -> Rep SizeChange x
from :: forall x. SizeChange -> Rep SizeChange x
$cto :: forall x. Rep SizeChange x -> SizeChange
to :: forall x. Rep SizeChange x -> SizeChange
Generic)
{-!
deriving instance Binary SizeChange
!-}

type SCGEntry = (Name, [Maybe (Int, SizeChange)])
type UsageReason = (Name, Int)  -- fn_name, its_arg_number

data CGInfo = CGInfo {
    CGInfo -> [Name]
calls    :: [Name] -- Immediate calls
  , CGInfo -> Maybe [Name]
allCalls :: Maybe [Name] -- Calls and descendents (built as required, for PE)
  , CGInfo -> [SCGEntry]
scg      :: [SCGEntry]
  , CGInfo -> [(Int, [(Name, Int)])]
usedpos  :: [(Int, [UsageReason])]
  } deriving (Int -> CGInfo -> ShowS
[CGInfo] -> ShowS
CGInfo -> String
(Int -> CGInfo -> ShowS)
-> (CGInfo -> String) -> ([CGInfo] -> ShowS) -> Show CGInfo
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> CGInfo -> ShowS
showsPrec :: Int -> CGInfo -> ShowS
$cshow :: CGInfo -> String
show :: CGInfo -> String
$cshowList :: [CGInfo] -> ShowS
showList :: [CGInfo] -> ShowS
Show, (forall x. CGInfo -> Rep CGInfo x)
-> (forall x. Rep CGInfo x -> CGInfo) -> Generic CGInfo
forall x. Rep CGInfo x -> CGInfo
forall x. CGInfo -> Rep CGInfo x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cfrom :: forall x. CGInfo -> Rep CGInfo x
from :: forall x. CGInfo -> Rep CGInfo x
$cto :: forall x. Rep CGInfo x -> CGInfo
to :: forall x. Rep CGInfo x -> CGInfo
Generic)
{-!
deriving instance Binary CGInfo
!-}

primDefs :: [Name]
primDefs :: [Name]
primDefs = [ String -> Name
sUN String
"unsafePerformPrimIO"
           , String -> Name
sUN String
"mkLazyForeignPrim"
           , String -> Name
sUN String
"mkForeignPrim"
           , String -> Name
sUN String
"void"
           , String -> Name
sUN String
"assert_unreachable"
           , String -> Name
sUN String
"idris_crash"
           ]

-- information that needs writing for the current module's .ibc file
data IBCWrite = IBCFix FixDecl
              | IBCImp Name
              | IBCStatic Name
              | IBCInterface Name
              | IBCRecord Name
              | IBCImplementation Bool Bool Name Name
              | IBCDSL Name
              | IBCData Name
              | IBCOpt Name
              | IBCMetavar Name
              | IBCSyntax Syntax
              | IBCKeyword String
              | IBCImport (Bool, FilePath) -- ^ True = import public
              | IBCImportDir FilePath
              | IBCSourceDir FilePath
              | IBCObj Codegen FilePath
              | IBCLib Codegen String
              | IBCCGFlag Codegen String
              | IBCDyLib String
              | IBCHeader Codegen String
              | IBCAccess Name Accessibility
              | IBCMetaInformation Name MetaInformation
              | IBCTotal Name Totality
              | IBCInjective Name Injectivity
              | IBCFlags Name
              | IBCFnInfo Name FnInfo
              | IBCTrans Name (Term, Term)
              | IBCErrRev (Term, Term)
              | IBCErrReduce Name
              | IBCCG Name
              | IBCDoc Name
              | IBCCoercion Name
              | IBCDef Name -- ^ The main context.
              | IBCNameHint (Name, Name)
              | IBCLineApp FilePath Int PTerm
              | IBCErrorHandler Name
              | IBCFunctionErrorHandler Name Name Name
              | IBCPostulate Name
              | IBCExtern (Name, Int)
              | IBCTotCheckErr FC String
              | IBCParsedRegion FC
              | IBCModDocs Name -- ^ The name is the special name used to track module docs
              | IBCUsage (Name, Int)
              | IBCExport Name
              | IBCAutoHint Name Name
              | IBCDeprecate Name String
              | IBCFragile Name String
              | IBCConstraint FC UConstraint
              | IBCImportHash FilePath Int
  deriving (Int -> IBCWrite -> ShowS
[IBCWrite] -> ShowS
IBCWrite -> String
(Int -> IBCWrite -> ShowS)
-> (IBCWrite -> String) -> ([IBCWrite] -> ShowS) -> Show IBCWrite
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> IBCWrite -> ShowS
showsPrec :: Int -> IBCWrite -> ShowS
$cshow :: IBCWrite -> String
show :: IBCWrite -> String
$cshowList :: [IBCWrite] -> ShowS
showList :: [IBCWrite] -> ShowS
Show, (forall x. IBCWrite -> Rep IBCWrite x)
-> (forall x. Rep IBCWrite x -> IBCWrite) -> Generic IBCWrite
forall x. Rep IBCWrite x -> IBCWrite
forall x. IBCWrite -> Rep IBCWrite x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cfrom :: forall x. IBCWrite -> Rep IBCWrite x
from :: forall x. IBCWrite -> Rep IBCWrite x
$cto :: forall x. Rep IBCWrite x -> IBCWrite
to :: forall x. Rep IBCWrite x -> IBCWrite
Generic)

initialInteractiveOpts :: InteractiveOpts
initialInteractiveOpts :: InteractiveOpts
initialInteractiveOpts = InteractiveOpts {
    interactiveOpts_indentWith :: Int
interactiveOpts_indentWith = Int
2
  , interactiveOpts_indentClause :: Int
interactiveOpts_indentClause = Int
2
}

-- | The initial state for the compiler
idrisInit :: IState
idrisInit :: IState
idrisInit = Context
-> Set ConstraintFC
-> [FixDecl]
-> Ctxt [PArg]
-> Ctxt [Bool]
-> Ctxt InterfaceInfo
-> [Name]
-> Ctxt RecordInfo
-> Ctxt DSL
-> Ctxt OptInfo
-> Ctxt TypeInfo
-> Ctxt [Name]
-> Ctxt ([([(Name, Term)], Term, Term)], [PTerm])
-> Ctxt [FnOpt]
-> Ctxt CGInfo
-> Ctxt (Docstring DocTerm, [(Name, Docstring DocTerm)])
-> Ctxt (Docstring DocTerm)
-> Ctxt TIData
-> Ctxt FnInfo
-> Ctxt [(Term, Term)]
-> Ctxt [Name]
-> [(FC, Name)]
-> [(FC, Name)]
-> [(FC, String)]
-> IOption
-> Int
-> [((String, Int), PTerm)]
-> [(Name, (Maybe Name, Int, [Name], Bool, Bool))]
-> [Name]
-> [(Term, Term)]
-> [Name]
-> SyntaxRules
-> [String]
-> [String]
-> [(Name, (Int, PrimFn))]
-> [(Codegen, String)]
-> [(Codegen, String)]
-> [(Codegen, String)]
-> [(Codegen, String)]
-> [(String, Bool)]
-> [(Name, (Bool, [String]))]
-> Maybe FC
-> [(FC, Err)]
-> Maybe Name
-> [Int]
-> [Maybe Int]
-> Maybe FC
-> Ctxt Accessibility
-> Accessibility
-> DefaultTotality
-> [IBCWrite]
-> Maybe String
-> [DynamicLib]
-> [LanguageExt]
-> OutputMode
-> Bool
-> ColourTheme
-> [Name]
-> (Int, Ctxt (Int, Name))
-> Ctxt (Map Name (Set Name))
-> Map [Text] [Text]
-> ConsoleWidth
-> Set Name
-> Set (Name, Int)
-> [(Name, Int)]
-> [Name]
-> [(Name, Bool)]
-> Map Name Name
-> [Name]
-> Set (FC', OutputAnnotation)
-> Set (FC', OutputAnnotation)
-> Ctxt String
-> Set Name
-> Map Term (Int, Term)
-> Ctxt String
-> InteractiveOpts
-> IState
IState Context
initContext Set ConstraintFC
forall a. Set a
S.empty []
                   Ctxt [PArg]
forall {k} {a}. Map k a
emptyContext Ctxt [Bool]
forall {k} {a}. Map k a
emptyContext Ctxt InterfaceInfo
forall {k} {a}. Map k a
emptyContext [] Ctxt RecordInfo
forall {k} {a}. Map k a
emptyContext
                   Ctxt DSL
forall {k} {a}. Map k a
emptyContext Ctxt OptInfo
forall {k} {a}. Map k a
emptyContext Ctxt TypeInfo
forall {k} {a}. Map k a
emptyContext Ctxt [Name]
forall {k} {a}. Map k a
emptyContext
                   Ctxt ([([(Name, Term)], Term, Term)], [PTerm])
forall {k} {a}. Map k a
emptyContext Ctxt [FnOpt]
forall {k} {a}. Map k a
emptyContext Ctxt CGInfo
forall {k} {a}. Map k a
emptyContext Ctxt (Docstring DocTerm, [(Name, Docstring DocTerm)])
forall {k} {a}. Map k a
emptyContext
                   Ctxt (Docstring DocTerm)
forall {k} {a}. Map k a
emptyContext Ctxt TIData
forall {k} {a}. Map k a
emptyContext Ctxt FnInfo
forall {k} {a}. Map k a
emptyContext Ctxt [(Term, Term)]
forall {k} {a}. Map k a
emptyContext
                   Ctxt [Name]
forall {k} {a}. Map k a
emptyContext
                   [] [] [] IOption
defaultOpts Int
6 [] [] [] [] [] SyntaxRules
emptySyntaxRules [] [] [] [] [] [] []
                   [] [] Maybe FC
forall a. Maybe a
Nothing [] Maybe Name
forall a. Maybe a
Nothing [] [] Maybe FC
forall a. Maybe a
Nothing Ctxt Accessibility
forall {k} {a}. Map k a
emptyContext Accessibility
Private DefaultTotality
DefaultCheckingPartial [] Maybe String
forall a. Maybe a
Nothing [] []
                   (Handle -> OutputMode
RawOutput Handle
stdout) Bool
True ColourTheme
defaultTheme [] (Int
0, Ctxt (Int, Name)
forall {k} {a}. Map k a
emptyContext) Ctxt (Map Name (Set Name))
forall {k} {a}. Map k a
emptyContext Map [Text] [Text]
forall {k} {a}. Map k a
M.empty
                   ConsoleWidth
AutomaticWidth Set Name
forall a. Set a
S.empty Set (Name, Int)
forall a. Set a
S.empty [] [] [] Map Name Name
forall {k} {a}. Map k a
M.empty [] Set (FC', OutputAnnotation)
forall a. Set a
S.empty Set (FC', OutputAnnotation)
forall a. Set a
S.empty
                   Ctxt String
forall {k} {a}. Map k a
emptyContext Set Name
forall a. Set a
S.empty Map Term (Int, Term)
forall {k} {a}. Map k a
M.empty Ctxt String
forall {k} {a}. Map k a
emptyContext InteractiveOpts
initialInteractiveOpts


-- | The monad for the main REPL - reading and processing files and
-- updating global state (hence the IO inner monad).
--
-- @
--     type Idris = WriterT [Either String (IO ())] (State IState a))
-- @
--
type Idris = StateT IState (ExceptT Err IO)

catchError :: Idris a -> (Err -> Idris a) -> Idris a
catchError :: forall a. Idris a -> (Err -> Idris a) -> Idris a
catchError = Catch Err (ExceptT Err IO) (a, IState)
-> Catch Err (StateT IState (ExceptT Err IO)) a
forall e (m :: * -> *) a s.
Catch e m (a, s) -> Catch e (StateT s m) a
liftCatch Catch Err (ExceptT Err IO) (a, IState)
forall (m :: * -> *) e a e'.
Monad m =>
ExceptT e m a -> (e -> ExceptT e' m a) -> ExceptT e' m a
catchE

throwError :: Err -> Idris a
throwError :: forall a. Err -> Idris a
throwError = ExceptT Err IO a -> StateT IState (ExceptT Err IO) a
forall (m :: * -> *) a. Monad m => m a -> StateT IState m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
Trans.lift (ExceptT Err IO a -> StateT IState (ExceptT Err IO) a)
-> (Err -> ExceptT Err IO a)
-> Err
-> StateT IState (ExceptT Err IO) a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Err -> ExceptT Err IO a
forall (m :: * -> *) e a. Monad m => e -> ExceptT e m a
throwE

-- Commands in the REPL




data ElabShellCmd = EQED
                  | EAbandon
                  | EUndo
                  | EProofState
                  | EProofTerm
                  | EEval PTerm
                  | ECheck PTerm
                  | ESearch PTerm
                  | EDocStr (Either Name Const)
  deriving (Int -> ElabShellCmd -> ShowS
[ElabShellCmd] -> ShowS
ElabShellCmd -> String
(Int -> ElabShellCmd -> ShowS)
-> (ElabShellCmd -> String)
-> ([ElabShellCmd] -> ShowS)
-> Show ElabShellCmd
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> ElabShellCmd -> ShowS
showsPrec :: Int -> ElabShellCmd -> ShowS
$cshow :: ElabShellCmd -> String
show :: ElabShellCmd -> String
$cshowList :: [ElabShellCmd] -> ShowS
showList :: [ElabShellCmd] -> ShowS
Show, ElabShellCmd -> ElabShellCmd -> Bool
(ElabShellCmd -> ElabShellCmd -> Bool)
-> (ElabShellCmd -> ElabShellCmd -> Bool) -> Eq ElabShellCmd
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: ElabShellCmd -> ElabShellCmd -> Bool
== :: ElabShellCmd -> ElabShellCmd -> Bool
$c/= :: ElabShellCmd -> ElabShellCmd -> Bool
/= :: ElabShellCmd -> ElabShellCmd -> Bool
Eq)




-- Parsed declarations

data Fixity = Infixl  { Fixity -> Int
prec :: Int }
            | Infixr  { prec :: Int }
            | InfixN  { prec :: Int }
            | PrefixN { prec :: Int }
    deriving (Fixity -> Fixity -> Bool
(Fixity -> Fixity -> Bool)
-> (Fixity -> Fixity -> Bool) -> Eq Fixity
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: Fixity -> Fixity -> Bool
== :: Fixity -> Fixity -> Bool
$c/= :: Fixity -> Fixity -> Bool
/= :: Fixity -> Fixity -> Bool
Eq, (forall x. Fixity -> Rep Fixity x)
-> (forall x. Rep Fixity x -> Fixity) -> Generic Fixity
forall x. Rep Fixity x -> Fixity
forall x. Fixity -> Rep Fixity x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cfrom :: forall x. Fixity -> Rep Fixity x
from :: forall x. Fixity -> Rep Fixity x
$cto :: forall x. Rep Fixity x -> Fixity
to :: forall x. Rep Fixity x -> Fixity
Generic)
{-!
deriving instance Binary Fixity
!-}

instance Show Fixity where
    show :: Fixity -> String
show (Infixl Int
i)  = String
"infixl " String -> ShowS
forall a. [a] -> [a] -> [a]
++ Int -> String
forall a. Show a => a -> String
show Int
i
    show (Infixr Int
i)  = String
"infixr " String -> ShowS
forall a. [a] -> [a] -> [a]
++ Int -> String
forall a. Show a => a -> String
show Int
i
    show (InfixN Int
i)  = String
"infix "  String -> ShowS
forall a. [a] -> [a] -> [a]
++ Int -> String
forall a. Show a => a -> String
show Int
i
    show (PrefixN Int
i) = String
"prefix " String -> ShowS
forall a. [a] -> [a] -> [a]
++ Int -> String
forall a. Show a => a -> String
show Int
i

data FixDecl = Fix Fixity String
    deriving (FixDecl -> FixDecl -> Bool
(FixDecl -> FixDecl -> Bool)
-> (FixDecl -> FixDecl -> Bool) -> Eq FixDecl
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: FixDecl -> FixDecl -> Bool
== :: FixDecl -> FixDecl -> Bool
$c/= :: FixDecl -> FixDecl -> Bool
/= :: FixDecl -> FixDecl -> Bool
Eq, (forall x. FixDecl -> Rep FixDecl x)
-> (forall x. Rep FixDecl x -> FixDecl) -> Generic FixDecl
forall x. Rep FixDecl x -> FixDecl
forall x. FixDecl -> Rep FixDecl x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cfrom :: forall x. FixDecl -> Rep FixDecl x
from :: forall x. FixDecl -> Rep FixDecl x
$cto :: forall x. Rep FixDecl x -> FixDecl
to :: forall x. Rep FixDecl x -> FixDecl
Generic)

instance Show FixDecl where
  show :: FixDecl -> String
show (Fix Fixity
f String
s) = Fixity -> String
forall a. Show a => a -> String
show Fixity
f String -> ShowS
forall a. [a] -> [a] -> [a]
++ String
" " String -> ShowS
forall a. [a] -> [a] -> [a]
++ String
s

{-!
deriving instance Binary FixDecl
!-}

instance Ord FixDecl where
    compare :: FixDecl -> FixDecl -> Ordering
compare (Fix Fixity
x String
_) (Fix Fixity
y String
_) = Int -> Int -> Ordering
forall a. Ord a => a -> a -> Ordering
compare (Fixity -> Int
prec Fixity
x) (Fixity -> Int
prec Fixity
y)


data Static = Static | Dynamic
  deriving (Int -> Static -> ShowS
[Static] -> ShowS
Static -> String
(Int -> Static -> ShowS)
-> (Static -> String) -> ([Static] -> ShowS) -> Show Static
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> Static -> ShowS
showsPrec :: Int -> Static -> ShowS
$cshow :: Static -> String
show :: Static -> String
$cshowList :: [Static] -> ShowS
showList :: [Static] -> ShowS
Show, Static -> Static -> Bool
(Static -> Static -> Bool)
-> (Static -> Static -> Bool) -> Eq Static
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: Static -> Static -> Bool
== :: Static -> Static -> Bool
$c/= :: Static -> Static -> Bool
/= :: Static -> Static -> Bool
Eq, Eq Static
Eq Static =>
(Static -> Static -> Ordering)
-> (Static -> Static -> Bool)
-> (Static -> Static -> Bool)
-> (Static -> Static -> Bool)
-> (Static -> Static -> Bool)
-> (Static -> Static -> Static)
-> (Static -> Static -> Static)
-> Ord Static
Static -> Static -> Bool
Static -> Static -> Ordering
Static -> Static -> Static
forall a.
Eq a =>
(a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
$ccompare :: Static -> Static -> Ordering
compare :: Static -> Static -> Ordering
$c< :: Static -> Static -> Bool
< :: Static -> Static -> Bool
$c<= :: Static -> Static -> Bool
<= :: Static -> Static -> Bool
$c> :: Static -> Static -> Bool
> :: Static -> Static -> Bool
$c>= :: Static -> Static -> Bool
>= :: Static -> Static -> Bool
$cmax :: Static -> Static -> Static
max :: Static -> Static -> Static
$cmin :: Static -> Static -> Static
min :: Static -> Static -> Static
Ord, Typeable Static
Typeable Static =>
(forall (c :: * -> *).
 (forall d b. Data d => c (d -> b) -> d -> c b)
 -> (forall g. g -> c g) -> Static -> c Static)
-> (forall (c :: * -> *).
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c Static)
-> (Static -> Constr)
-> (Static -> DataType)
-> (forall (t :: * -> *) (c :: * -> *).
    Typeable t =>
    (forall d. Data d => c (t d)) -> Maybe (c Static))
-> (forall (t :: * -> * -> *) (c :: * -> *).
    Typeable t =>
    (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c Static))
-> ((forall b. Data b => b -> b) -> Static -> Static)
-> (forall r r'.
    (r -> r' -> r)
    -> r -> (forall d. Data d => d -> r') -> Static -> r)
-> (forall r r'.
    (r' -> r -> r)
    -> r -> (forall d. Data d => d -> r') -> Static -> r)
-> (forall u. (forall d. Data d => d -> u) -> Static -> [u])
-> (forall u. Int -> (forall d. Data d => d -> u) -> Static -> u)
-> (forall (m :: * -> *).
    Monad m =>
    (forall d. Data d => d -> m d) -> Static -> m Static)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> Static -> m Static)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> Static -> m Static)
-> Data Static
Static -> Constr
Static -> DataType
(forall b. Data b => b -> b) -> Static -> Static
forall a.
Typeable a =>
(forall (c :: * -> *).
 (forall d b. Data d => c (d -> b) -> d -> c b)
 -> (forall g. g -> c g) -> a -> c a)
-> (forall (c :: * -> *).
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c a)
-> (a -> Constr)
-> (a -> DataType)
-> (forall (t :: * -> *) (c :: * -> *).
    Typeable t =>
    (forall d. Data d => c (t d)) -> Maybe (c a))
-> (forall (t :: * -> * -> *) (c :: * -> *).
    Typeable t =>
    (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c a))
-> ((forall b. Data b => b -> b) -> a -> a)
-> (forall r r'.
    (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall r r'.
    (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall u. (forall d. Data d => d -> u) -> a -> [u])
-> (forall u. Int -> (forall d. Data d => d -> u) -> a -> u)
-> (forall (m :: * -> *).
    Monad m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> Data a
forall u. Int -> (forall d. Data d => d -> u) -> Static -> u
forall u. (forall d. Data d => d -> u) -> Static -> [u]
forall r r'.
(r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> Static -> r
forall r r'.
(r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> Static -> r
forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> Static -> m Static
forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> Static -> m Static
forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c Static
forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> Static -> c Static
forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c Static)
forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c Static)
$cgfoldl :: forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> Static -> c Static
gfoldl :: forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> Static -> c Static
$cgunfold :: forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c Static
gunfold :: forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c Static
$ctoConstr :: Static -> Constr
toConstr :: Static -> Constr
$cdataTypeOf :: Static -> DataType
dataTypeOf :: Static -> DataType
$cdataCast1 :: forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c Static)
dataCast1 :: forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c Static)
$cdataCast2 :: forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c Static)
dataCast2 :: forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c Static)
$cgmapT :: (forall b. Data b => b -> b) -> Static -> Static
gmapT :: (forall b. Data b => b -> b) -> Static -> Static
$cgmapQl :: forall r r'.
(r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> Static -> r
gmapQl :: forall r r'.
(r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> Static -> r
$cgmapQr :: forall r r'.
(r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> Static -> r
gmapQr :: forall r r'.
(r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> Static -> r
$cgmapQ :: forall u. (forall d. Data d => d -> u) -> Static -> [u]
gmapQ :: forall u. (forall d. Data d => d -> u) -> Static -> [u]
$cgmapQi :: forall u. Int -> (forall d. Data d => d -> u) -> Static -> u
gmapQi :: forall u. Int -> (forall d. Data d => d -> u) -> Static -> u
$cgmapM :: forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> Static -> m Static
gmapM :: forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> Static -> m Static
$cgmapMp :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> Static -> m Static
gmapMp :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> Static -> m Static
$cgmapMo :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> Static -> m Static
gmapMo :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> Static -> m Static
Data, (forall x. Static -> Rep Static x)
-> (forall x. Rep Static x -> Static) -> Generic Static
forall x. Rep Static x -> Static
forall x. Static -> Rep Static x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cfrom :: forall x. Static -> Rep Static x
from :: forall x. Static -> Rep Static x
$cto :: forall x. Rep Static x -> Static
to :: forall x. Rep Static x -> Static
Generic, Typeable)
{-!
deriving instance Binary Static
!-}

-- ^ Mark bindings with their explicitness, and laziness
data Plicity = Imp { Plicity -> [ArgOpt]
pargopts  :: [ArgOpt]
                   , Plicity -> Static
pstatic   :: Static
                   , Plicity -> Bool
pparam    :: Bool
                   , Plicity -> Maybe ImplicitInfo
pscoped   :: Maybe ImplicitInfo -- ^ Nothing, if top level
                   , Plicity -> Bool
pinsource :: Bool               -- ^ Explicitly written in source
                   , Plicity -> RigCount
pcount    :: RigCount
                   }
             | Exp { pargopts :: [ArgOpt]
                   , pstatic  :: Static
                   , pparam   :: Bool -- ^ this is a param (rather than index)
                   , pcount    :: RigCount
                   }
             | Constraint { pargopts :: [ArgOpt]
                          , pstatic :: Static
                          , pcount    :: RigCount
                         }
             | TacImp { pargopts :: [ArgOpt]
                      , pstatic  :: Static
                      , Plicity -> PTerm
pscript  :: PTerm
                      , pcount    :: RigCount
                      }
             deriving (Int -> Plicity -> ShowS
[Plicity] -> ShowS
Plicity -> String
(Int -> Plicity -> ShowS)
-> (Plicity -> String) -> ([Plicity] -> ShowS) -> Show Plicity
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> Plicity -> ShowS
showsPrec :: Int -> Plicity -> ShowS
$cshow :: Plicity -> String
show :: Plicity -> String
$cshowList :: [Plicity] -> ShowS
showList :: [Plicity] -> ShowS
Show, Plicity -> Plicity -> Bool
(Plicity -> Plicity -> Bool)
-> (Plicity -> Plicity -> Bool) -> Eq Plicity
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: Plicity -> Plicity -> Bool
== :: Plicity -> Plicity -> Bool
$c/= :: Plicity -> Plicity -> Bool
/= :: Plicity -> Plicity -> Bool
Eq, Eq Plicity
Eq Plicity =>
(Plicity -> Plicity -> Ordering)
-> (Plicity -> Plicity -> Bool)
-> (Plicity -> Plicity -> Bool)
-> (Plicity -> Plicity -> Bool)
-> (Plicity -> Plicity -> Bool)
-> (Plicity -> Plicity -> Plicity)
-> (Plicity -> Plicity -> Plicity)
-> Ord Plicity
Plicity -> Plicity -> Bool
Plicity -> Plicity -> Ordering
Plicity -> Plicity -> Plicity
forall a.
Eq a =>
(a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
$ccompare :: Plicity -> Plicity -> Ordering
compare :: Plicity -> Plicity -> Ordering
$c< :: Plicity -> Plicity -> Bool
< :: Plicity -> Plicity -> Bool
$c<= :: Plicity -> Plicity -> Bool
<= :: Plicity -> Plicity -> Bool
$c> :: Plicity -> Plicity -> Bool
> :: Plicity -> Plicity -> Bool
$c>= :: Plicity -> Plicity -> Bool
>= :: Plicity -> Plicity -> Bool
$cmax :: Plicity -> Plicity -> Plicity
max :: Plicity -> Plicity -> Plicity
$cmin :: Plicity -> Plicity -> Plicity
min :: Plicity -> Plicity -> Plicity
Ord, Typeable Plicity
Typeable Plicity =>
(forall (c :: * -> *).
 (forall d b. Data d => c (d -> b) -> d -> c b)
 -> (forall g. g -> c g) -> Plicity -> c Plicity)
-> (forall (c :: * -> *).
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c Plicity)
-> (Plicity -> Constr)
-> (Plicity -> DataType)
-> (forall (t :: * -> *) (c :: * -> *).
    Typeable t =>
    (forall d. Data d => c (t d)) -> Maybe (c Plicity))
-> (forall (t :: * -> * -> *) (c :: * -> *).
    Typeable t =>
    (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c Plicity))
-> ((forall b. Data b => b -> b) -> Plicity -> Plicity)
-> (forall r r'.
    (r -> r' -> r)
    -> r -> (forall d. Data d => d -> r') -> Plicity -> r)
-> (forall r r'.
    (r' -> r -> r)
    -> r -> (forall d. Data d => d -> r') -> Plicity -> r)
-> (forall u. (forall d. Data d => d -> u) -> Plicity -> [u])
-> (forall u. Int -> (forall d. Data d => d -> u) -> Plicity -> u)
-> (forall (m :: * -> *).
    Monad m =>
    (forall d. Data d => d -> m d) -> Plicity -> m Plicity)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> Plicity -> m Plicity)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> Plicity -> m Plicity)
-> Data Plicity
Plicity -> Constr
Plicity -> DataType
(forall b. Data b => b -> b) -> Plicity -> Plicity
forall a.
Typeable a =>
(forall (c :: * -> *).
 (forall d b. Data d => c (d -> b) -> d -> c b)
 -> (forall g. g -> c g) -> a -> c a)
-> (forall (c :: * -> *).
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c a)
-> (a -> Constr)
-> (a -> DataType)
-> (forall (t :: * -> *) (c :: * -> *).
    Typeable t =>
    (forall d. Data d => c (t d)) -> Maybe (c a))
-> (forall (t :: * -> * -> *) (c :: * -> *).
    Typeable t =>
    (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c a))
-> ((forall b. Data b => b -> b) -> a -> a)
-> (forall r r'.
    (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall r r'.
    (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall u. (forall d. Data d => d -> u) -> a -> [u])
-> (forall u. Int -> (forall d. Data d => d -> u) -> a -> u)
-> (forall (m :: * -> *).
    Monad m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> Data a
forall u. Int -> (forall d. Data d => d -> u) -> Plicity -> u
forall u. (forall d. Data d => d -> u) -> Plicity -> [u]
forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> Plicity -> r
forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> Plicity -> r
forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> Plicity -> m Plicity
forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> Plicity -> m Plicity
forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c Plicity
forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> Plicity -> c Plicity
forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c Plicity)
forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c Plicity)
$cgfoldl :: forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> Plicity -> c Plicity
gfoldl :: forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> Plicity -> c Plicity
$cgunfold :: forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c Plicity
gunfold :: forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c Plicity
$ctoConstr :: Plicity -> Constr
toConstr :: Plicity -> Constr
$cdataTypeOf :: Plicity -> DataType
dataTypeOf :: Plicity -> DataType
$cdataCast1 :: forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c Plicity)
dataCast1 :: forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c Plicity)
$cdataCast2 :: forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c Plicity)
dataCast2 :: forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c Plicity)
$cgmapT :: (forall b. Data b => b -> b) -> Plicity -> Plicity
gmapT :: (forall b. Data b => b -> b) -> Plicity -> Plicity
$cgmapQl :: forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> Plicity -> r
gmapQl :: forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> Plicity -> r
$cgmapQr :: forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> Plicity -> r
gmapQr :: forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> Plicity -> r
$cgmapQ :: forall u. (forall d. Data d => d -> u) -> Plicity -> [u]
gmapQ :: forall u. (forall d. Data d => d -> u) -> Plicity -> [u]
$cgmapQi :: forall u. Int -> (forall d. Data d => d -> u) -> Plicity -> u
gmapQi :: forall u. Int -> (forall d. Data d => d -> u) -> Plicity -> u
$cgmapM :: forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> Plicity -> m Plicity
gmapM :: forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> Plicity -> m Plicity
$cgmapMp :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> Plicity -> m Plicity
gmapMp :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> Plicity -> m Plicity
$cgmapMo :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> Plicity -> m Plicity
gmapMo :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> Plicity -> m Plicity
Data, (forall x. Plicity -> Rep Plicity x)
-> (forall x. Rep Plicity x -> Plicity) -> Generic Plicity
forall x. Rep Plicity x -> Plicity
forall x. Plicity -> Rep Plicity x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cfrom :: forall x. Plicity -> Rep Plicity x
from :: forall x. Plicity -> Rep Plicity x
$cto :: forall x. Rep Plicity x -> Plicity
to :: forall x. Rep Plicity x -> Plicity
Generic, Typeable)

{-!
deriving instance Binary Plicity
!-}

is_scoped :: Plicity -> Maybe ImplicitInfo
is_scoped :: Plicity -> Maybe ImplicitInfo
is_scoped (Imp [ArgOpt]
_ Static
_ Bool
_ Maybe ImplicitInfo
s Bool
_ RigCount
_) = Maybe ImplicitInfo
s
is_scoped Plicity
_                 = Maybe ImplicitInfo
forall a. Maybe a
Nothing

-- Top level implicit
impl              :: Plicity
impl :: Plicity
impl              = [ArgOpt]
-> Static
-> Bool
-> Maybe ImplicitInfo
-> Bool
-> RigCount
-> Plicity
Imp [] Static
Dynamic Bool
False (ImplicitInfo -> Maybe ImplicitInfo
forall a. a -> Maybe a
Just (Bool -> Bool -> Bool -> ImplicitInfo
Impl Bool
False Bool
True Bool
False)) Bool
False RigCount
RigW
-- Machine generated top level implicit
impl_gen          :: Plicity
impl_gen :: Plicity
impl_gen          = [ArgOpt]
-> Static
-> Bool
-> Maybe ImplicitInfo
-> Bool
-> RigCount
-> Plicity
Imp [] Static
Dynamic Bool
False (ImplicitInfo -> Maybe ImplicitInfo
forall a. a -> Maybe a
Just (Bool -> Bool -> Bool -> ImplicitInfo
Impl Bool
False Bool
True Bool
True)) Bool
False RigCount
RigW

-- Scoped implicits
forall_imp        :: Plicity
forall_imp :: Plicity
forall_imp        = [ArgOpt]
-> Static
-> Bool
-> Maybe ImplicitInfo
-> Bool
-> RigCount
-> Plicity
Imp [] Static
Dynamic Bool
False (ImplicitInfo -> Maybe ImplicitInfo
forall a. a -> Maybe a
Just (Bool -> Bool -> Bool -> ImplicitInfo
Impl Bool
False Bool
False Bool
True)) Bool
False RigCount
RigW
forall_constraint :: Plicity
forall_constraint :: Plicity
forall_constraint = [ArgOpt]
-> Static
-> Bool
-> Maybe ImplicitInfo
-> Bool
-> RigCount
-> Plicity
Imp [] Static
Dynamic Bool
False (ImplicitInfo -> Maybe ImplicitInfo
forall a. a -> Maybe a
Just (Bool -> Bool -> Bool -> ImplicitInfo
Impl Bool
True Bool
False Bool
True)) Bool
False RigCount
RigW

expl              :: Plicity
expl :: Plicity
expl              = [ArgOpt] -> Static -> Bool -> RigCount -> Plicity
Exp [] Static
Dynamic Bool
False RigCount
RigW
expl_param        :: Plicity
expl_param :: Plicity
expl_param        = [ArgOpt] -> Static -> Bool -> RigCount -> Plicity
Exp [] Static
Dynamic Bool
True RigCount
RigW
expl_linear       :: Plicity
expl_linear :: Plicity
expl_linear       = [ArgOpt] -> Static -> Bool -> RigCount -> Plicity
Exp [] Static
Dynamic Bool
False RigCount
Rig1

constraint        :: Plicity
constraint :: Plicity
constraint        = [ArgOpt] -> Static -> RigCount -> Plicity
Constraint [] Static
Static RigCount
RigW

tacimpl           :: PTerm -> Plicity
tacimpl :: PTerm -> Plicity
tacimpl PTerm
t         = [ArgOpt] -> Static -> PTerm -> RigCount -> Plicity
TacImp [] Static
Dynamic PTerm
t RigCount
RigW

data FnOpt = Inlinable -- ^ always evaluate when simplifying
           | TotalFn | PartialFn | CoveringFn
           | AllGuarded -- ^ all delayed arguments guaranteed guarded by constructors
           | AssertTotal

           -- | interface dictionary, eval only when a function
           -- argument, and further evaluation results.
           | Dictionary
           | OverlappingDictionary -- ^ Interface dictionary which may overlap
           | Implicit                       -- ^ implicit coercion
           | NoImplicit                     -- ^ do not apply implicit coercions
           | CExport String                 -- ^ export, with a C name
           | ErrorHandler                   -- ^ an error handler for use with the ErrorReflection extension
           | ErrorReverse                   -- ^ attempt to reverse normalise before showing in error
           | ErrorReduce                    -- ^ unfold definition before showing an error
           | Reflection                     -- ^ a reflecting function, compile-time only
           | Specialise [(Name, Maybe Int)] -- ^ specialise it, freeze these names
           | Constructor -- ^ Data constructor type
           | AutoHint    -- ^ use in auto implicit search
           | PEGenerated -- ^ generated by partial evaluator
           | StaticFn    -- ^ Marked static, to be evaluated by partial evaluator
    deriving (Int -> FnOpt -> ShowS
[FnOpt] -> ShowS
FnOpt -> String
(Int -> FnOpt -> ShowS)
-> (FnOpt -> String) -> ([FnOpt] -> ShowS) -> Show FnOpt
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> FnOpt -> ShowS
showsPrec :: Int -> FnOpt -> ShowS
$cshow :: FnOpt -> String
show :: FnOpt -> String
$cshowList :: [FnOpt] -> ShowS
showList :: [FnOpt] -> ShowS
Show, FnOpt -> FnOpt -> Bool
(FnOpt -> FnOpt -> Bool) -> (FnOpt -> FnOpt -> Bool) -> Eq FnOpt
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: FnOpt -> FnOpt -> Bool
== :: FnOpt -> FnOpt -> Bool
$c/= :: FnOpt -> FnOpt -> Bool
/= :: FnOpt -> FnOpt -> Bool
Eq, (forall x. FnOpt -> Rep FnOpt x)
-> (forall x. Rep FnOpt x -> FnOpt) -> Generic FnOpt
forall x. Rep FnOpt x -> FnOpt
forall x. FnOpt -> Rep FnOpt x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cfrom :: forall x. FnOpt -> Rep FnOpt x
from :: forall x. FnOpt -> Rep FnOpt x
$cto :: forall x. Rep FnOpt x -> FnOpt
to :: forall x. Rep FnOpt x -> FnOpt
Generic)
{-!
deriving instance Binary FnOpt
!-}

type FnOpts = [FnOpt]

inlinable :: FnOpts -> Bool
inlinable :: [FnOpt] -> Bool
inlinable = FnOpt -> [FnOpt] -> Bool
forall a. Eq a => a -> [a] -> Bool
forall (t :: * -> *) a. (Foldable t, Eq a) => a -> t a -> Bool
elem FnOpt
Inlinable

dictionary :: FnOpts -> Bool
dictionary :: [FnOpt] -> Bool
dictionary = FnOpt -> [FnOpt] -> Bool
forall a. Eq a => a -> [a] -> Bool
forall (t :: * -> *) a. (Foldable t, Eq a) => a -> t a -> Bool
elem FnOpt
Dictionary


-- | Type provider - what to provide
data ProvideWhat' t = ProvTerm t t     -- ^ the first is the goal type, the second is the term
                    | ProvPostulate t  -- ^ goal type must be Type, so only term
    deriving (Int -> ProvideWhat' t -> ShowS
[ProvideWhat' t] -> ShowS
ProvideWhat' t -> String
(Int -> ProvideWhat' t -> ShowS)
-> (ProvideWhat' t -> String)
-> ([ProvideWhat' t] -> ShowS)
-> Show (ProvideWhat' t)
forall t. Show t => Int -> ProvideWhat' t -> ShowS
forall t. Show t => [ProvideWhat' t] -> ShowS
forall t. Show t => ProvideWhat' t -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: forall t. Show t => Int -> ProvideWhat' t -> ShowS
showsPrec :: Int -> ProvideWhat' t -> ShowS
$cshow :: forall t. Show t => ProvideWhat' t -> String
show :: ProvideWhat' t -> String
$cshowList :: forall t. Show t => [ProvideWhat' t] -> ShowS
showList :: [ProvideWhat' t] -> ShowS
Show, ProvideWhat' t -> ProvideWhat' t -> Bool
(ProvideWhat' t -> ProvideWhat' t -> Bool)
-> (ProvideWhat' t -> ProvideWhat' t -> Bool)
-> Eq (ProvideWhat' t)
forall t. Eq t => ProvideWhat' t -> ProvideWhat' t -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: forall t. Eq t => ProvideWhat' t -> ProvideWhat' t -> Bool
== :: ProvideWhat' t -> ProvideWhat' t -> Bool
$c/= :: forall t. Eq t => ProvideWhat' t -> ProvideWhat' t -> Bool
/= :: ProvideWhat' t -> ProvideWhat' t -> Bool
Eq, (forall a b. (a -> b) -> ProvideWhat' a -> ProvideWhat' b)
-> (forall a b. a -> ProvideWhat' b -> ProvideWhat' a)
-> Functor ProvideWhat'
forall a b. a -> ProvideWhat' b -> ProvideWhat' a
forall a b. (a -> b) -> ProvideWhat' a -> ProvideWhat' b
forall (f :: * -> *).
(forall a b. (a -> b) -> f a -> f b)
-> (forall a b. a -> f b -> f a) -> Functor f
$cfmap :: forall a b. (a -> b) -> ProvideWhat' a -> ProvideWhat' b
fmap :: forall a b. (a -> b) -> ProvideWhat' a -> ProvideWhat' b
$c<$ :: forall a b. a -> ProvideWhat' b -> ProvideWhat' a
<$ :: forall a b. a -> ProvideWhat' b -> ProvideWhat' a
Functor, (forall x. ProvideWhat' t -> Rep (ProvideWhat' t) x)
-> (forall x. Rep (ProvideWhat' t) x -> ProvideWhat' t)
-> Generic (ProvideWhat' t)
forall x. Rep (ProvideWhat' t) x -> ProvideWhat' t
forall x. ProvideWhat' t -> Rep (ProvideWhat' t) x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
forall t x. Rep (ProvideWhat' t) x -> ProvideWhat' t
forall t x. ProvideWhat' t -> Rep (ProvideWhat' t) x
$cfrom :: forall t x. ProvideWhat' t -> Rep (ProvideWhat' t) x
from :: forall x. ProvideWhat' t -> Rep (ProvideWhat' t) x
$cto :: forall t x. Rep (ProvideWhat' t) x -> ProvideWhat' t
to :: forall x. Rep (ProvideWhat' t) x -> ProvideWhat' t
Generic)

type ProvideWhat = ProvideWhat' PTerm

-- | Top-level declarations such as compiler directives, definitions,
-- datatypes and interfaces.
data PDecl' t
   -- | Fixity declaration
   = PFix FC Fixity [String]
   -- | Type declaration (last FC is precise name location)
   | PTy (Docstring (Either Err t)) [(Name, Docstring (Either Err t))] SyntaxInfo FC FnOpts Name FC t
   -- | Postulate, second FC is precise name location
   | PPostulate Bool -- external def if true
          (Docstring (Either Err t)) SyntaxInfo FC FC FnOpts Name t
   -- | Pattern clause
   | PClauses FC FnOpts Name [PClause' t]
   -- | Top level constant
   | PCAF FC Name t
   -- | Data declaration.
   | PData (Docstring (Either Err t)) [(Name, Docstring (Either Err t))] SyntaxInfo FC DataOpts (PData' t)
   -- | Params block
   | PParams FC [(Name, t)] [PDecl' t]
   -- | Open block/declaration
   | POpenInterfaces FC [Name] [PDecl' t]
   -- | New namespace, where FC is accurate location of the namespace
   -- in the file
   | PNamespace String FC [PDecl' t]
   -- | Record name.
   | PRecord (Docstring (Either Err t)) SyntaxInfo FC DataOpts
             Name                 -- Record name
             FC                   -- Record name precise location
             [(Name, FC, Plicity, t)] -- Parameters, where FC is precise name span
             [(Name, Docstring (Either Err t))] -- Param Docs
             [(Maybe (Name, FC), Plicity, t, Maybe (Docstring (Either Err t)))] -- Fields
             (Maybe (Name, FC)) -- Optional constructor name and location
             (Docstring (Either Err t)) -- Constructor doc
             SyntaxInfo -- Constructor SyntaxInfo

   -- | Interface: arguments are documentation, syntax info, source
   -- location, constraints, interface name, interface name location,
   -- parameters, method declarations, optional constructor name
   | PInterface (Docstring (Either Err t)) SyntaxInfo FC
            [(Name, t)]                        -- constraints
            Name                               -- interface name
            FC                                 -- accurate location of interface name
            [(Name, FC, t)]                    -- parameters and precise locations
            [(Name, Docstring (Either Err t))] -- parameter docstrings
            [(Name, FC)]                       -- determining parameters and precise locations
            [PDecl' t]                         -- declarations
            (Maybe (Name, FC))                 -- implementation constructor name and location
            (Docstring (Either Err t))         -- implementation constructor docs

   -- | Implementation declaration: arguments are documentation, syntax
   -- info, source location, constraints, interface name, parameters, full
   -- Implementation type, optional explicit name, and definitions
   | PImplementation (Docstring (Either Err t))         -- Implementation docs
                     [(Name, Docstring (Either Err t))] -- Parameter docs
                     SyntaxInfo
                     FC [(Name, t)]                     -- constraints
                     [Name]                             -- parent dictionaries to search for constraints
                     Accessibility
                     FnOpts
                     Name                               -- interface
                     FC                                 -- precise location of interface
                     [t]                                -- parameters
                     [(Name, t)]                        -- Extra names in scope in the body
                     t                                  -- full Implementation type
                     (Maybe Name)                       -- explicit name
                     [PDecl' t]
   | PDSL     Name (DSL' t) -- ^ DSL declaration
   | PSyntax  FC Syntax     -- ^ Syntax definition
   | PMutual  FC [PDecl' t] -- ^ Mutual block
   | PDirective Directive   -- ^ Compiler directive.

   -- | Type provider. The first t is the type, the second is the
   -- term. The second FC is precise highlighting location.
   | PProvider (Docstring (Either Err t)) SyntaxInfo FC FC (ProvideWhat' t) Name

   -- | Source-to-source transformation rule. If bool is True, lhs and
   -- rhs must be convertible.
   | PTransform FC Bool t t

   -- | FC is decl-level, for errors, and Strings represent the
   -- namespace
   | PRunElabDecl FC t [String]
 deriving ((forall a b. (a -> b) -> PDecl' a -> PDecl' b)
-> (forall a b. a -> PDecl' b -> PDecl' a) -> Functor PDecl'
forall a b. a -> PDecl' b -> PDecl' a
forall a b. (a -> b) -> PDecl' a -> PDecl' b
forall (f :: * -> *).
(forall a b. (a -> b) -> f a -> f b)
-> (forall a b. a -> f b -> f a) -> Functor f
$cfmap :: forall a b. (a -> b) -> PDecl' a -> PDecl' b
fmap :: forall a b. (a -> b) -> PDecl' a -> PDecl' b
$c<$ :: forall a b. a -> PDecl' b -> PDecl' a
<$ :: forall a b. a -> PDecl' b -> PDecl' a
Functor, (forall x. PDecl' t -> Rep (PDecl' t) x)
-> (forall x. Rep (PDecl' t) x -> PDecl' t) -> Generic (PDecl' t)
forall x. Rep (PDecl' t) x -> PDecl' t
forall x. PDecl' t -> Rep (PDecl' t) x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
forall t x. Rep (PDecl' t) x -> PDecl' t
forall t x. PDecl' t -> Rep (PDecl' t) x
$cfrom :: forall t x. PDecl' t -> Rep (PDecl' t) x
from :: forall x. PDecl' t -> Rep (PDecl' t) x
$cto :: forall t x. Rep (PDecl' t) x -> PDecl' t
to :: forall x. Rep (PDecl' t) x -> PDecl' t
Generic)
{-!
deriving instance Binary PDecl'
!-}

-- | The set of source directives
data Directive = DLib Codegen String
               | DLink Codegen String
               | DFlag Codegen String
               | DInclude Codegen String
               | DHide Name
               | DFreeze Name
               | DThaw Name
               | DInjective Name
               | DSetTotal Name -- assert totality after checking
               | DAccess Accessibility
               | DDefault DefaultTotality
               | DLogging Integer
               | DDynamicLibs [String]
               | DNameHint Name FC [(Name, FC)]
               | DErrorHandlers Name FC Name FC [(Name, FC)]
               | DLanguage LanguageExt
               | DDeprecate Name String
               | DFragile Name String
               | DAutoImplicits Bool
               | DUsed FC Name Name
  deriving (forall x. Directive -> Rep Directive x)
-> (forall x. Rep Directive x -> Directive) -> Generic Directive
forall x. Rep Directive x -> Directive
forall x. Directive -> Rep Directive x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cfrom :: forall x. Directive -> Rep Directive x
from :: forall x. Directive -> Rep Directive x
$cto :: forall x. Rep Directive x -> Directive
to :: forall x. Rep Directive x -> Directive
Generic

-- | A set of instructions for things that need to happen in IState
-- after a term elaboration when there's been reflected elaboration.
data RDeclInstructions = RTyDeclInstrs Name FC [PArg] Type
                       | RClausesInstrs Name [([(Name, Term)], Term, Term)]
                       | RAddImplementation Name Name
                       | RDatatypeDeclInstrs Name [PArg]
                       -- | Datatype, constructors
                       | RDatatypeDefnInstrs Name Type [(Name, [PArg], Type)]


-- | For elaborator state
data EState = EState {
    EState -> [(Name, PDecl' PTerm)]
case_decls        :: [(Name, PDecl)]
  , EState -> [(Int, Elab' EState ())]
delayed_elab      :: [(Int, Elab' EState ())]
  , EState -> [RDeclInstructions]
new_tyDecls       :: [RDeclInstructions]
  , EState -> Set (FC', OutputAnnotation)
highlighting      :: S.Set (FC', OutputAnnotation)
  , EState -> [Name]
auto_binds        :: [Name]        -- ^  names bound as auto implicits
  , EState -> [(FC, Name)]
implicit_warnings :: [(FC, Name)] -- ^ Implicit warnings to report (location and global name)
  }

initEState :: EState
initEState :: EState
initEState = [(Name, PDecl' PTerm)]
-> [(Int, Elab' EState ())]
-> [RDeclInstructions]
-> Set (FC', OutputAnnotation)
-> [Name]
-> [(FC, Name)]
-> EState
EState [] [] [] Set (FC', OutputAnnotation)
forall a. Set a
S.empty [] []

type ElabD a = Elab' EState a

highlightSource :: FC -> OutputAnnotation -> ElabD ()
highlightSource :: FC -> OutputAnnotation -> Elab' EState ()
highlightSource FC
fc OutputAnnotation
annot =
  (EState -> EState) -> Elab' EState ()
forall aux. (aux -> aux) -> Elab' aux ()
updateAux (\EState
aux -> EState
aux { highlighting = S.insert (FC' fc, annot) (highlighting aux) })

-- | One clause of a top-level definition. Term arguments to constructors are:
--
-- 1. The whole application (missing for PClauseR and PWithR because they're within a "with" clause)
--
-- 2. The list of extra 'with' patterns
--
-- 3. The right-hand side
--
-- 4. The where block (PDecl' t)

data PClause' t = PClause  FC Name t [t] t                    [PDecl' t] -- ^ A normal top-level definition.
                | PWith    FC Name t [t] t (Maybe (Name, FC)) [PDecl' t]
                | PClauseR FC        [t] t                    [PDecl' t]
                | PWithR   FC        [t] t (Maybe (Name, FC)) [PDecl' t]
    deriving ((forall a b. (a -> b) -> PClause' a -> PClause' b)
-> (forall a b. a -> PClause' b -> PClause' a) -> Functor PClause'
forall a b. a -> PClause' b -> PClause' a
forall a b. (a -> b) -> PClause' a -> PClause' b
forall (f :: * -> *).
(forall a b. (a -> b) -> f a -> f b)
-> (forall a b. a -> f b -> f a) -> Functor f
$cfmap :: forall a b. (a -> b) -> PClause' a -> PClause' b
fmap :: forall a b. (a -> b) -> PClause' a -> PClause' b
$c<$ :: forall a b. a -> PClause' b -> PClause' a
<$ :: forall a b. a -> PClause' b -> PClause' a
Functor, (forall x. PClause' t -> Rep (PClause' t) x)
-> (forall x. Rep (PClause' t) x -> PClause' t)
-> Generic (PClause' t)
forall x. Rep (PClause' t) x -> PClause' t
forall x. PClause' t -> Rep (PClause' t) x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
forall t x. Rep (PClause' t) x -> PClause' t
forall t x. PClause' t -> Rep (PClause' t) x
$cfrom :: forall t x. PClause' t -> Rep (PClause' t) x
from :: forall x. PClause' t -> Rep (PClause' t) x
$cto :: forall t x. Rep (PClause' t) x -> PClause' t
to :: forall x. Rep (PClause' t) x -> PClause' t
Generic)
{-!
deriving instance Binary PClause'
!-}

-- | Data declaration
data PData' t  =
    -- | Data declaration
    PDatadecl { forall t. PData' t -> Name
d_name    :: Name -- ^ The name of the datatype
              , forall t. PData' t -> FC
d_name_fc :: FC   -- ^ The precise location of the type constructor name
              , forall t. PData' t -> t
d_tcon    :: t    -- ^ Type constructor
              , forall t.
PData' t
-> [(Docstring (Either Err PTerm),
     [(Name, Docstring (Either Err PTerm))], Name, FC, t, FC, [Name])]
d_cons    :: [(Docstring (Either Err PTerm), [(Name, Docstring (Either Err PTerm))], Name, FC, t, FC, [Name])] -- ^ Constructors
              }
  -- | "Placeholder" for data whose constructors are defined later
  | PLaterdecl { d_name    :: Name
               , d_name_fc :: FC
               , d_tcon    :: t
  } deriving ((forall a b. (a -> b) -> PData' a -> PData' b)
-> (forall a b. a -> PData' b -> PData' a) -> Functor PData'
forall a b. a -> PData' b -> PData' a
forall a b. (a -> b) -> PData' a -> PData' b
forall (f :: * -> *).
(forall a b. (a -> b) -> f a -> f b)
-> (forall a b. a -> f b -> f a) -> Functor f
$cfmap :: forall a b. (a -> b) -> PData' a -> PData' b
fmap :: forall a b. (a -> b) -> PData' a -> PData' b
$c<$ :: forall a b. a -> PData' b -> PData' a
<$ :: forall a b. a -> PData' b -> PData' a
Functor, (forall x. PData' t -> Rep (PData' t) x)
-> (forall x. Rep (PData' t) x -> PData' t) -> Generic (PData' t)
forall x. Rep (PData' t) x -> PData' t
forall x. PData' t -> Rep (PData' t) x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
forall t x. Rep (PData' t) x -> PData' t
forall t x. PData' t -> Rep (PData' t) x
$cfrom :: forall t x. PData' t -> Rep (PData' t) x
from :: forall x. PData' t -> Rep (PData' t) x
$cto :: forall t x. Rep (PData' t) x -> PData' t
to :: forall x. Rep (PData' t) x -> PData' t
Generic)

-- | Transform the FCs in a PData and its associated terms. The first
-- function transforms the general-purpose FCs, and the second
-- transforms those that are used for semantic source highlighting, so
-- they can be treated specially.
mapPDataFC :: (FC -> FC) -> (FC -> FC) -> PData -> PData
mapPDataFC :: (FC -> FC) -> (FC -> FC) -> PData -> PData
mapPDataFC FC -> FC
f FC -> FC
g (PDatadecl Name
n FC
nfc PTerm
tycon [(Docstring (Either Err PTerm),
  [(Name, Docstring (Either Err PTerm))], Name, FC, PTerm, FC,
  [Name])]
ctors) =
  Name
-> FC
-> PTerm
-> [(Docstring (Either Err PTerm),
     [(Name, Docstring (Either Err PTerm))], Name, FC, PTerm, FC,
     [Name])]
-> PData
forall t.
Name
-> FC
-> t
-> [(Docstring (Either Err PTerm),
     [(Name, Docstring (Either Err PTerm))], Name, FC, t, FC, [Name])]
-> PData' t
PDatadecl Name
n (FC -> FC
g FC
nfc) ((FC -> FC) -> (FC -> FC) -> PTerm -> PTerm
mapPTermFC FC -> FC
f FC -> FC
g PTerm
tycon) (((Docstring (Either Err PTerm),
  [(Name, Docstring (Either Err PTerm))], Name, FC, PTerm, FC,
  [Name])
 -> (Docstring (Either Err PTerm),
     [(Name, Docstring (Either Err PTerm))], Name, FC, PTerm, FC,
     [Name]))
-> [(Docstring (Either Err PTerm),
     [(Name, Docstring (Either Err PTerm))], Name, FC, PTerm, FC,
     [Name])]
-> [(Docstring (Either Err PTerm),
     [(Name, Docstring (Either Err PTerm))], Name, FC, PTerm, FC,
     [Name])]
forall a b. (a -> b) -> [a] -> [b]
map (Docstring (Either Err PTerm),
 [(Name, Docstring (Either Err PTerm))], Name, FC, PTerm, FC,
 [Name])
-> (Docstring (Either Err PTerm),
    [(Name, Docstring (Either Err PTerm))], Name, FC, PTerm, FC,
    [Name])
forall {a} {b} {c} {g}.
(a, b, c, FC, PTerm, FC, g) -> (a, b, c, FC, PTerm, FC, g)
ctorFC [(Docstring (Either Err PTerm),
  [(Name, Docstring (Either Err PTerm))], Name, FC, PTerm, FC,
  [Name])]
ctors)
    where ctorFC :: (a, b, c, FC, PTerm, FC, g) -> (a, b, c, FC, PTerm, FC, g)
ctorFC (a
doc, b
argDocs, c
n, FC
nfc, PTerm
ty, FC
fc, g
ns) =
                 (a
doc, b
argDocs, c
n, FC -> FC
g FC
nfc, (FC -> FC) -> (FC -> FC) -> PTerm -> PTerm
mapPTermFC FC -> FC
f FC -> FC
g PTerm
ty, FC -> FC
f FC
fc, g
ns)
mapPDataFC FC -> FC
f FC -> FC
g (PLaterdecl Name
n FC
nfc PTerm
tycon) =
  Name -> FC -> PTerm -> PData
forall t. Name -> FC -> t -> PData' t
PLaterdecl Name
n (FC -> FC
g FC
nfc) ((FC -> FC) -> (FC -> FC) -> PTerm -> PTerm
mapPTermFC FC -> FC
f FC -> FC
g PTerm
tycon)
{-!
deriving instance Binary PData'
!-}

-- Handy to get a free function for applying PTerm -> PTerm functions
-- across a program, by deriving Functor

type PDecl   = PDecl' PTerm
type PData   = PData' PTerm
type PClause = PClause' PTerm

-- | Transform the FCs in a PTerm. The first function transforms the
-- general-purpose FCs, and the second transforms those that are used
-- for semantic source highlighting, so they can be treated specially.
mapPDeclFC :: (FC -> FC) -> (FC -> FC) -> PDecl -> PDecl
mapPDeclFC :: (FC -> FC) -> (FC -> FC) -> PDecl' PTerm -> PDecl' PTerm
mapPDeclFC FC -> FC
f FC -> FC
g (PFix FC
fc Fixity
fixity [String]
ops) =
    FC -> Fixity -> [String] -> PDecl' PTerm
forall t. FC -> Fixity -> [String] -> PDecl' t
PFix (FC -> FC
f FC
fc) Fixity
fixity [String]
ops
mapPDeclFC FC -> FC
f FC -> FC
g (PTy Docstring (Either Err PTerm)
doc [(Name, Docstring (Either Err PTerm))]
argdocs SyntaxInfo
syn FC
fc [FnOpt]
opts Name
n FC
nfc PTerm
ty) =
    Docstring (Either Err PTerm)
-> [(Name, Docstring (Either Err PTerm))]
-> SyntaxInfo
-> FC
-> [FnOpt]
-> Name
-> FC
-> PTerm
-> PDecl' PTerm
forall t.
Docstring (Either Err t)
-> [(Name, Docstring (Either Err t))]
-> SyntaxInfo
-> FC
-> [FnOpt]
-> Name
-> FC
-> t
-> PDecl' t
PTy Docstring (Either Err PTerm)
doc [(Name, Docstring (Either Err PTerm))]
argdocs SyntaxInfo
syn (FC -> FC
f FC
fc) [FnOpt]
opts Name
n (FC -> FC
g FC
nfc) ((FC -> FC) -> (FC -> FC) -> PTerm -> PTerm
mapPTermFC FC -> FC
f FC -> FC
g PTerm
ty)
mapPDeclFC FC -> FC
f FC -> FC
g (PPostulate Bool
ext Docstring (Either Err PTerm)
doc SyntaxInfo
syn FC
fc FC
nfc [FnOpt]
opts Name
n PTerm
ty) =
    Bool
-> Docstring (Either Err PTerm)
-> SyntaxInfo
-> FC
-> FC
-> [FnOpt]
-> Name
-> PTerm
-> PDecl' PTerm
forall t.
Bool
-> Docstring (Either Err t)
-> SyntaxInfo
-> FC
-> FC
-> [FnOpt]
-> Name
-> t
-> PDecl' t
PPostulate Bool
ext Docstring (Either Err PTerm)
doc SyntaxInfo
syn (FC -> FC
f FC
fc) (FC -> FC
g FC
nfc) [FnOpt]
opts Name
n ((FC -> FC) -> (FC -> FC) -> PTerm -> PTerm
mapPTermFC FC -> FC
f FC -> FC
g PTerm
ty)

mapPDeclFC FC -> FC
f FC -> FC
g (PClauses FC
fc [FnOpt]
opts Name
n [PClause' PTerm]
clauses) =
    FC -> [FnOpt] -> Name -> [PClause' PTerm] -> PDecl' PTerm
forall t. FC -> [FnOpt] -> Name -> [PClause' t] -> PDecl' t
PClauses (FC -> FC
f FC
fc) [FnOpt]
opts Name
n ((PClause' PTerm -> PClause' PTerm)
-> [PClause' PTerm] -> [PClause' PTerm]
forall a b. (a -> b) -> [a] -> [b]
map ((PTerm -> PTerm) -> PClause' PTerm -> PClause' PTerm
forall a b. (a -> b) -> PClause' a -> PClause' b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap ((FC -> FC) -> (FC -> FC) -> PTerm -> PTerm
mapPTermFC FC -> FC
f FC -> FC
g)) [PClause' PTerm]
clauses)
mapPDeclFC FC -> FC
f FC -> FC
g (PCAF FC
fc Name
n PTerm
tm) = FC -> Name -> PTerm -> PDecl' PTerm
forall t. FC -> Name -> t -> PDecl' t
PCAF (FC -> FC
f FC
fc) Name
n ((FC -> FC) -> (FC -> FC) -> PTerm -> PTerm
mapPTermFC FC -> FC
f FC -> FC
g PTerm
tm)
mapPDeclFC FC -> FC
f FC -> FC
g (PData Docstring (Either Err PTerm)
doc [(Name, Docstring (Either Err PTerm))]
argdocs SyntaxInfo
syn FC
fc DataOpts
opts PData
dat) =
    Docstring (Either Err PTerm)
-> [(Name, Docstring (Either Err PTerm))]
-> SyntaxInfo
-> FC
-> DataOpts
-> PData
-> PDecl' PTerm
forall t.
Docstring (Either Err t)
-> [(Name, Docstring (Either Err t))]
-> SyntaxInfo
-> FC
-> DataOpts
-> PData' t
-> PDecl' t
PData Docstring (Either Err PTerm)
doc [(Name, Docstring (Either Err PTerm))]
argdocs SyntaxInfo
syn (FC -> FC
f FC
fc) DataOpts
opts ((FC -> FC) -> (FC -> FC) -> PData -> PData
mapPDataFC FC -> FC
f FC -> FC
g PData
dat)
mapPDeclFC FC -> FC
f FC -> FC
g (PParams FC
fc [(Name, PTerm)]
params [PDecl' PTerm]
decls) =
    FC -> [(Name, PTerm)] -> [PDecl' PTerm] -> PDecl' PTerm
forall t. FC -> [(Name, t)] -> [PDecl' t] -> PDecl' t
PParams (FC -> FC
f FC
fc)
            (((Name, PTerm) -> (Name, PTerm))
-> [(Name, PTerm)] -> [(Name, PTerm)]
forall a b. (a -> b) -> [a] -> [b]
map (\(Name
n, PTerm
ty) -> (Name
n, (FC -> FC) -> (FC -> FC) -> PTerm -> PTerm
mapPTermFC FC -> FC
f FC -> FC
g PTerm
ty)) [(Name, PTerm)]
params)
            ((PDecl' PTerm -> PDecl' PTerm) -> [PDecl' PTerm] -> [PDecl' PTerm]
forall a b. (a -> b) -> [a] -> [b]
map ((FC -> FC) -> (FC -> FC) -> PDecl' PTerm -> PDecl' PTerm
mapPDeclFC FC -> FC
f FC -> FC
g) [PDecl' PTerm]
decls)
mapPDeclFC FC -> FC
f FC -> FC
g (POpenInterfaces FC
fc [Name]
ifs [PDecl' PTerm]
decls) =
    FC -> [Name] -> [PDecl' PTerm] -> PDecl' PTerm
forall t. FC -> [Name] -> [PDecl' t] -> PDecl' t
POpenInterfaces (FC -> FC
f FC
fc) [Name]
ifs ((PDecl' PTerm -> PDecl' PTerm) -> [PDecl' PTerm] -> [PDecl' PTerm]
forall a b. (a -> b) -> [a] -> [b]
map ((FC -> FC) -> (FC -> FC) -> PDecl' PTerm -> PDecl' PTerm
mapPDeclFC FC -> FC
f FC -> FC
g) [PDecl' PTerm]
decls)
mapPDeclFC FC -> FC
f FC -> FC
g (PNamespace String
ns FC
fc [PDecl' PTerm]
decls) =
    String -> FC -> [PDecl' PTerm] -> PDecl' PTerm
forall t. String -> FC -> [PDecl' t] -> PDecl' t
PNamespace String
ns (FC -> FC
f FC
fc) ((PDecl' PTerm -> PDecl' PTerm) -> [PDecl' PTerm] -> [PDecl' PTerm]
forall a b. (a -> b) -> [a] -> [b]
map ((FC -> FC) -> (FC -> FC) -> PDecl' PTerm -> PDecl' PTerm
mapPDeclFC FC -> FC
f FC -> FC
g) [PDecl' PTerm]
decls)
mapPDeclFC FC -> FC
f FC -> FC
g (PRecord Docstring (Either Err PTerm)
doc SyntaxInfo
syn FC
fc DataOpts
opts Name
n FC
nfc [(Name, FC, Plicity, PTerm)]
params [(Name, Docstring (Either Err PTerm))]
paramdocs [(Maybe (Name, FC), Plicity, PTerm,
  Maybe (Docstring (Either Err PTerm)))]
fields Maybe (Name, FC)
ctor Docstring (Either Err PTerm)
ctorDoc SyntaxInfo
syn') =
    Docstring (Either Err PTerm)
-> SyntaxInfo
-> FC
-> DataOpts
-> Name
-> FC
-> [(Name, FC, Plicity, PTerm)]
-> [(Name, Docstring (Either Err PTerm))]
-> [(Maybe (Name, FC), Plicity, PTerm,
     Maybe (Docstring (Either Err PTerm)))]
-> Maybe (Name, FC)
-> Docstring (Either Err PTerm)
-> SyntaxInfo
-> PDecl' PTerm
forall t.
Docstring (Either Err t)
-> SyntaxInfo
-> FC
-> DataOpts
-> Name
-> FC
-> [(Name, FC, Plicity, t)]
-> [(Name, Docstring (Either Err t))]
-> [(Maybe (Name, FC), Plicity, t,
     Maybe (Docstring (Either Err t)))]
-> Maybe (Name, FC)
-> Docstring (Either Err t)
-> SyntaxInfo
-> PDecl' t
PRecord Docstring (Either Err PTerm)
doc SyntaxInfo
syn (FC -> FC
f FC
fc) DataOpts
opts Name
n (FC -> FC
g FC
nfc)
            (((Name, FC, Plicity, PTerm) -> (Name, FC, Plicity, PTerm))
-> [(Name, FC, Plicity, PTerm)] -> [(Name, FC, Plicity, PTerm)]
forall a b. (a -> b) -> [a] -> [b]
map (\(Name
pn, FC
pnfc, Plicity
plic, PTerm
ty) -> (Name
pn, FC -> FC
g FC
pnfc, Plicity
plic, (FC -> FC) -> (FC -> FC) -> PTerm -> PTerm
mapPTermFC FC -> FC
f FC -> FC
g PTerm
ty)) [(Name, FC, Plicity, PTerm)]
params)
            [(Name, Docstring (Either Err PTerm))]
paramdocs
            (((Maybe (Name, FC), Plicity, PTerm,
  Maybe (Docstring (Either Err PTerm)))
 -> (Maybe (Name, FC), Plicity, PTerm,
     Maybe (Docstring (Either Err PTerm))))
-> [(Maybe (Name, FC), Plicity, PTerm,
     Maybe (Docstring (Either Err PTerm)))]
-> [(Maybe (Name, FC), Plicity, PTerm,
     Maybe (Docstring (Either Err PTerm)))]
forall a b. (a -> b) -> [a] -> [b]
map (\(Maybe (Name, FC)
fn, Plicity
plic, PTerm
ty, Maybe (Docstring (Either Err PTerm))
fdoc) -> (((Name, FC) -> (Name, FC)) -> Maybe (Name, FC) -> Maybe (Name, FC)
forall a b. (a -> b) -> Maybe a -> Maybe b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (\(Name
fn', FC
fnfc) -> (Name
fn', FC -> FC
g FC
fnfc)) Maybe (Name, FC)
fn,
                                            Plicity
plic, (FC -> FC) -> (FC -> FC) -> PTerm -> PTerm
mapPTermFC FC -> FC
f FC -> FC
g PTerm
ty, Maybe (Docstring (Either Err PTerm))
fdoc))
                 [(Maybe (Name, FC), Plicity, PTerm,
  Maybe (Docstring (Either Err PTerm)))]
fields)
            (((Name, FC) -> (Name, FC)) -> Maybe (Name, FC) -> Maybe (Name, FC)
forall a b. (a -> b) -> Maybe a -> Maybe b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (\(Name
ctorN, FC
ctorNFC) -> (Name
ctorN, FC -> FC
g FC
ctorNFC)) Maybe (Name, FC)
ctor)
            Docstring (Either Err PTerm)
ctorDoc
            SyntaxInfo
syn'
mapPDeclFC FC -> FC
f FC -> FC
g (PInterface Docstring (Either Err PTerm)
doc SyntaxInfo
syn FC
fc [(Name, PTerm)]
constrs Name
n FC
nfc [(Name, FC, PTerm)]
params [(Name, Docstring (Either Err PTerm))]
paramDocs [(Name, FC)]
det [PDecl' PTerm]
body Maybe (Name, FC)
ctor Docstring (Either Err PTerm)
ctorDoc) =
    Docstring (Either Err PTerm)
-> SyntaxInfo
-> FC
-> [(Name, PTerm)]
-> Name
-> FC
-> [(Name, FC, PTerm)]
-> [(Name, Docstring (Either Err PTerm))]
-> [(Name, FC)]
-> [PDecl' PTerm]
-> Maybe (Name, FC)
-> Docstring (Either Err PTerm)
-> PDecl' PTerm
forall t.
Docstring (Either Err t)
-> SyntaxInfo
-> FC
-> [(Name, t)]
-> Name
-> FC
-> [(Name, FC, t)]
-> [(Name, Docstring (Either Err t))]
-> [(Name, FC)]
-> [PDecl' t]
-> Maybe (Name, FC)
-> Docstring (Either Err t)
-> PDecl' t
PInterface Docstring (Either Err PTerm)
doc SyntaxInfo
syn (FC -> FC
f FC
fc)
           (((Name, PTerm) -> (Name, PTerm))
-> [(Name, PTerm)] -> [(Name, PTerm)]
forall a b. (a -> b) -> [a] -> [b]
map (\(Name
constrn, PTerm
constr) -> (Name
constrn, (FC -> FC) -> (FC -> FC) -> PTerm -> PTerm
mapPTermFC FC -> FC
f FC -> FC
g PTerm
constr)) [(Name, PTerm)]
constrs)
           Name
n (FC -> FC
g FC
nfc) (((Name, FC, PTerm) -> (Name, FC, PTerm))
-> [(Name, FC, PTerm)] -> [(Name, FC, PTerm)]
forall a b. (a -> b) -> [a] -> [b]
map (\(Name
n, FC
nfc, PTerm
pty) -> (Name
n, FC -> FC
g FC
nfc, (FC -> FC) -> (FC -> FC) -> PTerm -> PTerm
mapPTermFC FC -> FC
f FC -> FC
g PTerm
pty)) [(Name, FC, PTerm)]
params)
           [(Name, Docstring (Either Err PTerm))]
paramDocs (((Name, FC) -> (Name, FC)) -> [(Name, FC)] -> [(Name, FC)]
forall a b. (a -> b) -> [a] -> [b]
map (\(Name
dn, FC
dnfc) -> (Name
dn, FC -> FC
g FC
dnfc)) [(Name, FC)]
det)
           ((PDecl' PTerm -> PDecl' PTerm) -> [PDecl' PTerm] -> [PDecl' PTerm]
forall a b. (a -> b) -> [a] -> [b]
map ((FC -> FC) -> (FC -> FC) -> PDecl' PTerm -> PDecl' PTerm
mapPDeclFC FC -> FC
f FC -> FC
g) [PDecl' PTerm]
body)
           (((Name, FC) -> (Name, FC)) -> Maybe (Name, FC) -> Maybe (Name, FC)
forall a b. (a -> b) -> Maybe a -> Maybe b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (\(Name
n, FC
nfc) -> (Name
n, FC -> FC
g FC
nfc)) Maybe (Name, FC)
ctor)
           Docstring (Either Err PTerm)
ctorDoc
mapPDeclFC FC -> FC
f FC -> FC
g (PImplementation Docstring (Either Err PTerm)
doc [(Name, Docstring (Either Err PTerm))]
paramDocs SyntaxInfo
syn FC
fc [(Name, PTerm)]
constrs [Name]
pnames Accessibility
cn [FnOpt]
acc Name
opts FC
cnfc [PTerm]
params [(Name, PTerm)]
pextra PTerm
implTy Maybe Name
implN [PDecl' PTerm]
body) =
    Docstring (Either Err PTerm)
-> [(Name, Docstring (Either Err PTerm))]
-> SyntaxInfo
-> FC
-> [(Name, PTerm)]
-> [Name]
-> Accessibility
-> [FnOpt]
-> Name
-> FC
-> [PTerm]
-> [(Name, PTerm)]
-> PTerm
-> Maybe Name
-> [PDecl' PTerm]
-> PDecl' PTerm
forall t.
Docstring (Either Err t)
-> [(Name, Docstring (Either Err t))]
-> SyntaxInfo
-> FC
-> [(Name, t)]
-> [Name]
-> Accessibility
-> [FnOpt]
-> Name
-> FC
-> [t]
-> [(Name, t)]
-> t
-> Maybe Name
-> [PDecl' t]
-> PDecl' t
PImplementation Docstring (Either Err PTerm)
doc [(Name, Docstring (Either Err PTerm))]
paramDocs SyntaxInfo
syn (FC -> FC
f FC
fc)
                    (((Name, PTerm) -> (Name, PTerm))
-> [(Name, PTerm)] -> [(Name, PTerm)]
forall a b. (a -> b) -> [a] -> [b]
map (\(Name
constrN, PTerm
constrT) -> (Name
constrN, (FC -> FC) -> (FC -> FC) -> PTerm -> PTerm
mapPTermFC FC -> FC
f FC -> FC
g PTerm
constrT)) [(Name, PTerm)]
constrs)
                    [Name]
pnames Accessibility
cn [FnOpt]
acc Name
opts (FC -> FC
g FC
cnfc) ((PTerm -> PTerm) -> [PTerm] -> [PTerm]
forall a b. (a -> b) -> [a] -> [b]
map ((FC -> FC) -> (FC -> FC) -> PTerm -> PTerm
mapPTermFC FC -> FC
f FC -> FC
g) [PTerm]
params)
                    (((Name, PTerm) -> (Name, PTerm))
-> [(Name, PTerm)] -> [(Name, PTerm)]
forall a b. (a -> b) -> [a] -> [b]
map (\(Name
en, PTerm
et) -> (Name
en, (FC -> FC) -> (FC -> FC) -> PTerm -> PTerm
mapPTermFC FC -> FC
f FC -> FC
g PTerm
et)) [(Name, PTerm)]
pextra)
                    ((FC -> FC) -> (FC -> FC) -> PTerm -> PTerm
mapPTermFC FC -> FC
f FC -> FC
g PTerm
implTy)
                    Maybe Name
implN
                    ((PDecl' PTerm -> PDecl' PTerm) -> [PDecl' PTerm] -> [PDecl' PTerm]
forall a b. (a -> b) -> [a] -> [b]
map ((FC -> FC) -> (FC -> FC) -> PDecl' PTerm -> PDecl' PTerm
mapPDeclFC FC -> FC
f FC -> FC
g) [PDecl' PTerm]
body)
mapPDeclFC FC -> FC
f FC -> FC
g (PDSL Name
n DSL
dsl) = Name -> DSL -> PDecl' PTerm
forall t. Name -> DSL' t -> PDecl' t
PDSL Name
n ((PTerm -> PTerm) -> DSL -> DSL
forall a b. (a -> b) -> DSL' a -> DSL' b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap ((FC -> FC) -> (FC -> FC) -> PTerm -> PTerm
mapPTermFC FC -> FC
f FC -> FC
g) DSL
dsl)
mapPDeclFC FC -> FC
f FC -> FC
g (PSyntax FC
fc Syntax
syn) = FC -> Syntax -> PDecl' PTerm
forall t. FC -> Syntax -> PDecl' t
PSyntax (FC -> FC
f FC
fc) (Syntax -> PDecl' PTerm) -> Syntax -> PDecl' PTerm
forall a b. (a -> b) -> a -> b
$
                                    case Syntax
syn of
                                      Rule [SSymbol]
syms PTerm
tm SynContext
ctxt -> [SSymbol] -> PTerm -> SynContext -> Syntax
Rule [SSymbol]
syms ((FC -> FC) -> (FC -> FC) -> PTerm -> PTerm
mapPTermFC FC -> FC
f FC -> FC
g PTerm
tm) SynContext
ctxt
                                      DeclRule [SSymbol]
syms [PDecl' PTerm]
decls -> [SSymbol] -> [PDecl' PTerm] -> Syntax
DeclRule [SSymbol]
syms ((PDecl' PTerm -> PDecl' PTerm) -> [PDecl' PTerm] -> [PDecl' PTerm]
forall a b. (a -> b) -> [a] -> [b]
map ((FC -> FC) -> (FC -> FC) -> PDecl' PTerm -> PDecl' PTerm
mapPDeclFC FC -> FC
f FC -> FC
g) [PDecl' PTerm]
decls)
mapPDeclFC FC -> FC
f FC -> FC
g (PMutual FC
fc [PDecl' PTerm]
decls) =
    FC -> [PDecl' PTerm] -> PDecl' PTerm
forall t. FC -> [PDecl' t] -> PDecl' t
PMutual (FC -> FC
f FC
fc) ((PDecl' PTerm -> PDecl' PTerm) -> [PDecl' PTerm] -> [PDecl' PTerm]
forall a b. (a -> b) -> [a] -> [b]
map ((FC -> FC) -> (FC -> FC) -> PDecl' PTerm -> PDecl' PTerm
mapPDeclFC FC -> FC
f FC -> FC
g) [PDecl' PTerm]
decls)
mapPDeclFC FC -> FC
f FC -> FC
g (PDirective Directive
d) =
    Directive -> PDecl' PTerm
forall t. Directive -> PDecl' t
PDirective (Directive -> PDecl' PTerm) -> Directive -> PDecl' PTerm
forall a b. (a -> b) -> a -> b
$
      case Directive
d of
        DNameHint Name
n FC
nfc [(Name, FC)]
ns ->
            Name -> FC -> [(Name, FC)] -> Directive
DNameHint Name
n (FC -> FC
g FC
nfc) (((Name, FC) -> (Name, FC)) -> [(Name, FC)] -> [(Name, FC)]
forall a b. (a -> b) -> [a] -> [b]
map (\(Name
hn, FC
hnfc) -> (Name
hn, FC -> FC
g FC
hnfc)) [(Name, FC)]
ns)
        DErrorHandlers Name
n FC
nfc Name
n' FC
nfc' [(Name, FC)]
ns ->
            Name -> FC -> Name -> FC -> [(Name, FC)] -> Directive
DErrorHandlers Name
n (FC -> FC
g FC
nfc) Name
n' (FC -> FC
g FC
nfc') ([(Name, FC)] -> Directive) -> [(Name, FC)] -> Directive
forall a b. (a -> b) -> a -> b
$
                ((Name, FC) -> (Name, FC)) -> [(Name, FC)] -> [(Name, FC)]
forall a b. (a -> b) -> [a] -> [b]
map (\(Name
an, FC
anfc) -> (Name
an, FC -> FC
g FC
anfc)) [(Name, FC)]
ns
mapPDeclFC FC -> FC
f FC -> FC
g (PProvider Docstring (Either Err PTerm)
doc SyntaxInfo
syn FC
fc FC
nfc ProvideWhat' PTerm
what Name
n) =
    Docstring (Either Err PTerm)
-> SyntaxInfo
-> FC
-> FC
-> ProvideWhat' PTerm
-> Name
-> PDecl' PTerm
forall t.
Docstring (Either Err t)
-> SyntaxInfo -> FC -> FC -> ProvideWhat' t -> Name -> PDecl' t
PProvider Docstring (Either Err PTerm)
doc SyntaxInfo
syn (FC -> FC
f FC
fc) (FC -> FC
g FC
nfc) ((PTerm -> PTerm) -> ProvideWhat' PTerm -> ProvideWhat' PTerm
forall a b. (a -> b) -> ProvideWhat' a -> ProvideWhat' b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap ((FC -> FC) -> (FC -> FC) -> PTerm -> PTerm
mapPTermFC FC -> FC
f FC -> FC
g) ProvideWhat' PTerm
what) Name
n
mapPDeclFC FC -> FC
f FC -> FC
g (PTransform FC
fc Bool
safe PTerm
l PTerm
r) =
    FC -> Bool -> PTerm -> PTerm -> PDecl' PTerm
forall t. FC -> Bool -> t -> t -> PDecl' t
PTransform (FC -> FC
f FC
fc) Bool
safe ((FC -> FC) -> (FC -> FC) -> PTerm -> PTerm
mapPTermFC FC -> FC
f FC -> FC
g PTerm
l) ((FC -> FC) -> (FC -> FC) -> PTerm -> PTerm
mapPTermFC FC -> FC
f FC -> FC
g PTerm
r)
mapPDeclFC FC -> FC
f FC -> FC
g (PRunElabDecl FC
fc PTerm
script [String]
ns) =
    FC -> PTerm -> [String] -> PDecl' PTerm
forall t. FC -> t -> [String] -> PDecl' t
PRunElabDecl (FC -> FC
f FC
fc) ((FC -> FC) -> (FC -> FC) -> PTerm -> PTerm
mapPTermFC FC -> FC
f FC -> FC
g PTerm
script) [String]
ns

-- | Get all the names declared in a declaration
declared :: PDecl -> [Name]
declared :: PDecl' PTerm -> [Name]
declared (PFix FC
_ Fixity
_ [String]
_) = []
declared (PTy Docstring (Either Err PTerm)
_ [(Name, Docstring (Either Err PTerm))]
_ SyntaxInfo
_ FC
_ [FnOpt]
_ Name
n FC
fc PTerm
t) = [Name
n]
declared (PPostulate Bool
_ Docstring (Either Err PTerm)
_ SyntaxInfo
_ FC
_ FC
_ [FnOpt]
_ Name
n PTerm
t) = [Name
n]
declared (PClauses FC
_ [FnOpt]
_ Name
n [PClause' PTerm]
_) = [] -- not a declaration
declared (PCAF FC
_ Name
n PTerm
_) = [Name
n]
declared (PData Docstring (Either Err PTerm)
_ [(Name, Docstring (Either Err PTerm))]
_ SyntaxInfo
_ FC
_ DataOpts
_ (PDatadecl Name
n FC
_ PTerm
_ [(Docstring (Either Err PTerm),
  [(Name, Docstring (Either Err PTerm))], Name, FC, PTerm, FC,
  [Name])]
ts)) = Name
n Name -> [Name] -> [Name]
forall a. a -> [a] -> [a]
: ((Docstring (Either Err PTerm),
  [(Name, Docstring (Either Err PTerm))], Name, FC, PTerm, FC,
  [Name])
 -> Name)
-> [(Docstring (Either Err PTerm),
     [(Name, Docstring (Either Err PTerm))], Name, FC, PTerm, FC,
     [Name])]
-> [Name]
forall a b. (a -> b) -> [a] -> [b]
map (Docstring (Either Err PTerm),
 [(Name, Docstring (Either Err PTerm))], Name, FC, PTerm, FC,
 [Name])
-> Name
forall {a} {b} {c} {d} {e} {f} {g}. (a, b, c, d, e, f, g) -> c
fstt [(Docstring (Either Err PTerm),
  [(Name, Docstring (Either Err PTerm))], Name, FC, PTerm, FC,
  [Name])]
ts
   where fstt :: (a, b, c, d, e, f, g) -> c
fstt (a
_, b
_, c
a, d
_, e
_, f
_, g
_) = c
a
declared (PData Docstring (Either Err PTerm)
_ [(Name, Docstring (Either Err PTerm))]
_ SyntaxInfo
_ FC
_ DataOpts
_ (PLaterdecl Name
n FC
_ PTerm
_)) = [Name
n]
declared (PParams FC
_ [(Name, PTerm)]
_ [PDecl' PTerm]
ds) = (PDecl' PTerm -> [Name]) -> [PDecl' PTerm] -> [Name]
forall (t :: * -> *) a b. Foldable t => (a -> [b]) -> t a -> [b]
concatMap PDecl' PTerm -> [Name]
declared [PDecl' PTerm]
ds
declared (POpenInterfaces FC
_ [Name]
_ [PDecl' PTerm]
ds) = (PDecl' PTerm -> [Name]) -> [PDecl' PTerm] -> [Name]
forall (t :: * -> *) a b. Foldable t => (a -> [b]) -> t a -> [b]
concatMap PDecl' PTerm -> [Name]
declared [PDecl' PTerm]
ds
declared (PNamespace String
_ FC
_ [PDecl' PTerm]
ds) = (PDecl' PTerm -> [Name]) -> [PDecl' PTerm] -> [Name]
forall (t :: * -> *) a b. Foldable t => (a -> [b]) -> t a -> [b]
concatMap PDecl' PTerm -> [Name]
declared [PDecl' PTerm]
ds
declared (PRecord Docstring (Either Err PTerm)
_ SyntaxInfo
_ FC
_ DataOpts
_ Name
n  FC
_ [(Name, FC, Plicity, PTerm)]
_ [(Name, Docstring (Either Err PTerm))]
_ [(Maybe (Name, FC), Plicity, PTerm,
  Maybe (Docstring (Either Err PTerm)))]
_ Maybe (Name, FC)
cn Docstring (Either Err PTerm)
_ SyntaxInfo
_) = Name
n Name -> [Name] -> [Name]
forall a. a -> [a] -> [a]
: ((Name, FC) -> Name) -> [(Name, FC)] -> [Name]
forall a b. (a -> b) -> [a] -> [b]
map (Name, FC) -> Name
forall a b. (a, b) -> a
fst (Maybe (Name, FC) -> [(Name, FC)]
forall a. Maybe a -> [a]
maybeToList Maybe (Name, FC)
cn)
declared (PInterface Docstring (Either Err PTerm)
_ SyntaxInfo
_ FC
_ [(Name, PTerm)]
_ Name
n FC
_ [(Name, FC, PTerm)]
_ [(Name, Docstring (Either Err PTerm))]
_ [(Name, FC)]
_ [PDecl' PTerm]
ms Maybe (Name, FC)
cn Docstring (Either Err PTerm)
cd) = Name
n Name -> [Name] -> [Name]
forall a. a -> [a] -> [a]
: (((Name, FC) -> Name) -> [(Name, FC)] -> [Name]
forall a b. (a -> b) -> [a] -> [b]
map (Name, FC) -> Name
forall a b. (a, b) -> a
fst (Maybe (Name, FC) -> [(Name, FC)]
forall a. Maybe a -> [a]
maybeToList Maybe (Name, FC)
cn) [Name] -> [Name] -> [Name]
forall a. [a] -> [a] -> [a]
++ (PDecl' PTerm -> [Name]) -> [PDecl' PTerm] -> [Name]
forall (t :: * -> *) a b. Foldable t => (a -> [b]) -> t a -> [b]
concatMap PDecl' PTerm -> [Name]
declared [PDecl' PTerm]
ms)
declared (PImplementation Docstring (Either Err PTerm)
_ [(Name, Docstring (Either Err PTerm))]
_ SyntaxInfo
_ FC
_ [(Name, PTerm)]
_ [Name]
_ Accessibility
_ [FnOpt]
_ Name
_ FC
_ [PTerm]
_ [(Name, PTerm)]
_ PTerm
_ Maybe Name
mn [PDecl' PTerm]
_)
    = case Maybe Name
mn of
           Maybe Name
Nothing -> []
           Just Name
n -> [Name
n]
declared (PDSL Name
n DSL
_) = [Name
n]
declared (PSyntax FC
_ Syntax
_) = []
declared (PMutual FC
_ [PDecl' PTerm]
ds) = (PDecl' PTerm -> [Name]) -> [PDecl' PTerm] -> [Name]
forall (t :: * -> *) a b. Foldable t => (a -> [b]) -> t a -> [b]
concatMap PDecl' PTerm -> [Name]
declared [PDecl' PTerm]
ds
declared (PDirective Directive
_) = []
declared PDecl' PTerm
_ = []

-- get the names declared, not counting nested parameter blocks
tldeclared :: PDecl -> [Name]
tldeclared :: PDecl' PTerm -> [Name]
tldeclared (PFix FC
_ Fixity
_ [String]
_)                           = []
tldeclared (PTy Docstring (Either Err PTerm)
_ [(Name, Docstring (Either Err PTerm))]
_ SyntaxInfo
_ FC
_ [FnOpt]
_ Name
n FC
_ PTerm
t)                  = [Name
n]
tldeclared (PPostulate Bool
_ Docstring (Either Err PTerm)
_ SyntaxInfo
_ FC
_ FC
_ [FnOpt]
_ Name
n PTerm
t)           = [Name
n]
tldeclared (PClauses FC
_ [FnOpt]
_ Name
n [PClause' PTerm]
_)                     = [] -- not a declaration
tldeclared (PRecord Docstring (Either Err PTerm)
_ SyntaxInfo
_ FC
_ DataOpts
_ Name
n FC
_ [(Name, FC, Plicity, PTerm)]
_ [(Name, Docstring (Either Err PTerm))]
_ [(Maybe (Name, FC), Plicity, PTerm,
  Maybe (Docstring (Either Err PTerm)))]
_ Maybe (Name, FC)
cn Docstring (Either Err PTerm)
_ SyntaxInfo
_)     = Name
n Name -> [Name] -> [Name]
forall a. a -> [a] -> [a]
: ((Name, FC) -> Name) -> [(Name, FC)] -> [Name]
forall a b. (a -> b) -> [a] -> [b]
map (Name, FC) -> Name
forall a b. (a, b) -> a
fst (Maybe (Name, FC) -> [(Name, FC)]
forall a. Maybe a -> [a]
maybeToList Maybe (Name, FC)
cn)
tldeclared (PData Docstring (Either Err PTerm)
_ [(Name, Docstring (Either Err PTerm))]
_ SyntaxInfo
_ FC
_ DataOpts
_ (PDatadecl Name
n FC
_ PTerm
_ [(Docstring (Either Err PTerm),
  [(Name, Docstring (Either Err PTerm))], Name, FC, PTerm, FC,
  [Name])]
ts)) = Name
n Name -> [Name] -> [Name]
forall a. a -> [a] -> [a]
: ((Docstring (Either Err PTerm),
  [(Name, Docstring (Either Err PTerm))], Name, FC, PTerm, FC,
  [Name])
 -> Name)
-> [(Docstring (Either Err PTerm),
     [(Name, Docstring (Either Err PTerm))], Name, FC, PTerm, FC,
     [Name])]
-> [Name]
forall a b. (a -> b) -> [a] -> [b]
map (Docstring (Either Err PTerm),
 [(Name, Docstring (Either Err PTerm))], Name, FC, PTerm, FC,
 [Name])
-> Name
forall {a} {b} {c} {d} {e} {f} {g}. (a, b, c, d, e, f, g) -> c
fstt [(Docstring (Either Err PTerm),
  [(Name, Docstring (Either Err PTerm))], Name, FC, PTerm, FC,
  [Name])]
ts
   where fstt :: (a, b, c, d, e, f, g) -> c
fstt (a
_, b
_, c
a, d
_, e
_, f
_, g
_) = c
a
tldeclared (PParams FC
_ [(Name, PTerm)]
_ [PDecl' PTerm]
ds)                       = []
tldeclared (POpenInterfaces FC
_ [Name]
_ [PDecl' PTerm]
ds)               = (PDecl' PTerm -> [Name]) -> [PDecl' PTerm] -> [Name]
forall (t :: * -> *) a b. Foldable t => (a -> [b]) -> t a -> [b]
concatMap PDecl' PTerm -> [Name]
tldeclared [PDecl' PTerm]
ds
tldeclared (PMutual FC
_ [PDecl' PTerm]
ds)                         = (PDecl' PTerm -> [Name]) -> [PDecl' PTerm] -> [Name]
forall (t :: * -> *) a b. Foldable t => (a -> [b]) -> t a -> [b]
concatMap PDecl' PTerm -> [Name]
tldeclared [PDecl' PTerm]
ds
tldeclared (PNamespace String
_ FC
_ [PDecl' PTerm]
ds)                    = (PDecl' PTerm -> [Name]) -> [PDecl' PTerm] -> [Name]
forall (t :: * -> *) a b. Foldable t => (a -> [b]) -> t a -> [b]
concatMap PDecl' PTerm -> [Name]
tldeclared [PDecl' PTerm]
ds
tldeclared (PInterface Docstring (Either Err PTerm)
_ SyntaxInfo
_ FC
_ [(Name, PTerm)]
_ Name
n FC
_ [(Name, FC, PTerm)]
_ [(Name, Docstring (Either Err PTerm))]
_ [(Name, FC)]
_ [PDecl' PTerm]
ms Maybe (Name, FC)
cn Docstring (Either Err PTerm)
_)     = Name
n Name -> [Name] -> [Name]
forall a. a -> [a] -> [a]
: (((Name, FC) -> Name) -> [(Name, FC)] -> [Name]
forall a b. (a -> b) -> [a] -> [b]
map (Name, FC) -> Name
forall a b. (a, b) -> a
fst (Maybe (Name, FC) -> [(Name, FC)]
forall a. Maybe a -> [a]
maybeToList Maybe (Name, FC)
cn) [Name] -> [Name] -> [Name]
forall a. [a] -> [a] -> [a]
++ (PDecl' PTerm -> [Name]) -> [PDecl' PTerm] -> [Name]
forall (t :: * -> *) a b. Foldable t => (a -> [b]) -> t a -> [b]
concatMap PDecl' PTerm -> [Name]
tldeclared [PDecl' PTerm]
ms)
tldeclared (PImplementation Docstring (Either Err PTerm)
_ [(Name, Docstring (Either Err PTerm))]
_ SyntaxInfo
_ FC
_ [(Name, PTerm)]
_ [Name]
_ Accessibility
_ [FnOpt]
_ Name
_ FC
_ [PTerm]
_ [(Name, PTerm)]
_ PTerm
_ Maybe Name
mn [PDecl' PTerm]
_)
    = case Maybe Name
mn of
           Maybe Name
Nothing -> []
           Just Name
n -> [Name
n]
tldeclared PDecl' PTerm
_                                      = []

defined :: PDecl -> [Name]
defined :: PDecl' PTerm -> [Name]
defined (PFix FC
_ Fixity
_ [String]
_)                              = []
defined (PTy Docstring (Either Err PTerm)
_ [(Name, Docstring (Either Err PTerm))]
_ SyntaxInfo
_ FC
_ [FnOpt]
_ Name
n FC
_ PTerm
t)                     = []
defined (PPostulate Bool
_ Docstring (Either Err PTerm)
_ SyntaxInfo
_ FC
_ FC
_ [FnOpt]
_ Name
n PTerm
t)              = []
defined (PClauses FC
_ [FnOpt]
_ Name
n [PClause' PTerm]
_)                        = [Name
n] -- not a declaration
defined (PCAF FC
_ Name
n PTerm
_)                              = [Name
n]
defined (PData Docstring (Either Err PTerm)
_ [(Name, Docstring (Either Err PTerm))]
_ SyntaxInfo
_ FC
_ DataOpts
_ (PDatadecl Name
n FC
_ PTerm
_ [(Docstring (Either Err PTerm),
  [(Name, Docstring (Either Err PTerm))], Name, FC, PTerm, FC,
  [Name])]
ts))    = Name
n Name -> [Name] -> [Name]
forall a. a -> [a] -> [a]
: ((Docstring (Either Err PTerm),
  [(Name, Docstring (Either Err PTerm))], Name, FC, PTerm, FC,
  [Name])
 -> Name)
-> [(Docstring (Either Err PTerm),
     [(Name, Docstring (Either Err PTerm))], Name, FC, PTerm, FC,
     [Name])]
-> [Name]
forall a b. (a -> b) -> [a] -> [b]
map (Docstring (Either Err PTerm),
 [(Name, Docstring (Either Err PTerm))], Name, FC, PTerm, FC,
 [Name])
-> Name
forall {a} {b} {c} {d} {e} {f} {g}. (a, b, c, d, e, f, g) -> c
fstt [(Docstring (Either Err PTerm),
  [(Name, Docstring (Either Err PTerm))], Name, FC, PTerm, FC,
  [Name])]
ts
   where fstt :: (a, b, c, d, e, f, g) -> c
fstt (a
_, b
_, c
a, d
_, e
_, f
_, g
_) = c
a
defined (PData Docstring (Either Err PTerm)
_ [(Name, Docstring (Either Err PTerm))]
_ SyntaxInfo
_ FC
_ DataOpts
_ (PLaterdecl Name
n FC
_ PTerm
_))      = []
defined (PParams FC
_ [(Name, PTerm)]
_ [PDecl' PTerm]
ds)                          = (PDecl' PTerm -> [Name]) -> [PDecl' PTerm] -> [Name]
forall (t :: * -> *) a b. Foldable t => (a -> [b]) -> t a -> [b]
concatMap PDecl' PTerm -> [Name]
defined [PDecl' PTerm]
ds
defined (POpenInterfaces FC
_ [Name]
_ [PDecl' PTerm]
ds)                  = (PDecl' PTerm -> [Name]) -> [PDecl' PTerm] -> [Name]
forall (t :: * -> *) a b. Foldable t => (a -> [b]) -> t a -> [b]
concatMap PDecl' PTerm -> [Name]
defined [PDecl' PTerm]
ds
defined (PNamespace String
_ FC
_ [PDecl' PTerm]
ds)                       = (PDecl' PTerm -> [Name]) -> [PDecl' PTerm] -> [Name]
forall (t :: * -> *) a b. Foldable t => (a -> [b]) -> t a -> [b]
concatMap PDecl' PTerm -> [Name]
defined [PDecl' PTerm]
ds
defined (PRecord Docstring (Either Err PTerm)
_ SyntaxInfo
_ FC
_ DataOpts
_ Name
n FC
_ [(Name, FC, Plicity, PTerm)]
_ [(Name, Docstring (Either Err PTerm))]
_ [(Maybe (Name, FC), Plicity, PTerm,
  Maybe (Docstring (Either Err PTerm)))]
_ Maybe (Name, FC)
cn Docstring (Either Err PTerm)
_ SyntaxInfo
_)        = Name
n Name -> [Name] -> [Name]
forall a. a -> [a] -> [a]
: ((Name, FC) -> Name) -> [(Name, FC)] -> [Name]
forall a b. (a -> b) -> [a] -> [b]
map (Name, FC) -> Name
forall a b. (a, b) -> a
fst (Maybe (Name, FC) -> [(Name, FC)]
forall a. Maybe a -> [a]
maybeToList Maybe (Name, FC)
cn)
defined (PInterface Docstring (Either Err PTerm)
_ SyntaxInfo
_ FC
_ [(Name, PTerm)]
_ Name
n FC
_ [(Name, FC, PTerm)]
_ [(Name, Docstring (Either Err PTerm))]
_ [(Name, FC)]
_ [PDecl' PTerm]
ms Maybe (Name, FC)
cn Docstring (Either Err PTerm)
_)        = Name
n Name -> [Name] -> [Name]
forall a. a -> [a] -> [a]
: (((Name, FC) -> Name) -> [(Name, FC)] -> [Name]
forall a b. (a -> b) -> [a] -> [b]
map (Name, FC) -> Name
forall a b. (a, b) -> a
fst (Maybe (Name, FC) -> [(Name, FC)]
forall a. Maybe a -> [a]
maybeToList Maybe (Name, FC)
cn) [Name] -> [Name] -> [Name]
forall a. [a] -> [a] -> [a]
++ (PDecl' PTerm -> [Name]) -> [PDecl' PTerm] -> [Name]
forall (t :: * -> *) a b. Foldable t => (a -> [b]) -> t a -> [b]
concatMap PDecl' PTerm -> [Name]
defined [PDecl' PTerm]
ms)
defined (PImplementation Docstring (Either Err PTerm)
_ [(Name, Docstring (Either Err PTerm))]
_ SyntaxInfo
_ FC
_ [(Name, PTerm)]
_ [Name]
_ Accessibility
_ [FnOpt]
_ Name
_ FC
_ [PTerm]
_ [(Name, PTerm)]
_ PTerm
_ Maybe Name
mn [PDecl' PTerm]
_)
    = case Maybe Name
mn of
           Maybe Name
Nothing -> []
           Just Name
n -> [Name
n]
defined (PDSL Name
n DSL
_)                                = [Name
n]
defined (PSyntax FC
_ Syntax
_)                             = []
defined (PMutual FC
_ [PDecl' PTerm]
ds)                            = (PDecl' PTerm -> [Name]) -> [PDecl' PTerm] -> [Name]
forall (t :: * -> *) a b. Foldable t => (a -> [b]) -> t a -> [b]
concatMap PDecl' PTerm -> [Name]
defined [PDecl' PTerm]
ds
defined (PDirective Directive
_)                            = []
defined PDecl' PTerm
_                                         = []

updateN :: [(Name, Name)] -> Name -> Name
updateN :: [(Name, Name)] -> Name -> Name
updateN [(Name, Name)]
ns Name
n | Just Name
n' <- Name -> [(Name, Name)] -> Maybe Name
forall a b. Eq a => a -> [(a, b)] -> Maybe b
lookup Name
n [(Name, Name)]
ns = Name
n'
updateN [(Name, Name)]
_  Name
n = Name
n

updateNs :: [(Name, Name)] -> PTerm -> PTerm
updateNs :: [(Name, Name)] -> PTerm -> PTerm
updateNs [] PTerm
t = PTerm
t
updateNs [(Name, Name)]
ns PTerm
t = (PTerm -> PTerm) -> PTerm -> PTerm
mapPT PTerm -> PTerm
updateRef PTerm
t
  where updateRef :: PTerm -> PTerm
updateRef (PRef FC
fc [FC]
fcs Name
f) = FC -> [FC] -> Name -> PTerm
PRef FC
fc [FC]
fcs ([(Name, Name)] -> Name -> Name
updateN [(Name, Name)]
ns Name
f)
        updateRef PTerm
t = PTerm
t

data PunInfo = IsType
             | IsTerm
             | TypeOrTerm
             deriving (PunInfo -> PunInfo -> Bool
(PunInfo -> PunInfo -> Bool)
-> (PunInfo -> PunInfo -> Bool) -> Eq PunInfo
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: PunInfo -> PunInfo -> Bool
== :: PunInfo -> PunInfo -> Bool
$c/= :: PunInfo -> PunInfo -> Bool
/= :: PunInfo -> PunInfo -> Bool
Eq, Int -> PunInfo -> ShowS
[PunInfo] -> ShowS
PunInfo -> String
(Int -> PunInfo -> ShowS)
-> (PunInfo -> String) -> ([PunInfo] -> ShowS) -> Show PunInfo
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> PunInfo -> ShowS
showsPrec :: Int -> PunInfo -> ShowS
$cshow :: PunInfo -> String
show :: PunInfo -> String
$cshowList :: [PunInfo] -> ShowS
showList :: [PunInfo] -> ShowS
Show, Eq PunInfo
Eq PunInfo =>
(PunInfo -> PunInfo -> Ordering)
-> (PunInfo -> PunInfo -> Bool)
-> (PunInfo -> PunInfo -> Bool)
-> (PunInfo -> PunInfo -> Bool)
-> (PunInfo -> PunInfo -> Bool)
-> (PunInfo -> PunInfo -> PunInfo)
-> (PunInfo -> PunInfo -> PunInfo)
-> Ord PunInfo
PunInfo -> PunInfo -> Bool
PunInfo -> PunInfo -> Ordering
PunInfo -> PunInfo -> PunInfo
forall a.
Eq a =>
(a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
$ccompare :: PunInfo -> PunInfo -> Ordering
compare :: PunInfo -> PunInfo -> Ordering
$c< :: PunInfo -> PunInfo -> Bool
< :: PunInfo -> PunInfo -> Bool
$c<= :: PunInfo -> PunInfo -> Bool
<= :: PunInfo -> PunInfo -> Bool
$c> :: PunInfo -> PunInfo -> Bool
> :: PunInfo -> PunInfo -> Bool
$c>= :: PunInfo -> PunInfo -> Bool
>= :: PunInfo -> PunInfo -> Bool
$cmax :: PunInfo -> PunInfo -> PunInfo
max :: PunInfo -> PunInfo -> PunInfo
$cmin :: PunInfo -> PunInfo -> PunInfo
min :: PunInfo -> PunInfo -> PunInfo
Ord, Typeable PunInfo
Typeable PunInfo =>
(forall (c :: * -> *).
 (forall d b. Data d => c (d -> b) -> d -> c b)
 -> (forall g. g -> c g) -> PunInfo -> c PunInfo)
-> (forall (c :: * -> *).
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c PunInfo)
-> (PunInfo -> Constr)
-> (PunInfo -> DataType)
-> (forall (t :: * -> *) (c :: * -> *).
    Typeable t =>
    (forall d. Data d => c (t d)) -> Maybe (c PunInfo))
-> (forall (t :: * -> * -> *) (c :: * -> *).
    Typeable t =>
    (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c PunInfo))
-> ((forall b. Data b => b -> b) -> PunInfo -> PunInfo)
-> (forall r r'.
    (r -> r' -> r)
    -> r -> (forall d. Data d => d -> r') -> PunInfo -> r)
-> (forall r r'.
    (r' -> r -> r)
    -> r -> (forall d. Data d => d -> r') -> PunInfo -> r)
-> (forall u. (forall d. Data d => d -> u) -> PunInfo -> [u])
-> (forall u. Int -> (forall d. Data d => d -> u) -> PunInfo -> u)
-> (forall (m :: * -> *).
    Monad m =>
    (forall d. Data d => d -> m d) -> PunInfo -> m PunInfo)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> PunInfo -> m PunInfo)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> PunInfo -> m PunInfo)
-> Data PunInfo
PunInfo -> Constr
PunInfo -> DataType
(forall b. Data b => b -> b) -> PunInfo -> PunInfo
forall a.
Typeable a =>
(forall (c :: * -> *).
 (forall d b. Data d => c (d -> b) -> d -> c b)
 -> (forall g. g -> c g) -> a -> c a)
-> (forall (c :: * -> *).
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c a)
-> (a -> Constr)
-> (a -> DataType)
-> (forall (t :: * -> *) (c :: * -> *).
    Typeable t =>
    (forall d. Data d => c (t d)) -> Maybe (c a))
-> (forall (t :: * -> * -> *) (c :: * -> *).
    Typeable t =>
    (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c a))
-> ((forall b. Data b => b -> b) -> a -> a)
-> (forall r r'.
    (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall r r'.
    (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall u. (forall d. Data d => d -> u) -> a -> [u])
-> (forall u. Int -> (forall d. Data d => d -> u) -> a -> u)
-> (forall (m :: * -> *).
    Monad m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> Data a
forall u. Int -> (forall d. Data d => d -> u) -> PunInfo -> u
forall u. (forall d. Data d => d -> u) -> PunInfo -> [u]
forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> PunInfo -> r
forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> PunInfo -> r
forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> PunInfo -> m PunInfo
forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> PunInfo -> m PunInfo
forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c PunInfo
forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> PunInfo -> c PunInfo
forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c PunInfo)
forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c PunInfo)
$cgfoldl :: forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> PunInfo -> c PunInfo
gfoldl :: forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> PunInfo -> c PunInfo
$cgunfold :: forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c PunInfo
gunfold :: forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c PunInfo
$ctoConstr :: PunInfo -> Constr
toConstr :: PunInfo -> Constr
$cdataTypeOf :: PunInfo -> DataType
dataTypeOf :: PunInfo -> DataType
$cdataCast1 :: forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c PunInfo)
dataCast1 :: forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c PunInfo)
$cdataCast2 :: forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c PunInfo)
dataCast2 :: forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c PunInfo)
$cgmapT :: (forall b. Data b => b -> b) -> PunInfo -> PunInfo
gmapT :: (forall b. Data b => b -> b) -> PunInfo -> PunInfo
$cgmapQl :: forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> PunInfo -> r
gmapQl :: forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> PunInfo -> r
$cgmapQr :: forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> PunInfo -> r
gmapQr :: forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> PunInfo -> r
$cgmapQ :: forall u. (forall d. Data d => d -> u) -> PunInfo -> [u]
gmapQ :: forall u. (forall d. Data d => d -> u) -> PunInfo -> [u]
$cgmapQi :: forall u. Int -> (forall d. Data d => d -> u) -> PunInfo -> u
gmapQi :: forall u. Int -> (forall d. Data d => d -> u) -> PunInfo -> u
$cgmapM :: forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> PunInfo -> m PunInfo
gmapM :: forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> PunInfo -> m PunInfo
$cgmapMp :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> PunInfo -> m PunInfo
gmapMp :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> PunInfo -> m PunInfo
$cgmapMo :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> PunInfo -> m PunInfo
gmapMo :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> PunInfo -> m PunInfo
Data, Typeable, (forall x. PunInfo -> Rep PunInfo x)
-> (forall x. Rep PunInfo x -> PunInfo) -> Generic PunInfo
forall x. Rep PunInfo x -> PunInfo
forall x. PunInfo -> Rep PunInfo x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cfrom :: forall x. PunInfo -> Rep PunInfo x
from :: forall x. PunInfo -> Rep PunInfo x
$cto :: forall x. Rep PunInfo x -> PunInfo
to :: forall x. Rep PunInfo x -> PunInfo
Generic)

-- | High level language terms
data PTerm = PQuote Raw         -- ^ Inclusion of a core term into the
                                -- high-level language
           | PRef FC [FC] Name
             -- ^ A reference to a variable. The FC is its precise
             -- source location for highlighting. The list of FCs is a
             -- collection of additional highlighting locations.
           | PInferRef FC [FC] Name              -- ^ A name to be defined later
           | PPatvar FC Name                     -- ^ A pattern variable
           | PLam FC Name FC PTerm PTerm         -- ^ A lambda abstraction. Second FC is name span.
           | PPi  Plicity Name FC PTerm PTerm    -- ^ (n : t1) -> t2, where the FC is for the precise location of the variable
           | PLet FC RigCount Name FC PTerm PTerm PTerm   -- ^ A let binding (second FC is precise name location)
           | PTyped PTerm PTerm                  -- ^ Term with explicit type
           | PApp FC PTerm [PArg]                -- ^ e.g. IO (), List Char, length x
           | PWithApp FC PTerm PTerm             -- ^ Application plus a 'with' argument
           | PAppImpl PTerm [ImplicitInfo]       -- ^ Implicit argument application (introduced during elaboration only)
           | PAppBind FC PTerm [PArg]            -- ^ implicitly bound application
           | PMatchApp FC Name                   -- ^ Make an application by type matching
           | PIfThenElse FC PTerm PTerm PTerm    -- ^ Conditional expressions - elaborated to an overloading of ifThenElse
           | PCase FC PTerm [(PTerm, PTerm)]     -- ^ A case expression. Args are source location, scrutinee, and a list of pattern/RHS pairs
           | PTrue FC PunInfo                    -- ^ Unit type..?
           | PResolveTC FC                       -- ^ Solve this dictionary by interface resolution
           | PRewrite FC (Maybe Name) PTerm PTerm (Maybe PTerm)
             -- ^ "rewrite" syntax, with optional rewriting function and
             -- optional result type
           | PPair FC [FC] PunInfo PTerm PTerm
             -- ^ A pair (a, b) and whether it's a product type or a
             -- pair (solved by elaboration). The list of FCs is its
             -- punctuation.
           | PDPair FC [FC] PunInfo PTerm PTerm PTerm
             -- ^ A dependent pair (tm : a ** b) and whether it's a
             -- sigma type or a pair that inhabits one (solved by
             -- elaboration). The [FC] is its punctuation.
           | PAs FC Name PTerm                            -- ^ @-pattern, valid LHS only
           | PAlternative [(Name, Name)] PAltType [PTerm] -- ^ (| A, B, C|). Includes unapplied unique name mappings for mkUniqueNames.
           | PHidden PTerm                                -- ^ Irrelevant or hidden pattern
           | PType FC                                     -- ^ 'Type' type
           | PUniverse FC Universe                        -- ^ Some universe
           | PGoal FC PTerm Name PTerm                    -- ^ quoteGoal, used for %reflection functions
           | PConstant FC Const                           -- ^ Builtin types
           | Placeholder                                  -- ^ Underscore
           | PDoBlock [PDo]                               -- ^ Do notation
           | PIdiom FC PTerm                              -- ^ Idiom brackets
           | PMetavar FC Name                             -- ^ A metavariable, ?name, and its precise location
           | PProof [PTactic]                             -- ^ Proof script
           | PTactics [PTactic]                           -- ^ As PProof, but no auto solving
           | PElabError Err                               -- ^ Error to report on elaboration
           | PImpossible                                  -- ^ Special case for declaring when an LHS can't typecheck
           | PCoerced PTerm                               -- ^ To mark a coerced argument, so as not to coerce twice
           | PDisamb [[T.Text]] PTerm                     -- ^ Preferences for explicit namespaces
           | PUnifyLog PTerm                              -- ^ dump a trace of unifications when building term
           | PNoImplicits PTerm                           -- ^ never run implicit converions on the term
           | PQuasiquote PTerm (Maybe PTerm)              -- ^ `(Term [: Term])
           | PUnquote PTerm                               -- ^ ~Term
           | PQuoteName Name Bool FC
             -- ^ `{n} where the FC is the precise highlighting for
             -- the name in particular. If the Bool is False, then
             -- it's `{{n}} and the name won't be resolved.
           | PRunElab FC PTerm [String]
             -- ^ %runElab tm - New-style proof script. Args are
             -- location, script, enclosing namespace.
           | PConstSugar FC PTerm
             -- ^ A desugared constant. The FC is a precise source
             -- location that will be used to highlight it later.
       deriving (PTerm -> PTerm -> Bool
(PTerm -> PTerm -> Bool) -> (PTerm -> PTerm -> Bool) -> Eq PTerm
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: PTerm -> PTerm -> Bool
== :: PTerm -> PTerm -> Bool
$c/= :: PTerm -> PTerm -> Bool
/= :: PTerm -> PTerm -> Bool
Eq, Eq PTerm
Eq PTerm =>
(PTerm -> PTerm -> Ordering)
-> (PTerm -> PTerm -> Bool)
-> (PTerm -> PTerm -> Bool)
-> (PTerm -> PTerm -> Bool)
-> (PTerm -> PTerm -> Bool)
-> (PTerm -> PTerm -> PTerm)
-> (PTerm -> PTerm -> PTerm)
-> Ord PTerm
PTerm -> PTerm -> Bool
PTerm -> PTerm -> Ordering
PTerm -> PTerm -> PTerm
forall a.
Eq a =>
(a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
$ccompare :: PTerm -> PTerm -> Ordering
compare :: PTerm -> PTerm -> Ordering
$c< :: PTerm -> PTerm -> Bool
< :: PTerm -> PTerm -> Bool
$c<= :: PTerm -> PTerm -> Bool
<= :: PTerm -> PTerm -> Bool
$c> :: PTerm -> PTerm -> Bool
> :: PTerm -> PTerm -> Bool
$c>= :: PTerm -> PTerm -> Bool
>= :: PTerm -> PTerm -> Bool
$cmax :: PTerm -> PTerm -> PTerm
max :: PTerm -> PTerm -> PTerm
$cmin :: PTerm -> PTerm -> PTerm
min :: PTerm -> PTerm -> PTerm
Ord, Typeable PTerm
Typeable PTerm =>
(forall (c :: * -> *).
 (forall d b. Data d => c (d -> b) -> d -> c b)
 -> (forall g. g -> c g) -> PTerm -> c PTerm)
-> (forall (c :: * -> *).
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c PTerm)
-> (PTerm -> Constr)
-> (PTerm -> DataType)
-> (forall (t :: * -> *) (c :: * -> *).
    Typeable t =>
    (forall d. Data d => c (t d)) -> Maybe (c PTerm))
-> (forall (t :: * -> * -> *) (c :: * -> *).
    Typeable t =>
    (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c PTerm))
-> ((forall b. Data b => b -> b) -> PTerm -> PTerm)
-> (forall r r'.
    (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> PTerm -> r)
-> (forall r r'.
    (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> PTerm -> r)
-> (forall u. (forall d. Data d => d -> u) -> PTerm -> [u])
-> (forall u. Int -> (forall d. Data d => d -> u) -> PTerm -> u)
-> (forall (m :: * -> *).
    Monad m =>
    (forall d. Data d => d -> m d) -> PTerm -> m PTerm)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> PTerm -> m PTerm)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> PTerm -> m PTerm)
-> Data PTerm
PTerm -> Constr
PTerm -> DataType
(forall b. Data b => b -> b) -> PTerm -> PTerm
forall a.
Typeable a =>
(forall (c :: * -> *).
 (forall d b. Data d => c (d -> b) -> d -> c b)
 -> (forall g. g -> c g) -> a -> c a)
-> (forall (c :: * -> *).
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c a)
-> (a -> Constr)
-> (a -> DataType)
-> (forall (t :: * -> *) (c :: * -> *).
    Typeable t =>
    (forall d. Data d => c (t d)) -> Maybe (c a))
-> (forall (t :: * -> * -> *) (c :: * -> *).
    Typeable t =>
    (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c a))
-> ((forall b. Data b => b -> b) -> a -> a)
-> (forall r r'.
    (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall r r'.
    (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall u. (forall d. Data d => d -> u) -> a -> [u])
-> (forall u. Int -> (forall d. Data d => d -> u) -> a -> u)
-> (forall (m :: * -> *).
    Monad m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> Data a
forall u. Int -> (forall d. Data d => d -> u) -> PTerm -> u
forall u. (forall d. Data d => d -> u) -> PTerm -> [u]
forall r r'.
(r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> PTerm -> r
forall r r'.
(r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> PTerm -> r
forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> PTerm -> m PTerm
forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> PTerm -> m PTerm
forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c PTerm
forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> PTerm -> c PTerm
forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c PTerm)
forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c PTerm)
$cgfoldl :: forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> PTerm -> c PTerm
gfoldl :: forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> PTerm -> c PTerm
$cgunfold :: forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c PTerm
gunfold :: forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c PTerm
$ctoConstr :: PTerm -> Constr
toConstr :: PTerm -> Constr
$cdataTypeOf :: PTerm -> DataType
dataTypeOf :: PTerm -> DataType
$cdataCast1 :: forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c PTerm)
dataCast1 :: forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c PTerm)
$cdataCast2 :: forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c PTerm)
dataCast2 :: forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c PTerm)
$cgmapT :: (forall b. Data b => b -> b) -> PTerm -> PTerm
gmapT :: (forall b. Data b => b -> b) -> PTerm -> PTerm
$cgmapQl :: forall r r'.
(r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> PTerm -> r
gmapQl :: forall r r'.
(r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> PTerm -> r
$cgmapQr :: forall r r'.
(r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> PTerm -> r
gmapQr :: forall r r'.
(r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> PTerm -> r
$cgmapQ :: forall u. (forall d. Data d => d -> u) -> PTerm -> [u]
gmapQ :: forall u. (forall d. Data d => d -> u) -> PTerm -> [u]
$cgmapQi :: forall u. Int -> (forall d. Data d => d -> u) -> PTerm -> u
gmapQi :: forall u. Int -> (forall d. Data d => d -> u) -> PTerm -> u
$cgmapM :: forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> PTerm -> m PTerm
gmapM :: forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> PTerm -> m PTerm
$cgmapMp :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> PTerm -> m PTerm
gmapMp :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> PTerm -> m PTerm
$cgmapMo :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> PTerm -> m PTerm
gmapMo :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> PTerm -> m PTerm
Data, Typeable, (forall x. PTerm -> Rep PTerm x)
-> (forall x. Rep PTerm x -> PTerm) -> Generic PTerm
forall x. Rep PTerm x -> PTerm
forall x. PTerm -> Rep PTerm x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cfrom :: forall x. PTerm -> Rep PTerm x
from :: forall x. PTerm -> Rep PTerm x
$cto :: forall x. Rep PTerm x -> PTerm
to :: forall x. Rep PTerm x -> PTerm
Generic)

data PAltType = ExactlyOne Bool -- ^ flag sets whether delay is allowed
              | FirstSuccess
              | TryImplicit
       deriving (PAltType -> PAltType -> Bool
(PAltType -> PAltType -> Bool)
-> (PAltType -> PAltType -> Bool) -> Eq PAltType
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: PAltType -> PAltType -> Bool
== :: PAltType -> PAltType -> Bool
$c/= :: PAltType -> PAltType -> Bool
/= :: PAltType -> PAltType -> Bool
Eq, Eq PAltType
Eq PAltType =>
(PAltType -> PAltType -> Ordering)
-> (PAltType -> PAltType -> Bool)
-> (PAltType -> PAltType -> Bool)
-> (PAltType -> PAltType -> Bool)
-> (PAltType -> PAltType -> Bool)
-> (PAltType -> PAltType -> PAltType)
-> (PAltType -> PAltType -> PAltType)
-> Ord PAltType
PAltType -> PAltType -> Bool
PAltType -> PAltType -> Ordering
PAltType -> PAltType -> PAltType
forall a.
Eq a =>
(a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
$ccompare :: PAltType -> PAltType -> Ordering
compare :: PAltType -> PAltType -> Ordering
$c< :: PAltType -> PAltType -> Bool
< :: PAltType -> PAltType -> Bool
$c<= :: PAltType -> PAltType -> Bool
<= :: PAltType -> PAltType -> Bool
$c> :: PAltType -> PAltType -> Bool
> :: PAltType -> PAltType -> Bool
$c>= :: PAltType -> PAltType -> Bool
>= :: PAltType -> PAltType -> Bool
$cmax :: PAltType -> PAltType -> PAltType
max :: PAltType -> PAltType -> PAltType
$cmin :: PAltType -> PAltType -> PAltType
min :: PAltType -> PAltType -> PAltType
Ord, Typeable PAltType
Typeable PAltType =>
(forall (c :: * -> *).
 (forall d b. Data d => c (d -> b) -> d -> c b)
 -> (forall g. g -> c g) -> PAltType -> c PAltType)
-> (forall (c :: * -> *).
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c PAltType)
-> (PAltType -> Constr)
-> (PAltType -> DataType)
-> (forall (t :: * -> *) (c :: * -> *).
    Typeable t =>
    (forall d. Data d => c (t d)) -> Maybe (c PAltType))
-> (forall (t :: * -> * -> *) (c :: * -> *).
    Typeable t =>
    (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c PAltType))
-> ((forall b. Data b => b -> b) -> PAltType -> PAltType)
-> (forall r r'.
    (r -> r' -> r)
    -> r -> (forall d. Data d => d -> r') -> PAltType -> r)
-> (forall r r'.
    (r' -> r -> r)
    -> r -> (forall d. Data d => d -> r') -> PAltType -> r)
-> (forall u. (forall d. Data d => d -> u) -> PAltType -> [u])
-> (forall u. Int -> (forall d. Data d => d -> u) -> PAltType -> u)
-> (forall (m :: * -> *).
    Monad m =>
    (forall d. Data d => d -> m d) -> PAltType -> m PAltType)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> PAltType -> m PAltType)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> PAltType -> m PAltType)
-> Data PAltType
PAltType -> Constr
PAltType -> DataType
(forall b. Data b => b -> b) -> PAltType -> PAltType
forall a.
Typeable a =>
(forall (c :: * -> *).
 (forall d b. Data d => c (d -> b) -> d -> c b)
 -> (forall g. g -> c g) -> a -> c a)
-> (forall (c :: * -> *).
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c a)
-> (a -> Constr)
-> (a -> DataType)
-> (forall (t :: * -> *) (c :: * -> *).
    Typeable t =>
    (forall d. Data d => c (t d)) -> Maybe (c a))
-> (forall (t :: * -> * -> *) (c :: * -> *).
    Typeable t =>
    (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c a))
-> ((forall b. Data b => b -> b) -> a -> a)
-> (forall r r'.
    (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall r r'.
    (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall u. (forall d. Data d => d -> u) -> a -> [u])
-> (forall u. Int -> (forall d. Data d => d -> u) -> a -> u)
-> (forall (m :: * -> *).
    Monad m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> Data a
forall u. Int -> (forall d. Data d => d -> u) -> PAltType -> u
forall u. (forall d. Data d => d -> u) -> PAltType -> [u]
forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> PAltType -> r
forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> PAltType -> r
forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> PAltType -> m PAltType
forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> PAltType -> m PAltType
forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c PAltType
forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> PAltType -> c PAltType
forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c PAltType)
forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c PAltType)
$cgfoldl :: forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> PAltType -> c PAltType
gfoldl :: forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> PAltType -> c PAltType
$cgunfold :: forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c PAltType
gunfold :: forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c PAltType
$ctoConstr :: PAltType -> Constr
toConstr :: PAltType -> Constr
$cdataTypeOf :: PAltType -> DataType
dataTypeOf :: PAltType -> DataType
$cdataCast1 :: forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c PAltType)
dataCast1 :: forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c PAltType)
$cdataCast2 :: forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c PAltType)
dataCast2 :: forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c PAltType)
$cgmapT :: (forall b. Data b => b -> b) -> PAltType -> PAltType
gmapT :: (forall b. Data b => b -> b) -> PAltType -> PAltType
$cgmapQl :: forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> PAltType -> r
gmapQl :: forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> PAltType -> r
$cgmapQr :: forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> PAltType -> r
gmapQr :: forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> PAltType -> r
$cgmapQ :: forall u. (forall d. Data d => d -> u) -> PAltType -> [u]
gmapQ :: forall u. (forall d. Data d => d -> u) -> PAltType -> [u]
$cgmapQi :: forall u. Int -> (forall d. Data d => d -> u) -> PAltType -> u
gmapQi :: forall u. Int -> (forall d. Data d => d -> u) -> PAltType -> u
$cgmapM :: forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> PAltType -> m PAltType
gmapM :: forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> PAltType -> m PAltType
$cgmapMp :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> PAltType -> m PAltType
gmapMp :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> PAltType -> m PAltType
$cgmapMo :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> PAltType -> m PAltType
gmapMo :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> PAltType -> m PAltType
Data, (forall x. PAltType -> Rep PAltType x)
-> (forall x. Rep PAltType x -> PAltType) -> Generic PAltType
forall x. Rep PAltType x -> PAltType
forall x. PAltType -> Rep PAltType x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cfrom :: forall x. PAltType -> Rep PAltType x
from :: forall x. PAltType -> Rep PAltType x
$cto :: forall x. Rep PAltType x -> PAltType
to :: forall x. Rep PAltType x -> PAltType
Generic, Typeable)

-- | Transform the FCs in a PTerm. The first function transforms the
-- general-purpose FCs, and the second transforms those that are used
-- for semantic source highlighting, so they can be treated specially.
mapPTermFC :: (FC -> FC) -> (FC -> FC) -> PTerm -> PTerm
mapPTermFC :: (FC -> FC) -> (FC -> FC) -> PTerm -> PTerm
mapPTermFC FC -> FC
f FC -> FC
g (PQuote Raw
q)                     = Raw -> PTerm
PQuote Raw
q
mapPTermFC FC -> FC
f FC -> FC
g (PRef FC
fc [FC]
fcs Name
n)                = FC -> [FC] -> Name -> PTerm
PRef (FC -> FC
g FC
fc) ((FC -> FC) -> [FC] -> [FC]
forall a b. (a -> b) -> [a] -> [b]
map FC -> FC
g [FC]
fcs) Name
n
mapPTermFC FC -> FC
f FC -> FC
g (PInferRef FC
fc [FC]
fcs Name
n)           = FC -> [FC] -> Name -> PTerm
PInferRef (FC -> FC
g FC
fc) ((FC -> FC) -> [FC] -> [FC]
forall a b. (a -> b) -> [a] -> [b]
map FC -> FC
g [FC]
fcs) Name
n
mapPTermFC FC -> FC
f FC -> FC
g (PPatvar FC
fc Name
n)                 = FC -> Name -> PTerm
PPatvar (FC -> FC
g FC
fc) Name
n
mapPTermFC FC -> FC
f FC -> FC
g (PLam FC
fc Name
n FC
fc' PTerm
t1 PTerm
t2)          = FC -> Name -> FC -> PTerm -> PTerm -> PTerm
PLam (FC -> FC
f FC
fc) Name
n (FC -> FC
g FC
fc') ((FC -> FC) -> (FC -> FC) -> PTerm -> PTerm
mapPTermFC FC -> FC
f FC -> FC
g PTerm
t1) ((FC -> FC) -> (FC -> FC) -> PTerm -> PTerm
mapPTermFC FC -> FC
f FC -> FC
g PTerm
t2)
mapPTermFC FC -> FC
f FC -> FC
g (PPi Plicity
plic Name
n FC
fc PTerm
t1 PTerm
t2)          = Plicity -> Name -> FC -> PTerm -> PTerm -> PTerm
PPi Plicity
plic Name
n (FC -> FC
g FC
fc) ((FC -> FC) -> (FC -> FC) -> PTerm -> PTerm
mapPTermFC FC -> FC
f FC -> FC
g PTerm
t1) ((FC -> FC) -> (FC -> FC) -> PTerm -> PTerm
mapPTermFC FC -> FC
f FC -> FC
g PTerm
t2)
mapPTermFC FC -> FC
f FC -> FC
g (PLet FC
fc RigCount
rc Name
n FC
fc' PTerm
t1 PTerm
t2 PTerm
t3)    = FC -> RigCount -> Name -> FC -> PTerm -> PTerm -> PTerm -> PTerm
PLet (FC -> FC
f FC
fc) RigCount
rc Name
n (FC -> FC
g FC
fc') ((FC -> FC) -> (FC -> FC) -> PTerm -> PTerm
mapPTermFC FC -> FC
f FC -> FC
g PTerm
t1) ((FC -> FC) -> (FC -> FC) -> PTerm -> PTerm
mapPTermFC FC -> FC
f FC -> FC
g PTerm
t2) ((FC -> FC) -> (FC -> FC) -> PTerm -> PTerm
mapPTermFC FC -> FC
f FC -> FC
g PTerm
t3)
mapPTermFC FC -> FC
f FC -> FC
g (PTyped PTerm
t1 PTerm
t2)                 = PTerm -> PTerm -> PTerm
PTyped ((FC -> FC) -> (FC -> FC) -> PTerm -> PTerm
mapPTermFC FC -> FC
f FC -> FC
g PTerm
t1) ((FC -> FC) -> (FC -> FC) -> PTerm -> PTerm
mapPTermFC FC -> FC
f FC -> FC
g PTerm
t2)
mapPTermFC FC -> FC
f FC -> FC
g (PApp FC
fc PTerm
t [PArg]
args)               = FC -> PTerm -> [PArg] -> PTerm
PApp (FC -> FC
f FC
fc) ((FC -> FC) -> (FC -> FC) -> PTerm -> PTerm
mapPTermFC FC -> FC
f FC -> FC
g PTerm
t) ((PArg -> PArg) -> [PArg] -> [PArg]
forall a b. (a -> b) -> [a] -> [b]
map ((PTerm -> PTerm) -> PArg -> PArg
forall a b. (a -> b) -> PArg' a -> PArg' b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap ((FC -> FC) -> (FC -> FC) -> PTerm -> PTerm
mapPTermFC FC -> FC
f FC -> FC
g)) [PArg]
args)
mapPTermFC FC -> FC
f FC -> FC
g (PWithApp FC
fc PTerm
t PTerm
arg)            = FC -> PTerm -> PTerm -> PTerm
PWithApp (FC -> FC
f FC
fc) ((FC -> FC) -> (FC -> FC) -> PTerm -> PTerm
mapPTermFC FC -> FC
f FC -> FC
g PTerm
t) ((FC -> FC) -> (FC -> FC) -> PTerm -> PTerm
mapPTermFC FC -> FC
f FC -> FC
g PTerm
arg)
mapPTermFC FC -> FC
f FC -> FC
g (PAppImpl PTerm
t1 [ImplicitInfo]
impls)            = PTerm -> [ImplicitInfo] -> PTerm
PAppImpl ((FC -> FC) -> (FC -> FC) -> PTerm -> PTerm
mapPTermFC FC -> FC
f FC -> FC
g PTerm
t1) [ImplicitInfo]
impls
mapPTermFC FC -> FC
f FC -> FC
g (PAppBind FC
fc PTerm
t [PArg]
args)           = FC -> PTerm -> [PArg] -> PTerm
PAppBind (FC -> FC
f FC
fc) ((FC -> FC) -> (FC -> FC) -> PTerm -> PTerm
mapPTermFC FC -> FC
f FC -> FC
g PTerm
t) ((PArg -> PArg) -> [PArg] -> [PArg]
forall a b. (a -> b) -> [a] -> [b]
map ((PTerm -> PTerm) -> PArg -> PArg
forall a b. (a -> b) -> PArg' a -> PArg' b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap ((FC -> FC) -> (FC -> FC) -> PTerm -> PTerm
mapPTermFC FC -> FC
f FC -> FC
g)) [PArg]
args)
mapPTermFC FC -> FC
f FC -> FC
g (PMatchApp FC
fc Name
n)               = FC -> Name -> PTerm
PMatchApp (FC -> FC
f FC
fc) Name
n
mapPTermFC FC -> FC
f FC -> FC
g (PIfThenElse FC
fc PTerm
t1 PTerm
t2 PTerm
t3)      = FC -> PTerm -> PTerm -> PTerm -> PTerm
PIfThenElse (FC -> FC
f FC
fc) ((FC -> FC) -> (FC -> FC) -> PTerm -> PTerm
mapPTermFC FC -> FC
f FC -> FC
g PTerm
t1) ((FC -> FC) -> (FC -> FC) -> PTerm -> PTerm
mapPTermFC FC -> FC
f FC -> FC
g PTerm
t2) ((FC -> FC) -> (FC -> FC) -> PTerm -> PTerm
mapPTermFC FC -> FC
f FC -> FC
g PTerm
t3)
mapPTermFC FC -> FC
f FC -> FC
g (PCase FC
fc PTerm
t [(PTerm, PTerm)]
cases)             = FC -> PTerm -> [(PTerm, PTerm)] -> PTerm
PCase (FC -> FC
f FC
fc) ((FC -> FC) -> (FC -> FC) -> PTerm -> PTerm
mapPTermFC FC -> FC
f FC -> FC
g PTerm
t) (((PTerm, PTerm) -> (PTerm, PTerm))
-> [(PTerm, PTerm)] -> [(PTerm, PTerm)]
forall a b. (a -> b) -> [a] -> [b]
map (\(PTerm
l,PTerm
r) -> ((FC -> FC) -> (FC -> FC) -> PTerm -> PTerm
mapPTermFC FC -> FC
f FC -> FC
g PTerm
l, (FC -> FC) -> (FC -> FC) -> PTerm -> PTerm
mapPTermFC FC -> FC
f FC -> FC
g PTerm
r)) [(PTerm, PTerm)]
cases)
mapPTermFC FC -> FC
f FC -> FC
g (PTrue FC
fc PunInfo
info)                = FC -> PunInfo -> PTerm
PTrue (FC -> FC
f FC
fc) PunInfo
info
mapPTermFC FC -> FC
f FC -> FC
g (PResolveTC FC
fc)                = FC -> PTerm
PResolveTC (FC -> FC
f FC
fc)
mapPTermFC FC -> FC
f FC -> FC
g (PRewrite FC
fc Maybe Name
by PTerm
t1 PTerm
t2 Maybe PTerm
t3)      = FC -> Maybe Name -> PTerm -> PTerm -> Maybe PTerm -> PTerm
PRewrite (FC -> FC
f FC
fc) Maybe Name
by ((FC -> FC) -> (FC -> FC) -> PTerm -> PTerm
mapPTermFC FC -> FC
f FC -> FC
g PTerm
t1) ((FC -> FC) -> (FC -> FC) -> PTerm -> PTerm
mapPTermFC FC -> FC
f FC -> FC
g PTerm
t2) ((PTerm -> PTerm) -> Maybe PTerm -> Maybe PTerm
forall a b. (a -> b) -> Maybe a -> Maybe b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap ((FC -> FC) -> (FC -> FC) -> PTerm -> PTerm
mapPTermFC FC -> FC
f FC -> FC
g) Maybe PTerm
t3)
mapPTermFC FC -> FC
f FC -> FC
g (PPair FC
fc [FC]
hls PunInfo
info PTerm
t1 PTerm
t2)      = FC -> [FC] -> PunInfo -> PTerm -> PTerm -> PTerm
PPair (FC -> FC
f FC
fc) ((FC -> FC) -> [FC] -> [FC]
forall a b. (a -> b) -> [a] -> [b]
map FC -> FC
g [FC]
hls) PunInfo
info ((FC -> FC) -> (FC -> FC) -> PTerm -> PTerm
mapPTermFC FC -> FC
f FC -> FC
g PTerm
t1) ((FC -> FC) -> (FC -> FC) -> PTerm -> PTerm
mapPTermFC FC -> FC
f FC -> FC
g PTerm
t2)
mapPTermFC FC -> FC
f FC -> FC
g (PDPair FC
fc [FC]
hls PunInfo
info PTerm
t1 PTerm
t2 PTerm
t3)  = FC -> [FC] -> PunInfo -> PTerm -> PTerm -> PTerm -> PTerm
PDPair (FC -> FC
f FC
fc) ((FC -> FC) -> [FC] -> [FC]
forall a b. (a -> b) -> [a] -> [b]
map FC -> FC
g [FC]
hls) PunInfo
info ((FC -> FC) -> (FC -> FC) -> PTerm -> PTerm
mapPTermFC FC -> FC
f FC -> FC
g PTerm
t1) ((FC -> FC) -> (FC -> FC) -> PTerm -> PTerm
mapPTermFC FC -> FC
f FC -> FC
g PTerm
t2) ((FC -> FC) -> (FC -> FC) -> PTerm -> PTerm
mapPTermFC FC -> FC
f FC -> FC
g PTerm
t3)
mapPTermFC FC -> FC
f FC -> FC
g (PAs FC
fc Name
n PTerm
t)                   = FC -> Name -> PTerm -> PTerm
PAs (FC -> FC
f FC
fc) Name
n ((FC -> FC) -> (FC -> FC) -> PTerm -> PTerm
mapPTermFC FC -> FC
f FC -> FC
g PTerm
t)
mapPTermFC FC -> FC
f FC -> FC
g (PAlternative [(Name, Name)]
ns PAltType
ty [PTerm]
ts)        = [(Name, Name)] -> PAltType -> [PTerm] -> PTerm
PAlternative [(Name, Name)]
ns PAltType
ty ((PTerm -> PTerm) -> [PTerm] -> [PTerm]
forall a b. (a -> b) -> [a] -> [b]
map ((FC -> FC) -> (FC -> FC) -> PTerm -> PTerm
mapPTermFC FC -> FC
f FC -> FC
g) [PTerm]
ts)
mapPTermFC FC -> FC
f FC -> FC
g (PHidden PTerm
t)                    = PTerm -> PTerm
PHidden ((FC -> FC) -> (FC -> FC) -> PTerm -> PTerm
mapPTermFC FC -> FC
f FC -> FC
g PTerm
t)
mapPTermFC FC -> FC
f FC -> FC
g (PType FC
fc)                     = FC -> PTerm
PType (FC -> FC
f FC
fc)
mapPTermFC FC -> FC
f FC -> FC
g (PUniverse FC
fc Universe
u)               = FC -> Universe -> PTerm
PUniverse (FC -> FC
f FC
fc) Universe
u
mapPTermFC FC -> FC
f FC -> FC
g (PGoal FC
fc PTerm
t1 Name
n PTerm
t2)             = FC -> PTerm -> Name -> PTerm -> PTerm
PGoal (FC -> FC
f FC
fc) ((FC -> FC) -> (FC -> FC) -> PTerm -> PTerm
mapPTermFC FC -> FC
f FC -> FC
g PTerm
t1) Name
n ((FC -> FC) -> (FC -> FC) -> PTerm -> PTerm
mapPTermFC FC -> FC
f FC -> FC
g PTerm
t2)
mapPTermFC FC -> FC
f FC -> FC
g (PConstant FC
fc Const
c)               = FC -> Const -> PTerm
PConstant (FC -> FC
f FC
fc) Const
c
mapPTermFC FC -> FC
f FC -> FC
g PTerm
Placeholder                    = PTerm
Placeholder
mapPTermFC FC -> FC
f FC -> FC
g (PDoBlock [PDo]
dos) = [PDo] -> PTerm
PDoBlock ((PDo -> PDo) -> [PDo] -> [PDo]
forall a b. (a -> b) -> [a] -> [b]
map PDo -> PDo
mapPDoFC [PDo]
dos)
  where mapPDoFC :: PDo -> PDo
mapPDoFC (DoExp  FC
fc PTerm
t) = FC -> PTerm -> PDo
forall t. FC -> t -> PDo' t
DoExp (FC -> FC
f FC
fc) ((FC -> FC) -> (FC -> FC) -> PTerm -> PTerm
mapPTermFC FC -> FC
f FC -> FC
g PTerm
t)
        mapPDoFC (DoBind FC
fc Name
n FC
nfc PTerm
t) = FC -> Name -> FC -> PTerm -> PDo
forall t. FC -> Name -> FC -> t -> PDo' t
DoBind (FC -> FC
f FC
fc) Name
n (FC -> FC
g FC
nfc) ((FC -> FC) -> (FC -> FC) -> PTerm -> PTerm
mapPTermFC FC -> FC
f FC -> FC
g PTerm
t)
        mapPDoFC (DoBindP FC
fc PTerm
t1 PTerm
t2 [(PTerm, PTerm)]
alts) =
          FC -> PTerm -> PTerm -> [(PTerm, PTerm)] -> PDo
forall t. FC -> t -> t -> [(t, t)] -> PDo' t
DoBindP (FC -> FC
f FC
fc) ((FC -> FC) -> (FC -> FC) -> PTerm -> PTerm
mapPTermFC FC -> FC
f FC -> FC
g PTerm
t1) ((FC -> FC) -> (FC -> FC) -> PTerm -> PTerm
mapPTermFC FC -> FC
f FC -> FC
g PTerm
t2) (((PTerm, PTerm) -> (PTerm, PTerm))
-> [(PTerm, PTerm)] -> [(PTerm, PTerm)]
forall a b. (a -> b) -> [a] -> [b]
map (\(PTerm
l,PTerm
r)-> ((FC -> FC) -> (FC -> FC) -> PTerm -> PTerm
mapPTermFC FC -> FC
f FC -> FC
g PTerm
l, (FC -> FC) -> (FC -> FC) -> PTerm -> PTerm
mapPTermFC FC -> FC
f FC -> FC
g PTerm
r)) [(PTerm, PTerm)]
alts)
        mapPDoFC (DoLet FC
fc RigCount
rc Name
n FC
nfc PTerm
t1 PTerm
t2) = FC -> RigCount -> Name -> FC -> PTerm -> PTerm -> PDo
forall t. FC -> RigCount -> Name -> FC -> t -> t -> PDo' t
DoLet (FC -> FC
f FC
fc) RigCount
rc Name
n (FC -> FC
g FC
nfc) ((FC -> FC) -> (FC -> FC) -> PTerm -> PTerm
mapPTermFC FC -> FC
f FC -> FC
g PTerm
t1) ((FC -> FC) -> (FC -> FC) -> PTerm -> PTerm
mapPTermFC FC -> FC
f FC -> FC
g PTerm
t2)
        mapPDoFC (DoLetP FC
fc PTerm
t1 PTerm
t2 [(PTerm, PTerm)]
alts) =
          FC -> PTerm -> PTerm -> [(PTerm, PTerm)] -> PDo
forall t. FC -> t -> t -> [(t, t)] -> PDo' t
DoLetP (FC -> FC
f FC
fc) ((FC -> FC) -> (FC -> FC) -> PTerm -> PTerm
mapPTermFC FC -> FC
f FC -> FC
g PTerm
t1) ((FC -> FC) -> (FC -> FC) -> PTerm -> PTerm
mapPTermFC FC -> FC
f FC -> FC
g PTerm
t2) (((PTerm, PTerm) -> (PTerm, PTerm))
-> [(PTerm, PTerm)] -> [(PTerm, PTerm)]
forall a b. (a -> b) -> [a] -> [b]
map (\(PTerm
l,PTerm
r) -> ((FC -> FC) -> (FC -> FC) -> PTerm -> PTerm
mapPTermFC FC -> FC
f FC -> FC
g PTerm
l, (FC -> FC) -> (FC -> FC) -> PTerm -> PTerm
mapPTermFC FC -> FC
f FC -> FC
g PTerm
r)) [(PTerm, PTerm)]
alts)
        mapPDoFC (DoRewrite FC
fc PTerm
h) = FC -> PTerm -> PDo
forall t. FC -> t -> PDo' t
DoRewrite (FC -> FC
f FC
fc) ((FC -> FC) -> (FC -> FC) -> PTerm -> PTerm
mapPTermFC FC -> FC
f FC -> FC
g PTerm
h)
mapPTermFC FC -> FC
f FC -> FC
g (PIdiom FC
fc PTerm
t)                  = FC -> PTerm -> PTerm
PIdiom (FC -> FC
f FC
fc) ((FC -> FC) -> (FC -> FC) -> PTerm -> PTerm
mapPTermFC FC -> FC
f FC -> FC
g PTerm
t)
mapPTermFC FC -> FC
f FC -> FC
g (PMetavar FC
fc Name
n)                = FC -> Name -> PTerm
PMetavar (FC -> FC
g FC
fc) Name
n
mapPTermFC FC -> FC
f FC -> FC
g (PProof [PTactic]
tacs)                  = [PTactic] -> PTerm
PProof ((PTactic -> PTactic) -> [PTactic] -> [PTactic]
forall a b. (a -> b) -> [a] -> [b]
map ((PTerm -> PTerm) -> PTactic -> PTactic
forall a b. (a -> b) -> PTactic' a -> PTactic' b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap ((FC -> FC) -> (FC -> FC) -> PTerm -> PTerm
mapPTermFC FC -> FC
f FC -> FC
g)) [PTactic]
tacs)
mapPTermFC FC -> FC
f FC -> FC
g (PTactics [PTactic]
tacs)                = [PTactic] -> PTerm
PTactics ((PTactic -> PTactic) -> [PTactic] -> [PTactic]
forall a b. (a -> b) -> [a] -> [b]
map ((PTerm -> PTerm) -> PTactic -> PTactic
forall a b. (a -> b) -> PTactic' a -> PTactic' b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap ((FC -> FC) -> (FC -> FC) -> PTerm -> PTerm
mapPTermFC FC -> FC
f FC -> FC
g)) [PTactic]
tacs)
mapPTermFC FC -> FC
f FC -> FC
g (PElabError Err
err)               = Err -> PTerm
PElabError Err
err
mapPTermFC FC -> FC
f FC -> FC
g PTerm
PImpossible                    = PTerm
PImpossible
mapPTermFC FC -> FC
f FC -> FC
g (PCoerced PTerm
t)                   = PTerm -> PTerm
PCoerced ((FC -> FC) -> (FC -> FC) -> PTerm -> PTerm
mapPTermFC FC -> FC
f FC -> FC
g PTerm
t)
mapPTermFC FC -> FC
f FC -> FC
g (PDisamb [[Text]]
msg PTerm
t)                = [[Text]] -> PTerm -> PTerm
PDisamb [[Text]]
msg ((FC -> FC) -> (FC -> FC) -> PTerm -> PTerm
mapPTermFC FC -> FC
f FC -> FC
g PTerm
t)
mapPTermFC FC -> FC
f FC -> FC
g (PUnifyLog PTerm
t)                  = PTerm -> PTerm
PUnifyLog ((FC -> FC) -> (FC -> FC) -> PTerm -> PTerm
mapPTermFC FC -> FC
f FC -> FC
g PTerm
t)
mapPTermFC FC -> FC
f FC -> FC
g (PNoImplicits PTerm
t)               = PTerm -> PTerm
PNoImplicits ((FC -> FC) -> (FC -> FC) -> PTerm -> PTerm
mapPTermFC FC -> FC
f FC -> FC
g PTerm
t)
mapPTermFC FC -> FC
f FC -> FC
g (PQuasiquote PTerm
t1 Maybe PTerm
t2)            = PTerm -> Maybe PTerm -> PTerm
PQuasiquote ((FC -> FC) -> (FC -> FC) -> PTerm -> PTerm
mapPTermFC FC -> FC
f FC -> FC
g PTerm
t1) ((PTerm -> PTerm) -> Maybe PTerm -> Maybe PTerm
forall a b. (a -> b) -> Maybe a -> Maybe b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap ((FC -> FC) -> (FC -> FC) -> PTerm -> PTerm
mapPTermFC FC -> FC
f FC -> FC
g) Maybe PTerm
t2)
mapPTermFC FC -> FC
f FC -> FC
g (PUnquote PTerm
t)                   = PTerm -> PTerm
PUnquote ((FC -> FC) -> (FC -> FC) -> PTerm -> PTerm
mapPTermFC FC -> FC
f FC -> FC
g PTerm
t)
mapPTermFC FC -> FC
f FC -> FC
g (PRunElab FC
fc PTerm
tm [String]
ns)            = FC -> PTerm -> [String] -> PTerm
PRunElab (FC -> FC
f FC
fc) ((FC -> FC) -> (FC -> FC) -> PTerm -> PTerm
mapPTermFC FC -> FC
f FC -> FC
g PTerm
tm) [String]
ns
mapPTermFC FC -> FC
f FC -> FC
g (PConstSugar FC
fc PTerm
tm)            = FC -> PTerm -> PTerm
PConstSugar (FC -> FC
g FC
fc) ((FC -> FC) -> (FC -> FC) -> PTerm -> PTerm
mapPTermFC FC -> FC
f FC -> FC
g PTerm
tm)
mapPTermFC FC -> FC
f FC -> FC
g (PQuoteName Name
n Bool
x FC
fc)            = Name -> Bool -> FC -> PTerm
PQuoteName Name
n Bool
x (FC -> FC
g FC
fc)

{-!
dg instance Binary PTerm
!-}

mapPT :: (PTerm -> PTerm) -> PTerm -> PTerm
mapPT :: (PTerm -> PTerm) -> PTerm -> PTerm
mapPT PTerm -> PTerm
f PTerm
t = PTerm -> PTerm
f (PTerm -> PTerm
mpt PTerm
t) where
  mpt :: PTerm -> PTerm
mpt (PLam FC
fc Name
n FC
nfc PTerm
t PTerm
s)     = FC -> Name -> FC -> PTerm -> PTerm -> PTerm
PLam FC
fc Name
n FC
nfc ((PTerm -> PTerm) -> PTerm -> PTerm
mapPT PTerm -> PTerm
f PTerm
t) ((PTerm -> PTerm) -> PTerm -> PTerm
mapPT PTerm -> PTerm
f PTerm
s)
  mpt (PPi Plicity
p Name
n FC
nfc PTerm
t PTerm
s)       = Plicity -> Name -> FC -> PTerm -> PTerm -> PTerm
PPi Plicity
p Name
n FC
nfc ((PTerm -> PTerm) -> PTerm -> PTerm
mapPT PTerm -> PTerm
f PTerm
t) ((PTerm -> PTerm) -> PTerm -> PTerm
mapPT PTerm -> PTerm
f PTerm
s)
  mpt (PLet FC
fc RigCount
rc Name
n FC
nfc PTerm
ty PTerm
v PTerm
s) = FC -> RigCount -> Name -> FC -> PTerm -> PTerm -> PTerm -> PTerm
PLet FC
fc RigCount
rc Name
n FC
nfc ((PTerm -> PTerm) -> PTerm -> PTerm
mapPT PTerm -> PTerm
f PTerm
ty) ((PTerm -> PTerm) -> PTerm -> PTerm
mapPT PTerm -> PTerm
f PTerm
v) ((PTerm -> PTerm) -> PTerm -> PTerm
mapPT PTerm -> PTerm
f PTerm
s)
  mpt (PRewrite FC
fc Maybe Name
by PTerm
t PTerm
s Maybe PTerm
g)  = FC -> Maybe Name -> PTerm -> PTerm -> Maybe PTerm -> PTerm
PRewrite FC
fc Maybe Name
by ((PTerm -> PTerm) -> PTerm -> PTerm
mapPT PTerm -> PTerm
f PTerm
t) ((PTerm -> PTerm) -> PTerm -> PTerm
mapPT PTerm -> PTerm
f PTerm
s) ((PTerm -> PTerm) -> Maybe PTerm -> Maybe PTerm
forall a b. (a -> b) -> Maybe a -> Maybe b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap ((PTerm -> PTerm) -> PTerm -> PTerm
mapPT PTerm -> PTerm
f) Maybe PTerm
g)
  mpt (PApp FC
fc PTerm
t [PArg]
as)          = FC -> PTerm -> [PArg] -> PTerm
PApp FC
fc ((PTerm -> PTerm) -> PTerm -> PTerm
mapPT PTerm -> PTerm
f PTerm
t) ((PArg -> PArg) -> [PArg] -> [PArg]
forall a b. (a -> b) -> [a] -> [b]
map ((PTerm -> PTerm) -> PArg -> PArg
forall a b. (a -> b) -> PArg' a -> PArg' b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap ((PTerm -> PTerm) -> PTerm -> PTerm
mapPT PTerm -> PTerm
f)) [PArg]
as)
  mpt (PWithApp FC
fc PTerm
t PTerm
a)       = FC -> PTerm -> PTerm -> PTerm
PWithApp FC
fc ((PTerm -> PTerm) -> PTerm -> PTerm
mapPT PTerm -> PTerm
f PTerm
t) ((PTerm -> PTerm) -> PTerm -> PTerm
mapPT PTerm -> PTerm
f PTerm
a)
  mpt (PAppBind FC
fc PTerm
t [PArg]
as)      = FC -> PTerm -> [PArg] -> PTerm
PAppBind FC
fc ((PTerm -> PTerm) -> PTerm -> PTerm
mapPT PTerm -> PTerm
f PTerm
t) ((PArg -> PArg) -> [PArg] -> [PArg]
forall a b. (a -> b) -> [a] -> [b]
map ((PTerm -> PTerm) -> PArg -> PArg
forall a b. (a -> b) -> PArg' a -> PArg' b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap ((PTerm -> PTerm) -> PTerm -> PTerm
mapPT PTerm -> PTerm
f)) [PArg]
as)
  mpt (PCase FC
fc PTerm
c [(PTerm, PTerm)]
os)         = FC -> PTerm -> [(PTerm, PTerm)] -> PTerm
PCase FC
fc ((PTerm -> PTerm) -> PTerm -> PTerm
mapPT PTerm -> PTerm
f PTerm
c) (((PTerm, PTerm) -> (PTerm, PTerm))
-> [(PTerm, PTerm)] -> [(PTerm, PTerm)]
forall a b. (a -> b) -> [a] -> [b]
map ((PTerm -> PTerm) -> (PTerm, PTerm) -> (PTerm, PTerm)
forall {t} {b}. (t -> b) -> (t, t) -> (b, b)
pmap ((PTerm -> PTerm) -> PTerm -> PTerm
mapPT PTerm -> PTerm
f)) [(PTerm, PTerm)]
os)
  mpt (PIfThenElse FC
fc PTerm
c PTerm
t PTerm
e)  = FC -> PTerm -> PTerm -> PTerm -> PTerm
PIfThenElse FC
fc ((PTerm -> PTerm) -> PTerm -> PTerm
mapPT PTerm -> PTerm
f PTerm
c) ((PTerm -> PTerm) -> PTerm -> PTerm
mapPT PTerm -> PTerm
f PTerm
t) ((PTerm -> PTerm) -> PTerm -> PTerm
mapPT PTerm -> PTerm
f PTerm
e)
  mpt (PTyped PTerm
l PTerm
r)            = PTerm -> PTerm -> PTerm
PTyped ((PTerm -> PTerm) -> PTerm -> PTerm
mapPT PTerm -> PTerm
f PTerm
l) ((PTerm -> PTerm) -> PTerm -> PTerm
mapPT PTerm -> PTerm
f PTerm
r)
  mpt (PPair FC
fc [FC]
hls PunInfo
p PTerm
l PTerm
r)    = FC -> [FC] -> PunInfo -> PTerm -> PTerm -> PTerm
PPair FC
fc [FC]
hls PunInfo
p ((PTerm -> PTerm) -> PTerm -> PTerm
mapPT PTerm -> PTerm
f PTerm
l) ((PTerm -> PTerm) -> PTerm -> PTerm
mapPT PTerm -> PTerm
f PTerm
r)
  mpt (PDPair FC
fc [FC]
hls PunInfo
p PTerm
l PTerm
t PTerm
r) = FC -> [FC] -> PunInfo -> PTerm -> PTerm -> PTerm -> PTerm
PDPair FC
fc [FC]
hls PunInfo
p ((PTerm -> PTerm) -> PTerm -> PTerm
mapPT PTerm -> PTerm
f PTerm
l) ((PTerm -> PTerm) -> PTerm -> PTerm
mapPT PTerm -> PTerm
f PTerm
t) ((PTerm -> PTerm) -> PTerm -> PTerm
mapPT PTerm -> PTerm
f PTerm
r)
  mpt (PAlternative [(Name, Name)]
ns PAltType
a [PTerm]
as)  = [(Name, Name)] -> PAltType -> [PTerm] -> PTerm
PAlternative [(Name, Name)]
ns PAltType
a ((PTerm -> PTerm) -> [PTerm] -> [PTerm]
forall a b. (a -> b) -> [a] -> [b]
map ((PTerm -> PTerm) -> PTerm -> PTerm
mapPT PTerm -> PTerm
f) [PTerm]
as)
  mpt (PHidden PTerm
t)             = PTerm -> PTerm
PHidden ((PTerm -> PTerm) -> PTerm -> PTerm
mapPT PTerm -> PTerm
f PTerm
t)
  mpt (PDoBlock [PDo]
ds)           = [PDo] -> PTerm
PDoBlock ((PDo -> PDo) -> [PDo] -> [PDo]
forall a b. (a -> b) -> [a] -> [b]
map ((PTerm -> PTerm) -> PDo -> PDo
forall a b. (a -> b) -> PDo' a -> PDo' b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap ((PTerm -> PTerm) -> PTerm -> PTerm
mapPT PTerm -> PTerm
f)) [PDo]
ds)
  mpt (PProof [PTactic]
ts)             = [PTactic] -> PTerm
PProof ((PTactic -> PTactic) -> [PTactic] -> [PTactic]
forall a b. (a -> b) -> [a] -> [b]
map ((PTerm -> PTerm) -> PTactic -> PTactic
forall a b. (a -> b) -> PTactic' a -> PTactic' b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap ((PTerm -> PTerm) -> PTerm -> PTerm
mapPT PTerm -> PTerm
f)) [PTactic]
ts)
  mpt (PTactics [PTactic]
ts)           = [PTactic] -> PTerm
PTactics ((PTactic -> PTactic) -> [PTactic] -> [PTactic]
forall a b. (a -> b) -> [a] -> [b]
map ((PTerm -> PTerm) -> PTactic -> PTactic
forall a b. (a -> b) -> PTactic' a -> PTactic' b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap ((PTerm -> PTerm) -> PTerm -> PTerm
mapPT PTerm -> PTerm
f)) [PTactic]
ts)
  mpt (PUnifyLog PTerm
tm)          = PTerm -> PTerm
PUnifyLog ((PTerm -> PTerm) -> PTerm -> PTerm
mapPT PTerm -> PTerm
f PTerm
tm)
  mpt (PDisamb [[Text]]
ns PTerm
tm)         = [[Text]] -> PTerm -> PTerm
PDisamb [[Text]]
ns ((PTerm -> PTerm) -> PTerm -> PTerm
mapPT PTerm -> PTerm
f PTerm
tm)
  mpt (PNoImplicits PTerm
tm)       = PTerm -> PTerm
PNoImplicits ((PTerm -> PTerm) -> PTerm -> PTerm
mapPT PTerm -> PTerm
f PTerm
tm)
  mpt (PGoal FC
fc PTerm
r Name
n PTerm
sc)       = FC -> PTerm -> Name -> PTerm -> PTerm
PGoal FC
fc ((PTerm -> PTerm) -> PTerm -> PTerm
mapPT PTerm -> PTerm
f PTerm
r) Name
n ((PTerm -> PTerm) -> PTerm -> PTerm
mapPT PTerm -> PTerm
f PTerm
sc)
  mpt PTerm
x                       = PTerm
x


data PTactic' t = Intro [Name] | Intros | Focus Name
                | Refine Name [Bool] | Rewrite t | DoUnify
                | Equiv t
                | Claim Name t
                | Unfocus
                | MatchRefine Name
                | LetTac Name t | LetTacTy Name t t
                | Exact t | Compute | Trivial | TCImplementation
                | ProofSearch Bool Bool Int (Maybe Name)
                              [Name] -- allowed local names
                              [Name] -- hints
                  -- ^ the bool is whether to search recursively
                | Solve
                | Attack
                | ProofState | ProofTerm | Undo
                | Try (PTactic' t) (PTactic' t)
                | TSeq (PTactic' t) (PTactic' t)
                | ApplyTactic t -- see Language.Reflection module
                | ByReflection t
                | Reflect t
                | Fill t
                | GoalType String (PTactic' t)
                | TCheck t
                | TEval t
                | TDocStr (Either Name Const)
                | TSearch t
                | Skip
                | TFail [ErrorReportPart]
                | Qed | Abandon
                | SourceFC
    deriving (Int -> PTactic' t -> ShowS
[PTactic' t] -> ShowS
PTactic' t -> String
(Int -> PTactic' t -> ShowS)
-> (PTactic' t -> String)
-> ([PTactic' t] -> ShowS)
-> Show (PTactic' t)
forall t. Show t => Int -> PTactic' t -> ShowS
forall t. Show t => [PTactic' t] -> ShowS
forall t. Show t => PTactic' t -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: forall t. Show t => Int -> PTactic' t -> ShowS
showsPrec :: Int -> PTactic' t -> ShowS
$cshow :: forall t. Show t => PTactic' t -> String
show :: PTactic' t -> String
$cshowList :: forall t. Show t => [PTactic' t] -> ShowS
showList :: [PTactic' t] -> ShowS
Show, PTactic' t -> PTactic' t -> Bool
(PTactic' t -> PTactic' t -> Bool)
-> (PTactic' t -> PTactic' t -> Bool) -> Eq (PTactic' t)
forall t. Eq t => PTactic' t -> PTactic' t -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: forall t. Eq t => PTactic' t -> PTactic' t -> Bool
== :: PTactic' t -> PTactic' t -> Bool
$c/= :: forall t. Eq t => PTactic' t -> PTactic' t -> Bool
/= :: PTactic' t -> PTactic' t -> Bool
Eq, Eq (PTactic' t)
Eq (PTactic' t) =>
(PTactic' t -> PTactic' t -> Ordering)
-> (PTactic' t -> PTactic' t -> Bool)
-> (PTactic' t -> PTactic' t -> Bool)
-> (PTactic' t -> PTactic' t -> Bool)
-> (PTactic' t -> PTactic' t -> Bool)
-> (PTactic' t -> PTactic' t -> PTactic' t)
-> (PTactic' t -> PTactic' t -> PTactic' t)
-> Ord (PTactic' t)
PTactic' t -> PTactic' t -> Bool
PTactic' t -> PTactic' t -> Ordering
PTactic' t -> PTactic' t -> PTactic' 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 (PTactic' t)
forall t. Ord t => PTactic' t -> PTactic' t -> Bool
forall t. Ord t => PTactic' t -> PTactic' t -> Ordering
forall t. Ord t => PTactic' t -> PTactic' t -> PTactic' t
$ccompare :: forall t. Ord t => PTactic' t -> PTactic' t -> Ordering
compare :: PTactic' t -> PTactic' t -> Ordering
$c< :: forall t. Ord t => PTactic' t -> PTactic' t -> Bool
< :: PTactic' t -> PTactic' t -> Bool
$c<= :: forall t. Ord t => PTactic' t -> PTactic' t -> Bool
<= :: PTactic' t -> PTactic' t -> Bool
$c> :: forall t. Ord t => PTactic' t -> PTactic' t -> Bool
> :: PTactic' t -> PTactic' t -> Bool
$c>= :: forall t. Ord t => PTactic' t -> PTactic' t -> Bool
>= :: PTactic' t -> PTactic' t -> Bool
$cmax :: forall t. Ord t => PTactic' t -> PTactic' t -> PTactic' t
max :: PTactic' t -> PTactic' t -> PTactic' t
$cmin :: forall t. Ord t => PTactic' t -> PTactic' t -> PTactic' t
min :: PTactic' t -> PTactic' t -> PTactic' t
Ord, (forall a b. (a -> b) -> PTactic' a -> PTactic' b)
-> (forall a b. a -> PTactic' b -> PTactic' a) -> Functor PTactic'
forall a b. a -> PTactic' b -> PTactic' a
forall a b. (a -> b) -> PTactic' a -> PTactic' b
forall (f :: * -> *).
(forall a b. (a -> b) -> f a -> f b)
-> (forall a b. a -> f b -> f a) -> Functor f
$cfmap :: forall a b. (a -> b) -> PTactic' a -> PTactic' b
fmap :: forall a b. (a -> b) -> PTactic' a -> PTactic' b
$c<$ :: forall a b. a -> PTactic' b -> PTactic' a
<$ :: forall a b. a -> PTactic' b -> PTactic' a
Functor, (forall m. Monoid m => PTactic' m -> m)
-> (forall m a. Monoid m => (a -> m) -> PTactic' a -> m)
-> (forall m a. Monoid m => (a -> m) -> PTactic' a -> m)
-> (forall a b. (a -> b -> b) -> b -> PTactic' a -> b)
-> (forall a b. (a -> b -> b) -> b -> PTactic' a -> b)
-> (forall b a. (b -> a -> b) -> b -> PTactic' a -> b)
-> (forall b a. (b -> a -> b) -> b -> PTactic' a -> b)
-> (forall a. (a -> a -> a) -> PTactic' a -> a)
-> (forall a. (a -> a -> a) -> PTactic' a -> a)
-> (forall a. PTactic' a -> [a])
-> (forall a. PTactic' a -> Bool)
-> (forall a. PTactic' a -> Int)
-> (forall a. Eq a => a -> PTactic' a -> Bool)
-> (forall a. Ord a => PTactic' a -> a)
-> (forall a. Ord a => PTactic' a -> a)
-> (forall a. Num a => PTactic' a -> a)
-> (forall a. Num a => PTactic' a -> a)
-> Foldable PTactic'
forall a. Eq a => a -> PTactic' a -> Bool
forall a. Num a => PTactic' a -> a
forall a. Ord a => PTactic' a -> a
forall m. Monoid m => PTactic' m -> m
forall a. PTactic' a -> Bool
forall a. PTactic' a -> Int
forall a. PTactic' a -> [a]
forall a. (a -> a -> a) -> PTactic' a -> a
forall m a. Monoid m => (a -> m) -> PTactic' a -> m
forall b a. (b -> a -> b) -> b -> PTactic' a -> b
forall a b. (a -> b -> b) -> b -> PTactic' a -> b
forall (t :: * -> *).
(forall m. Monoid m => t m -> m)
-> (forall m a. Monoid m => (a -> m) -> t a -> m)
-> (forall m a. Monoid m => (a -> m) -> t a -> m)
-> (forall a b. (a -> b -> b) -> b -> t a -> b)
-> (forall a b. (a -> b -> b) -> b -> t a -> b)
-> (forall b a. (b -> a -> b) -> b -> t a -> b)
-> (forall b a. (b -> a -> b) -> b -> t a -> b)
-> (forall a. (a -> a -> a) -> t a -> a)
-> (forall a. (a -> a -> a) -> t a -> a)
-> (forall a. t a -> [a])
-> (forall a. t a -> Bool)
-> (forall a. t a -> Int)
-> (forall a. Eq a => a -> t a -> Bool)
-> (forall a. Ord a => t a -> a)
-> (forall a. Ord a => t a -> a)
-> (forall a. Num a => t a -> a)
-> (forall a. Num a => t a -> a)
-> Foldable t
$cfold :: forall m. Monoid m => PTactic' m -> m
fold :: forall m. Monoid m => PTactic' m -> m
$cfoldMap :: forall m a. Monoid m => (a -> m) -> PTactic' a -> m
foldMap :: forall m a. Monoid m => (a -> m) -> PTactic' a -> m
$cfoldMap' :: forall m a. Monoid m => (a -> m) -> PTactic' a -> m
foldMap' :: forall m a. Monoid m => (a -> m) -> PTactic' a -> m
$cfoldr :: forall a b. (a -> b -> b) -> b -> PTactic' a -> b
foldr :: forall a b. (a -> b -> b) -> b -> PTactic' a -> b
$cfoldr' :: forall a b. (a -> b -> b) -> b -> PTactic' a -> b
foldr' :: forall a b. (a -> b -> b) -> b -> PTactic' a -> b
$cfoldl :: forall b a. (b -> a -> b) -> b -> PTactic' a -> b
foldl :: forall b a. (b -> a -> b) -> b -> PTactic' a -> b
$cfoldl' :: forall b a. (b -> a -> b) -> b -> PTactic' a -> b
foldl' :: forall b a. (b -> a -> b) -> b -> PTactic' a -> b
$cfoldr1 :: forall a. (a -> a -> a) -> PTactic' a -> a
foldr1 :: forall a. (a -> a -> a) -> PTactic' a -> a
$cfoldl1 :: forall a. (a -> a -> a) -> PTactic' a -> a
foldl1 :: forall a. (a -> a -> a) -> PTactic' a -> a
$ctoList :: forall a. PTactic' a -> [a]
toList :: forall a. PTactic' a -> [a]
$cnull :: forall a. PTactic' a -> Bool
null :: forall a. PTactic' a -> Bool
$clength :: forall a. PTactic' a -> Int
length :: forall a. PTactic' a -> Int
$celem :: forall a. Eq a => a -> PTactic' a -> Bool
elem :: forall a. Eq a => a -> PTactic' a -> Bool
$cmaximum :: forall a. Ord a => PTactic' a -> a
maximum :: forall a. Ord a => PTactic' a -> a
$cminimum :: forall a. Ord a => PTactic' a -> a
minimum :: forall a. Ord a => PTactic' a -> a
$csum :: forall a. Num a => PTactic' a -> a
sum :: forall a. Num a => PTactic' a -> a
$cproduct :: forall a. Num a => PTactic' a -> a
product :: forall a. Num a => PTactic' a -> a
Foldable, Functor PTactic'
Foldable PTactic'
(Functor PTactic', Foldable PTactic') =>
(forall (f :: * -> *) a b.
 Applicative f =>
 (a -> f b) -> PTactic' a -> f (PTactic' b))
-> (forall (f :: * -> *) a.
    Applicative f =>
    PTactic' (f a) -> f (PTactic' a))
-> (forall (m :: * -> *) a b.
    Monad m =>
    (a -> m b) -> PTactic' a -> m (PTactic' b))
-> (forall (m :: * -> *) a.
    Monad m =>
    PTactic' (m a) -> m (PTactic' a))
-> Traversable PTactic'
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 => PTactic' (m a) -> m (PTactic' a)
forall (f :: * -> *) a.
Applicative f =>
PTactic' (f a) -> f (PTactic' a)
forall (m :: * -> *) a b.
Monad m =>
(a -> m b) -> PTactic' a -> m (PTactic' b)
forall (f :: * -> *) a b.
Applicative f =>
(a -> f b) -> PTactic' a -> f (PTactic' b)
$ctraverse :: forall (f :: * -> *) a b.
Applicative f =>
(a -> f b) -> PTactic' a -> f (PTactic' b)
traverse :: forall (f :: * -> *) a b.
Applicative f =>
(a -> f b) -> PTactic' a -> f (PTactic' b)
$csequenceA :: forall (f :: * -> *) a.
Applicative f =>
PTactic' (f a) -> f (PTactic' a)
sequenceA :: forall (f :: * -> *) a.
Applicative f =>
PTactic' (f a) -> f (PTactic' a)
$cmapM :: forall (m :: * -> *) a b.
Monad m =>
(a -> m b) -> PTactic' a -> m (PTactic' b)
mapM :: forall (m :: * -> *) a b.
Monad m =>
(a -> m b) -> PTactic' a -> m (PTactic' b)
$csequence :: forall (m :: * -> *) a. Monad m => PTactic' (m a) -> m (PTactic' a)
sequence :: forall (m :: * -> *) a. Monad m => PTactic' (m a) -> m (PTactic' a)
Traversable, Typeable (PTactic' t)
Typeable (PTactic' t) =>
(forall (c :: * -> *).
 (forall d b. Data d => c (d -> b) -> d -> c b)
 -> (forall g. g -> c g) -> PTactic' t -> c (PTactic' t))
-> (forall (c :: * -> *).
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c (PTactic' t))
-> (PTactic' t -> Constr)
-> (PTactic' t -> DataType)
-> (forall (t :: * -> *) (c :: * -> *).
    Typeable t =>
    (forall d. Data d => c (t d)) -> Maybe (c (PTactic' t)))
-> (forall (t :: * -> * -> *) (c :: * -> *).
    Typeable t =>
    (forall d e. (Data d, Data e) => c (t d e))
    -> Maybe (c (PTactic' t)))
-> ((forall b. Data b => b -> b) -> PTactic' t -> PTactic' t)
-> (forall r r'.
    (r -> r' -> r)
    -> r -> (forall d. Data d => d -> r') -> PTactic' t -> r)
-> (forall r r'.
    (r' -> r -> r)
    -> r -> (forall d. Data d => d -> r') -> PTactic' t -> r)
-> (forall u. (forall d. Data d => d -> u) -> PTactic' t -> [u])
-> (forall u.
    Int -> (forall d. Data d => d -> u) -> PTactic' t -> u)
-> (forall (m :: * -> *).
    Monad m =>
    (forall d. Data d => d -> m d) -> PTactic' t -> m (PTactic' t))
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> PTactic' t -> m (PTactic' t))
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> PTactic' t -> m (PTactic' t))
-> Data (PTactic' t)
PTactic' t -> Constr
PTactic' t -> DataType
(forall b. Data b => b -> b) -> PTactic' t -> PTactic' t
forall t. Data t => Typeable (PTactic' t)
forall t. Data t => PTactic' t -> Constr
forall t. Data t => PTactic' t -> DataType
forall t.
Data t =>
(forall b. Data b => b -> b) -> PTactic' t -> PTactic' t
forall t u.
Data t =>
Int -> (forall d. Data d => d -> u) -> PTactic' t -> u
forall t u.
Data t =>
(forall d. Data d => d -> u) -> PTactic' t -> [u]
forall t r r'.
Data t =>
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> PTactic' t -> r
forall t r r'.
Data t =>
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> PTactic' t -> r
forall t (m :: * -> *).
(Data t, Monad m) =>
(forall d. Data d => d -> m d) -> PTactic' t -> m (PTactic' t)
forall t (m :: * -> *).
(Data t, MonadPlus m) =>
(forall d. Data d => d -> m d) -> PTactic' t -> m (PTactic' t)
forall t (c :: * -> *).
Data t =>
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c (PTactic' t)
forall t (c :: * -> *).
Data t =>
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> PTactic' t -> c (PTactic' t)
forall t (t :: * -> *) (c :: * -> *).
(Data t, Typeable t) =>
(forall d. Data d => c (t d)) -> Maybe (c (PTactic' t))
forall t (t :: * -> * -> *) (c :: * -> *).
(Data t, Typeable t) =>
(forall d e. (Data d, Data e) => c (t d e))
-> Maybe (c (PTactic' t))
forall a.
Typeable a =>
(forall (c :: * -> *).
 (forall d b. Data d => c (d -> b) -> d -> c b)
 -> (forall g. g -> c g) -> a -> c a)
-> (forall (c :: * -> *).
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c a)
-> (a -> Constr)
-> (a -> DataType)
-> (forall (t :: * -> *) (c :: * -> *).
    Typeable t =>
    (forall d. Data d => c (t d)) -> Maybe (c a))
-> (forall (t :: * -> * -> *) (c :: * -> *).
    Typeable t =>
    (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c a))
-> ((forall b. Data b => b -> b) -> a -> a)
-> (forall r r'.
    (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall r r'.
    (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall u. (forall d. Data d => d -> u) -> a -> [u])
-> (forall u. Int -> (forall d. Data d => d -> u) -> a -> u)
-> (forall (m :: * -> *).
    Monad m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> Data a
forall u. Int -> (forall d. Data d => d -> u) -> PTactic' t -> u
forall u. (forall d. Data d => d -> u) -> PTactic' t -> [u]
forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> PTactic' t -> r
forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> PTactic' t -> r
forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> PTactic' t -> m (PTactic' t)
forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> PTactic' t -> m (PTactic' t)
forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c (PTactic' t)
forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> PTactic' t -> c (PTactic' t)
forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c (PTactic' t))
forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e))
-> Maybe (c (PTactic' t))
$cgfoldl :: forall t (c :: * -> *).
Data t =>
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> PTactic' t -> c (PTactic' t)
gfoldl :: forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> PTactic' t -> c (PTactic' t)
$cgunfold :: forall t (c :: * -> *).
Data t =>
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c (PTactic' t)
gunfold :: forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c (PTactic' t)
$ctoConstr :: forall t. Data t => PTactic' t -> Constr
toConstr :: PTactic' t -> Constr
$cdataTypeOf :: forall t. Data t => PTactic' t -> DataType
dataTypeOf :: PTactic' t -> DataType
$cdataCast1 :: forall t (t :: * -> *) (c :: * -> *).
(Data t, Typeable t) =>
(forall d. Data d => c (t d)) -> Maybe (c (PTactic' t))
dataCast1 :: forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c (PTactic' t))
$cdataCast2 :: forall t (t :: * -> * -> *) (c :: * -> *).
(Data t, Typeable t) =>
(forall d e. (Data d, Data e) => c (t d e))
-> Maybe (c (PTactic' t))
dataCast2 :: forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e))
-> Maybe (c (PTactic' t))
$cgmapT :: forall t.
Data t =>
(forall b. Data b => b -> b) -> PTactic' t -> PTactic' t
gmapT :: (forall b. Data b => b -> b) -> PTactic' t -> PTactic' t
$cgmapQl :: forall t r r'.
Data t =>
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> PTactic' t -> r
gmapQl :: forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> PTactic' t -> r
$cgmapQr :: forall t r r'.
Data t =>
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> PTactic' t -> r
gmapQr :: forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> PTactic' t -> r
$cgmapQ :: forall t u.
Data t =>
(forall d. Data d => d -> u) -> PTactic' t -> [u]
gmapQ :: forall u. (forall d. Data d => d -> u) -> PTactic' t -> [u]
$cgmapQi :: forall t u.
Data t =>
Int -> (forall d. Data d => d -> u) -> PTactic' t -> u
gmapQi :: forall u. Int -> (forall d. Data d => d -> u) -> PTactic' t -> u
$cgmapM :: forall t (m :: * -> *).
(Data t, Monad m) =>
(forall d. Data d => d -> m d) -> PTactic' t -> m (PTactic' t)
gmapM :: forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> PTactic' t -> m (PTactic' t)
$cgmapMp :: forall t (m :: * -> *).
(Data t, MonadPlus m) =>
(forall d. Data d => d -> m d) -> PTactic' t -> m (PTactic' t)
gmapMp :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> PTactic' t -> m (PTactic' t)
$cgmapMo :: forall t (m :: * -> *).
(Data t, MonadPlus m) =>
(forall d. Data d => d -> m d) -> PTactic' t -> m (PTactic' t)
gmapMo :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> PTactic' t -> m (PTactic' t)
Data, (forall x. PTactic' t -> Rep (PTactic' t) x)
-> (forall x. Rep (PTactic' t) x -> PTactic' t)
-> Generic (PTactic' t)
forall x. Rep (PTactic' t) x -> PTactic' t
forall x. PTactic' t -> Rep (PTactic' t) x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
forall t x. Rep (PTactic' t) x -> PTactic' t
forall t x. PTactic' t -> Rep (PTactic' t) x
$cfrom :: forall t x. PTactic' t -> Rep (PTactic' t) x
from :: forall x. PTactic' t -> Rep (PTactic' t) x
$cto :: forall t x. Rep (PTactic' t) x -> PTactic' t
to :: forall x. Rep (PTactic' t) x -> PTactic' t
Generic, Typeable)
{-!
deriving instance Binary PTactic'
!-}
instance Sized a => Sized (PTactic' a) where
  size :: PTactic' a -> Int
size (Intro [Name]
nms)      = Int
1 Int -> Int -> Int
forall a. Num a => a -> a -> a
+ [Name] -> Int
forall a. Sized a => a -> Int
size [Name]
nms
  size PTactic' a
Intros           = Int
1
  size (Focus Name
nm)       = Int
1 Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Name -> Int
forall a. Sized a => a -> Int
size Name
nm
  size (Refine Name
nm [Bool]
bs)   = Int
1 Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Name -> Int
forall a. Sized a => a -> Int
size Name
nm Int -> Int -> Int
forall a. Num a => a -> a -> a
+ [Bool] -> Int
forall a. [a] -> Int
forall (t :: * -> *) a. Foldable t => t a -> Int
length [Bool]
bs
  size (Rewrite a
t)      = Int
1 Int -> Int -> Int
forall a. Num a => a -> a -> a
+ a -> Int
forall a. Sized a => a -> Int
size a
t
  size (LetTac Name
nm a
t)    = Int
1 Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Name -> Int
forall a. Sized a => a -> Int
size Name
nm Int -> Int -> Int
forall a. Num a => a -> a -> a
+ a -> Int
forall a. Sized a => a -> Int
size a
t
  size (Exact a
t)        = Int
1 Int -> Int -> Int
forall a. Num a => a -> a -> a
+ a -> Int
forall a. Sized a => a -> Int
size a
t
  size PTactic' a
Compute          = Int
1
  size PTactic' a
Trivial          = Int
1
  size PTactic' a
Solve            = Int
1
  size PTactic' a
Attack           = Int
1
  size PTactic' a
ProofState       = Int
1
  size PTactic' a
ProofTerm        = Int
1
  size PTactic' a
Undo             = Int
1
  size (Try PTactic' a
l PTactic' a
r)        = Int
1 Int -> Int -> Int
forall a. Num a => a -> a -> a
+ PTactic' a -> Int
forall a. Sized a => a -> Int
size PTactic' a
l Int -> Int -> Int
forall a. Num a => a -> a -> a
+ PTactic' a -> Int
forall a. Sized a => a -> Int
size PTactic' a
r
  size (TSeq PTactic' a
l PTactic' a
r)       = Int
1 Int -> Int -> Int
forall a. Num a => a -> a -> a
+ PTactic' a -> Int
forall a. Sized a => a -> Int
size PTactic' a
l Int -> Int -> Int
forall a. Num a => a -> a -> a
+ PTactic' a -> Int
forall a. Sized a => a -> Int
size PTactic' a
r
  size (ApplyTactic a
t)  = Int
1 Int -> Int -> Int
forall a. Num a => a -> a -> a
+ a -> Int
forall a. Sized a => a -> Int
size a
t
  size (Reflect a
t)      = Int
1 Int -> Int -> Int
forall a. Num a => a -> a -> a
+ a -> Int
forall a. Sized a => a -> Int
size a
t
  size (Fill a
t)         = Int
1 Int -> Int -> Int
forall a. Num a => a -> a -> a
+ a -> Int
forall a. Sized a => a -> Int
size a
t
  size PTactic' a
Qed              = Int
1
  size PTactic' a
Abandon          = Int
1
  size PTactic' a
Skip             = Int
1
  size (TFail [ErrorReportPart]
ts)       = Int
1 Int -> Int -> Int
forall a. Num a => a -> a -> a
+ [ErrorReportPart] -> Int
forall a. Sized a => a -> Int
size [ErrorReportPart]
ts
  size PTactic' a
SourceFC         = Int
1
  size PTactic' a
DoUnify          = Int
1
  size (Equiv a
t)        = Int
1 Int -> Int -> Int
forall a. Num a => a -> a -> a
+ a -> Int
forall a. Sized a => a -> Int
size a
t
  size (Claim Name
x a
y)      = Int
1 Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Name -> Int
forall a. Sized a => a -> Int
size Name
x Int -> Int -> Int
forall a. Num a => a -> a -> a
+ a -> Int
forall a. Sized a => a -> Int
size a
y
  size PTactic' a
Unfocus          = Int
1
  size (MatchRefine Name
x)  = Int
1 Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Name -> Int
forall a. Sized a => a -> Int
size Name
x
  size (LetTacTy Name
x a
y a
z) = Int
1 Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Name -> Int
forall a. Sized a => a -> Int
size Name
x Int -> Int -> Int
forall a. Num a => a -> a -> a
+ a -> Int
forall a. Sized a => a -> Int
size a
y Int -> Int -> Int
forall a. Num a => a -> a -> a
+ a -> Int
forall a. Sized a => a -> Int
size a
z
  size PTactic' a
TCImplementation       = Int
1

type PTactic = PTactic' PTerm

data PDo' t = DoExp  FC t
            | DoBind FC Name FC t     -- ^ second FC is precise name location
            | DoBindP FC t t [(t,t)]
            | DoLet  FC RigCount Name FC t t   -- ^ second FC is precise name location
            | DoLetP FC t t [(t,t)]
            | DoRewrite FC t          -- rewrite in do block
    deriving (PDo' t -> PDo' t -> Bool
(PDo' t -> PDo' t -> Bool)
-> (PDo' t -> PDo' t -> Bool) -> Eq (PDo' t)
forall t. Eq t => PDo' t -> PDo' t -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: forall t. Eq t => PDo' t -> PDo' t -> Bool
== :: PDo' t -> PDo' t -> Bool
$c/= :: forall t. Eq t => PDo' t -> PDo' t -> Bool
/= :: PDo' t -> PDo' t -> Bool
Eq, Eq (PDo' t)
Eq (PDo' t) =>
(PDo' t -> PDo' t -> Ordering)
-> (PDo' t -> PDo' t -> Bool)
-> (PDo' t -> PDo' t -> Bool)
-> (PDo' t -> PDo' t -> Bool)
-> (PDo' t -> PDo' t -> Bool)
-> (PDo' t -> PDo' t -> PDo' t)
-> (PDo' t -> PDo' t -> PDo' t)
-> Ord (PDo' t)
PDo' t -> PDo' t -> Bool
PDo' t -> PDo' t -> Ordering
PDo' t -> PDo' t -> PDo' 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 (PDo' t)
forall t. Ord t => PDo' t -> PDo' t -> Bool
forall t. Ord t => PDo' t -> PDo' t -> Ordering
forall t. Ord t => PDo' t -> PDo' t -> PDo' t
$ccompare :: forall t. Ord t => PDo' t -> PDo' t -> Ordering
compare :: PDo' t -> PDo' t -> Ordering
$c< :: forall t. Ord t => PDo' t -> PDo' t -> Bool
< :: PDo' t -> PDo' t -> Bool
$c<= :: forall t. Ord t => PDo' t -> PDo' t -> Bool
<= :: PDo' t -> PDo' t -> Bool
$c> :: forall t. Ord t => PDo' t -> PDo' t -> Bool
> :: PDo' t -> PDo' t -> Bool
$c>= :: forall t. Ord t => PDo' t -> PDo' t -> Bool
>= :: PDo' t -> PDo' t -> Bool
$cmax :: forall t. Ord t => PDo' t -> PDo' t -> PDo' t
max :: PDo' t -> PDo' t -> PDo' t
$cmin :: forall t. Ord t => PDo' t -> PDo' t -> PDo' t
min :: PDo' t -> PDo' t -> PDo' t
Ord, (forall a b. (a -> b) -> PDo' a -> PDo' b)
-> (forall a b. a -> PDo' b -> PDo' a) -> Functor PDo'
forall a b. a -> PDo' b -> PDo' a
forall a b. (a -> b) -> PDo' a -> PDo' b
forall (f :: * -> *).
(forall a b. (a -> b) -> f a -> f b)
-> (forall a b. a -> f b -> f a) -> Functor f
$cfmap :: forall a b. (a -> b) -> PDo' a -> PDo' b
fmap :: forall a b. (a -> b) -> PDo' a -> PDo' b
$c<$ :: forall a b. a -> PDo' b -> PDo' a
<$ :: forall a b. a -> PDo' b -> PDo' a
Functor, Typeable (PDo' t)
Typeable (PDo' t) =>
(forall (c :: * -> *).
 (forall d b. Data d => c (d -> b) -> d -> c b)
 -> (forall g. g -> c g) -> PDo' t -> c (PDo' t))
-> (forall (c :: * -> *).
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c (PDo' t))
-> (PDo' t -> Constr)
-> (PDo' t -> DataType)
-> (forall (t :: * -> *) (c :: * -> *).
    Typeable t =>
    (forall d. Data d => c (t d)) -> Maybe (c (PDo' t)))
-> (forall (t :: * -> * -> *) (c :: * -> *).
    Typeable t =>
    (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c (PDo' t)))
-> ((forall b. Data b => b -> b) -> PDo' t -> PDo' t)
-> (forall r r'.
    (r -> r' -> r)
    -> r -> (forall d. Data d => d -> r') -> PDo' t -> r)
-> (forall r r'.
    (r' -> r -> r)
    -> r -> (forall d. Data d => d -> r') -> PDo' t -> r)
-> (forall u. (forall d. Data d => d -> u) -> PDo' t -> [u])
-> (forall u. Int -> (forall d. Data d => d -> u) -> PDo' t -> u)
-> (forall (m :: * -> *).
    Monad m =>
    (forall d. Data d => d -> m d) -> PDo' t -> m (PDo' t))
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> PDo' t -> m (PDo' t))
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> PDo' t -> m (PDo' t))
-> Data (PDo' t)
PDo' t -> Constr
PDo' t -> DataType
(forall b. Data b => b -> b) -> PDo' t -> PDo' t
forall t. Data t => Typeable (PDo' t)
forall t. Data t => PDo' t -> Constr
forall t. Data t => PDo' t -> DataType
forall t.
Data t =>
(forall b. Data b => b -> b) -> PDo' t -> PDo' t
forall t u.
Data t =>
Int -> (forall d. Data d => d -> u) -> PDo' t -> u
forall t u. Data t => (forall d. Data d => d -> u) -> PDo' t -> [u]
forall t r r'.
Data t =>
(r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> PDo' t -> r
forall t r r'.
Data t =>
(r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> PDo' t -> r
forall t (m :: * -> *).
(Data t, Monad m) =>
(forall d. Data d => d -> m d) -> PDo' t -> m (PDo' t)
forall t (m :: * -> *).
(Data t, MonadPlus m) =>
(forall d. Data d => d -> m d) -> PDo' t -> m (PDo' t)
forall t (c :: * -> *).
Data t =>
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c (PDo' t)
forall t (c :: * -> *).
Data t =>
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> PDo' t -> c (PDo' t)
forall t (t :: * -> *) (c :: * -> *).
(Data t, Typeable t) =>
(forall d. Data d => c (t d)) -> Maybe (c (PDo' t))
forall t (t :: * -> * -> *) (c :: * -> *).
(Data t, Typeable t) =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c (PDo' t))
forall a.
Typeable a =>
(forall (c :: * -> *).
 (forall d b. Data d => c (d -> b) -> d -> c b)
 -> (forall g. g -> c g) -> a -> c a)
-> (forall (c :: * -> *).
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c a)
-> (a -> Constr)
-> (a -> DataType)
-> (forall (t :: * -> *) (c :: * -> *).
    Typeable t =>
    (forall d. Data d => c (t d)) -> Maybe (c a))
-> (forall (t :: * -> * -> *) (c :: * -> *).
    Typeable t =>
    (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c a))
-> ((forall b. Data b => b -> b) -> a -> a)
-> (forall r r'.
    (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall r r'.
    (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall u. (forall d. Data d => d -> u) -> a -> [u])
-> (forall u. Int -> (forall d. Data d => d -> u) -> a -> u)
-> (forall (m :: * -> *).
    Monad m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> Data a
forall u. Int -> (forall d. Data d => d -> u) -> PDo' t -> u
forall u. (forall d. Data d => d -> u) -> PDo' t -> [u]
forall r r'.
(r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> PDo' t -> r
forall r r'.
(r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> PDo' t -> r
forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> PDo' t -> m (PDo' t)
forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> PDo' t -> m (PDo' t)
forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c (PDo' t)
forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> PDo' t -> c (PDo' t)
forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c (PDo' t))
forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c (PDo' t))
$cgfoldl :: forall t (c :: * -> *).
Data t =>
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> PDo' t -> c (PDo' t)
gfoldl :: forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> PDo' t -> c (PDo' t)
$cgunfold :: forall t (c :: * -> *).
Data t =>
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c (PDo' t)
gunfold :: forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c (PDo' t)
$ctoConstr :: forall t. Data t => PDo' t -> Constr
toConstr :: PDo' t -> Constr
$cdataTypeOf :: forall t. Data t => PDo' t -> DataType
dataTypeOf :: PDo' t -> DataType
$cdataCast1 :: forall t (t :: * -> *) (c :: * -> *).
(Data t, Typeable t) =>
(forall d. Data d => c (t d)) -> Maybe (c (PDo' t))
dataCast1 :: forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c (PDo' t))
$cdataCast2 :: forall t (t :: * -> * -> *) (c :: * -> *).
(Data t, Typeable t) =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c (PDo' t))
dataCast2 :: forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c (PDo' t))
$cgmapT :: forall t.
Data t =>
(forall b. Data b => b -> b) -> PDo' t -> PDo' t
gmapT :: (forall b. Data b => b -> b) -> PDo' t -> PDo' t
$cgmapQl :: forall t r r'.
Data t =>
(r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> PDo' t -> r
gmapQl :: forall r r'.
(r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> PDo' t -> r
$cgmapQr :: forall t r r'.
Data t =>
(r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> PDo' t -> r
gmapQr :: forall r r'.
(r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> PDo' t -> r
$cgmapQ :: forall t u. Data t => (forall d. Data d => d -> u) -> PDo' t -> [u]
gmapQ :: forall u. (forall d. Data d => d -> u) -> PDo' t -> [u]
$cgmapQi :: forall t u.
Data t =>
Int -> (forall d. Data d => d -> u) -> PDo' t -> u
gmapQi :: forall u. Int -> (forall d. Data d => d -> u) -> PDo' t -> u
$cgmapM :: forall t (m :: * -> *).
(Data t, Monad m) =>
(forall d. Data d => d -> m d) -> PDo' t -> m (PDo' t)
gmapM :: forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> PDo' t -> m (PDo' t)
$cgmapMp :: forall t (m :: * -> *).
(Data t, MonadPlus m) =>
(forall d. Data d => d -> m d) -> PDo' t -> m (PDo' t)
gmapMp :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> PDo' t -> m (PDo' t)
$cgmapMo :: forall t (m :: * -> *).
(Data t, MonadPlus m) =>
(forall d. Data d => d -> m d) -> PDo' t -> m (PDo' t)
gmapMo :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> PDo' t -> m (PDo' t)
Data, (forall x. PDo' t -> Rep (PDo' t) x)
-> (forall x. Rep (PDo' t) x -> PDo' t) -> Generic (PDo' t)
forall x. Rep (PDo' t) x -> PDo' t
forall x. PDo' t -> Rep (PDo' t) x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
forall t x. Rep (PDo' t) x -> PDo' t
forall t x. PDo' t -> Rep (PDo' t) x
$cfrom :: forall t x. PDo' t -> Rep (PDo' t) x
from :: forall x. PDo' t -> Rep (PDo' t) x
$cto :: forall t x. Rep (PDo' t) x -> PDo' t
to :: forall x. Rep (PDo' t) x -> PDo' t
Generic, Typeable)
{-!
deriving instance Binary PDo'
!-}

instance Sized a => Sized (PDo' a) where
  size :: PDo' a -> Int
size (DoExp FC
fc a
t)           = Int
1 Int -> Int -> Int
forall a. Num a => a -> a -> a
+ FC -> Int
forall a. Sized a => a -> Int
size FC
fc Int -> Int -> Int
forall a. Num a => a -> a -> a
+ a -> Int
forall a. Sized a => a -> Int
size a
t
  size (DoBind FC
fc Name
nm FC
nfc a
t)   = Int
1 Int -> Int -> Int
forall a. Num a => a -> a -> a
+ FC -> Int
forall a. Sized a => a -> Int
size FC
fc Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Name -> Int
forall a. Sized a => a -> Int
size Name
nm Int -> Int -> Int
forall a. Num a => a -> a -> a
+ FC -> Int
forall a. Sized a => a -> Int
size FC
nfc Int -> Int -> Int
forall a. Num a => a -> a -> a
+ a -> Int
forall a. Sized a => a -> Int
size a
t
  size (DoBindP FC
fc a
l a
r [(a, a)]
alts)  = Int
1 Int -> Int -> Int
forall a. Num a => a -> a -> a
+ FC -> Int
forall a. Sized a => a -> Int
size FC
fc Int -> Int -> Int
forall a. Num a => a -> a -> a
+ a -> Int
forall a. Sized a => a -> Int
size a
l  Int -> Int -> Int
forall a. Num a => a -> a -> a
+ a -> Int
forall a. Sized a => a -> Int
size a
r   Int -> Int -> Int
forall a. Num a => a -> a -> a
+ [(a, a)] -> Int
forall a. Sized a => a -> Int
size [(a, a)]
alts
  size (DoLet FC
fc RigCount
rc Name
nm FC
nfc a
l a
r)  = Int
1 Int -> Int -> Int
forall a. Num a => a -> a -> a
+ FC -> Int
forall a. Sized a => a -> Int
size FC
fc Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Name -> Int
forall a. Sized a => a -> Int
size Name
nm Int -> Int -> Int
forall a. Num a => a -> a -> a
+ a -> Int
forall a. Sized a => a -> Int
size a
l   Int -> Int -> Int
forall a. Num a => a -> a -> a
+ a -> Int
forall a. Sized a => a -> Int
size a
r
  size (DoLetP FC
fc a
l a
r [(a, a)]
alts)   = Int
1 Int -> Int -> Int
forall a. Num a => a -> a -> a
+ FC -> Int
forall a. Sized a => a -> Int
size FC
fc Int -> Int -> Int
forall a. Num a => a -> a -> a
+ a -> Int
forall a. Sized a => a -> Int
size a
l  Int -> Int -> Int
forall a. Num a => a -> a -> a
+ a -> Int
forall a. Sized a => a -> Int
size a
r Int -> Int -> Int
forall a. Num a => a -> a -> a
+ [(a, a)] -> Int
forall a. Sized a => a -> Int
size [(a, a)]
alts
  size (DoRewrite FC
fc a
h)       = Int
1 Int -> Int -> Int
forall a. Num a => a -> a -> a
+ FC -> Int
forall a. Sized a => a -> Int
size FC
fc Int -> Int -> Int
forall a. Num a => a -> a -> a
+ a -> Int
forall a. Sized a => a -> Int
size a
h

type PDo = PDo' PTerm

-- The priority gives a hint as to elaboration order. Best to elaborate
-- things early which will help give a more concrete type to other
-- variables, e.g. a before (interpTy a).

data PArg' t = PImp { forall t. PArg' t -> Int
priority    :: Int
                    , forall t. PArg' t -> Bool
machine_inf :: Bool -- ^ true if the machine inferred it
                    , forall t. PArg' t -> [ArgOpt]
argopts     :: [ArgOpt]
                    , forall t. PArg' t -> Name
pname       :: Name
                    , forall t. PArg' t -> t
getTm       :: t
                    }
             | PExp { priority :: Int
                    , argopts  :: [ArgOpt]
                    , pname    :: Name
                    , getTm    :: t
                    }
             | PConstraint { priority :: Int
                           , argopts  :: [ArgOpt]
                           , pname    :: Name
                           , getTm    :: t
                           }
             | PTacImplicit { priority  :: Int
                            , argopts   :: [ArgOpt]
                            , pname     :: Name
                            , forall t. PArg' t -> t
getScript :: t
                            , getTm     :: t
                            }
             deriving (Int -> PArg' t -> ShowS
[PArg' t] -> ShowS
PArg' t -> String
(Int -> PArg' t -> ShowS)
-> (PArg' t -> String) -> ([PArg' t] -> ShowS) -> Show (PArg' t)
forall t. Show t => Int -> PArg' t -> ShowS
forall t. Show t => [PArg' t] -> ShowS
forall t. Show t => PArg' t -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: forall t. Show t => Int -> PArg' t -> ShowS
showsPrec :: Int -> PArg' t -> ShowS
$cshow :: forall t. Show t => PArg' t -> String
show :: PArg' t -> String
$cshowList :: forall t. Show t => [PArg' t] -> ShowS
showList :: [PArg' t] -> ShowS
Show, PArg' t -> PArg' t -> Bool
(PArg' t -> PArg' t -> Bool)
-> (PArg' t -> PArg' t -> Bool) -> Eq (PArg' t)
forall t. Eq t => PArg' t -> PArg' t -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: forall t. Eq t => PArg' t -> PArg' t -> Bool
== :: PArg' t -> PArg' t -> Bool
$c/= :: forall t. Eq t => PArg' t -> PArg' t -> Bool
/= :: PArg' t -> PArg' t -> Bool
Eq, Eq (PArg' t)
Eq (PArg' t) =>
(PArg' t -> PArg' t -> Ordering)
-> (PArg' t -> PArg' t -> Bool)
-> (PArg' t -> PArg' t -> Bool)
-> (PArg' t -> PArg' t -> Bool)
-> (PArg' t -> PArg' t -> Bool)
-> (PArg' t -> PArg' t -> PArg' t)
-> (PArg' t -> PArg' t -> PArg' t)
-> Ord (PArg' t)
PArg' t -> PArg' t -> Bool
PArg' t -> PArg' t -> Ordering
PArg' t -> PArg' t -> PArg' 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 (PArg' t)
forall t. Ord t => PArg' t -> PArg' t -> Bool
forall t. Ord t => PArg' t -> PArg' t -> Ordering
forall t. Ord t => PArg' t -> PArg' t -> PArg' t
$ccompare :: forall t. Ord t => PArg' t -> PArg' t -> Ordering
compare :: PArg' t -> PArg' t -> Ordering
$c< :: forall t. Ord t => PArg' t -> PArg' t -> Bool
< :: PArg' t -> PArg' t -> Bool
$c<= :: forall t. Ord t => PArg' t -> PArg' t -> Bool
<= :: PArg' t -> PArg' t -> Bool
$c> :: forall t. Ord t => PArg' t -> PArg' t -> Bool
> :: PArg' t -> PArg' t -> Bool
$c>= :: forall t. Ord t => PArg' t -> PArg' t -> Bool
>= :: PArg' t -> PArg' t -> Bool
$cmax :: forall t. Ord t => PArg' t -> PArg' t -> PArg' t
max :: PArg' t -> PArg' t -> PArg' t
$cmin :: forall t. Ord t => PArg' t -> PArg' t -> PArg' t
min :: PArg' t -> PArg' t -> PArg' t
Ord, (forall a b. (a -> b) -> PArg' a -> PArg' b)
-> (forall a b. a -> PArg' b -> PArg' a) -> Functor PArg'
forall a b. a -> PArg' b -> PArg' a
forall a b. (a -> b) -> PArg' a -> PArg' b
forall (f :: * -> *).
(forall a b. (a -> b) -> f a -> f b)
-> (forall a b. a -> f b -> f a) -> Functor f
$cfmap :: forall a b. (a -> b) -> PArg' a -> PArg' b
fmap :: forall a b. (a -> b) -> PArg' a -> PArg' b
$c<$ :: forall a b. a -> PArg' b -> PArg' a
<$ :: forall a b. a -> PArg' b -> PArg' a
Functor, Typeable (PArg' t)
Typeable (PArg' t) =>
(forall (c :: * -> *).
 (forall d b. Data d => c (d -> b) -> d -> c b)
 -> (forall g. g -> c g) -> PArg' t -> c (PArg' t))
-> (forall (c :: * -> *).
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c (PArg' t))
-> (PArg' t -> Constr)
-> (PArg' t -> DataType)
-> (forall (t :: * -> *) (c :: * -> *).
    Typeable t =>
    (forall d. Data d => c (t d)) -> Maybe (c (PArg' t)))
-> (forall (t :: * -> * -> *) (c :: * -> *).
    Typeable t =>
    (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c (PArg' t)))
-> ((forall b. Data b => b -> b) -> PArg' t -> PArg' t)
-> (forall r r'.
    (r -> r' -> r)
    -> r -> (forall d. Data d => d -> r') -> PArg' t -> r)
-> (forall r r'.
    (r' -> r -> r)
    -> r -> (forall d. Data d => d -> r') -> PArg' t -> r)
-> (forall u. (forall d. Data d => d -> u) -> PArg' t -> [u])
-> (forall u. Int -> (forall d. Data d => d -> u) -> PArg' t -> u)
-> (forall (m :: * -> *).
    Monad m =>
    (forall d. Data d => d -> m d) -> PArg' t -> m (PArg' t))
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> PArg' t -> m (PArg' t))
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> PArg' t -> m (PArg' t))
-> Data (PArg' t)
PArg' t -> Constr
PArg' t -> DataType
(forall b. Data b => b -> b) -> PArg' t -> PArg' t
forall t. Data t => Typeable (PArg' t)
forall t. Data t => PArg' t -> Constr
forall t. Data t => PArg' t -> DataType
forall t.
Data t =>
(forall b. Data b => b -> b) -> PArg' t -> PArg' t
forall t u.
Data t =>
Int -> (forall d. Data d => d -> u) -> PArg' t -> u
forall t u.
Data t =>
(forall d. Data d => d -> u) -> PArg' t -> [u]
forall t r r'.
Data t =>
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> PArg' t -> r
forall t r r'.
Data t =>
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> PArg' t -> r
forall t (m :: * -> *).
(Data t, Monad m) =>
(forall d. Data d => d -> m d) -> PArg' t -> m (PArg' t)
forall t (m :: * -> *).
(Data t, MonadPlus m) =>
(forall d. Data d => d -> m d) -> PArg' t -> m (PArg' t)
forall t (c :: * -> *).
Data t =>
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c (PArg' t)
forall t (c :: * -> *).
Data t =>
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> PArg' t -> c (PArg' t)
forall t (t :: * -> *) (c :: * -> *).
(Data t, Typeable t) =>
(forall d. Data d => c (t d)) -> Maybe (c (PArg' t))
forall t (t :: * -> * -> *) (c :: * -> *).
(Data t, Typeable t) =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c (PArg' t))
forall a.
Typeable a =>
(forall (c :: * -> *).
 (forall d b. Data d => c (d -> b) -> d -> c b)
 -> (forall g. g -> c g) -> a -> c a)
-> (forall (c :: * -> *).
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c a)
-> (a -> Constr)
-> (a -> DataType)
-> (forall (t :: * -> *) (c :: * -> *).
    Typeable t =>
    (forall d. Data d => c (t d)) -> Maybe (c a))
-> (forall (t :: * -> * -> *) (c :: * -> *).
    Typeable t =>
    (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c a))
-> ((forall b. Data b => b -> b) -> a -> a)
-> (forall r r'.
    (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall r r'.
    (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall u. (forall d. Data d => d -> u) -> a -> [u])
-> (forall u. Int -> (forall d. Data d => d -> u) -> a -> u)
-> (forall (m :: * -> *).
    Monad m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> Data a
forall u. Int -> (forall d. Data d => d -> u) -> PArg' t -> u
forall u. (forall d. Data d => d -> u) -> PArg' t -> [u]
forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> PArg' t -> r
forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> PArg' t -> r
forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> PArg' t -> m (PArg' t)
forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> PArg' t -> m (PArg' t)
forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c (PArg' t)
forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> PArg' t -> c (PArg' t)
forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c (PArg' t))
forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c (PArg' t))
$cgfoldl :: forall t (c :: * -> *).
Data t =>
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> PArg' t -> c (PArg' t)
gfoldl :: forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> PArg' t -> c (PArg' t)
$cgunfold :: forall t (c :: * -> *).
Data t =>
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c (PArg' t)
gunfold :: forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c (PArg' t)
$ctoConstr :: forall t. Data t => PArg' t -> Constr
toConstr :: PArg' t -> Constr
$cdataTypeOf :: forall t. Data t => PArg' t -> DataType
dataTypeOf :: PArg' t -> DataType
$cdataCast1 :: forall t (t :: * -> *) (c :: * -> *).
(Data t, Typeable t) =>
(forall d. Data d => c (t d)) -> Maybe (c (PArg' t))
dataCast1 :: forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c (PArg' t))
$cdataCast2 :: forall t (t :: * -> * -> *) (c :: * -> *).
(Data t, Typeable t) =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c (PArg' t))
dataCast2 :: forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c (PArg' t))
$cgmapT :: forall t.
Data t =>
(forall b. Data b => b -> b) -> PArg' t -> PArg' t
gmapT :: (forall b. Data b => b -> b) -> PArg' t -> PArg' t
$cgmapQl :: forall t r r'.
Data t =>
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> PArg' t -> r
gmapQl :: forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> PArg' t -> r
$cgmapQr :: forall t r r'.
Data t =>
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> PArg' t -> r
gmapQr :: forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> PArg' t -> r
$cgmapQ :: forall t u.
Data t =>
(forall d. Data d => d -> u) -> PArg' t -> [u]
gmapQ :: forall u. (forall d. Data d => d -> u) -> PArg' t -> [u]
$cgmapQi :: forall t u.
Data t =>
Int -> (forall d. Data d => d -> u) -> PArg' t -> u
gmapQi :: forall u. Int -> (forall d. Data d => d -> u) -> PArg' t -> u
$cgmapM :: forall t (m :: * -> *).
(Data t, Monad m) =>
(forall d. Data d => d -> m d) -> PArg' t -> m (PArg' t)
gmapM :: forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> PArg' t -> m (PArg' t)
$cgmapMp :: forall t (m :: * -> *).
(Data t, MonadPlus m) =>
(forall d. Data d => d -> m d) -> PArg' t -> m (PArg' t)
gmapMp :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> PArg' t -> m (PArg' t)
$cgmapMo :: forall t (m :: * -> *).
(Data t, MonadPlus m) =>
(forall d. Data d => d -> m d) -> PArg' t -> m (PArg' t)
gmapMo :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> PArg' t -> m (PArg' t)
Data, (forall x. PArg' t -> Rep (PArg' t) x)
-> (forall x. Rep (PArg' t) x -> PArg' t) -> Generic (PArg' t)
forall x. Rep (PArg' t) x -> PArg' t
forall x. PArg' t -> Rep (PArg' t) x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
forall t x. Rep (PArg' t) x -> PArg' t
forall t x. PArg' t -> Rep (PArg' t) x
$cfrom :: forall t x. PArg' t -> Rep (PArg' t) x
from :: forall x. PArg' t -> Rep (PArg' t) x
$cto :: forall t x. Rep (PArg' t) x -> PArg' t
to :: forall x. Rep (PArg' t) x -> PArg' t
Generic, Typeable)

data ArgOpt = AlwaysShow
            | HideDisplay
            | InaccessibleArg
            | UnknownImp
            deriving (Int -> ArgOpt -> ShowS
[ArgOpt] -> ShowS
ArgOpt -> String
(Int -> ArgOpt -> ShowS)
-> (ArgOpt -> String) -> ([ArgOpt] -> ShowS) -> Show ArgOpt
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> ArgOpt -> ShowS
showsPrec :: Int -> ArgOpt -> ShowS
$cshow :: ArgOpt -> String
show :: ArgOpt -> String
$cshowList :: [ArgOpt] -> ShowS
showList :: [ArgOpt] -> ShowS
Show, ArgOpt -> ArgOpt -> Bool
(ArgOpt -> ArgOpt -> Bool)
-> (ArgOpt -> ArgOpt -> Bool) -> Eq ArgOpt
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: ArgOpt -> ArgOpt -> Bool
== :: ArgOpt -> ArgOpt -> Bool
$c/= :: ArgOpt -> ArgOpt -> Bool
/= :: ArgOpt -> ArgOpt -> Bool
Eq, Eq ArgOpt
Eq ArgOpt =>
(ArgOpt -> ArgOpt -> Ordering)
-> (ArgOpt -> ArgOpt -> Bool)
-> (ArgOpt -> ArgOpt -> Bool)
-> (ArgOpt -> ArgOpt -> Bool)
-> (ArgOpt -> ArgOpt -> Bool)
-> (ArgOpt -> ArgOpt -> ArgOpt)
-> (ArgOpt -> ArgOpt -> ArgOpt)
-> Ord ArgOpt
ArgOpt -> ArgOpt -> Bool
ArgOpt -> ArgOpt -> Ordering
ArgOpt -> ArgOpt -> ArgOpt
forall a.
Eq a =>
(a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
$ccompare :: ArgOpt -> ArgOpt -> Ordering
compare :: ArgOpt -> ArgOpt -> Ordering
$c< :: ArgOpt -> ArgOpt -> Bool
< :: ArgOpt -> ArgOpt -> Bool
$c<= :: ArgOpt -> ArgOpt -> Bool
<= :: ArgOpt -> ArgOpt -> Bool
$c> :: ArgOpt -> ArgOpt -> Bool
> :: ArgOpt -> ArgOpt -> Bool
$c>= :: ArgOpt -> ArgOpt -> Bool
>= :: ArgOpt -> ArgOpt -> Bool
$cmax :: ArgOpt -> ArgOpt -> ArgOpt
max :: ArgOpt -> ArgOpt -> ArgOpt
$cmin :: ArgOpt -> ArgOpt -> ArgOpt
min :: ArgOpt -> ArgOpt -> ArgOpt
Ord, Typeable ArgOpt
Typeable ArgOpt =>
(forall (c :: * -> *).
 (forall d b. Data d => c (d -> b) -> d -> c b)
 -> (forall g. g -> c g) -> ArgOpt -> c ArgOpt)
-> (forall (c :: * -> *).
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c ArgOpt)
-> (ArgOpt -> Constr)
-> (ArgOpt -> DataType)
-> (forall (t :: * -> *) (c :: * -> *).
    Typeable t =>
    (forall d. Data d => c (t d)) -> Maybe (c ArgOpt))
-> (forall (t :: * -> * -> *) (c :: * -> *).
    Typeable t =>
    (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c ArgOpt))
-> ((forall b. Data b => b -> b) -> ArgOpt -> ArgOpt)
-> (forall r r'.
    (r -> r' -> r)
    -> r -> (forall d. Data d => d -> r') -> ArgOpt -> r)
-> (forall r r'.
    (r' -> r -> r)
    -> r -> (forall d. Data d => d -> r') -> ArgOpt -> r)
-> (forall u. (forall d. Data d => d -> u) -> ArgOpt -> [u])
-> (forall u. Int -> (forall d. Data d => d -> u) -> ArgOpt -> u)
-> (forall (m :: * -> *).
    Monad m =>
    (forall d. Data d => d -> m d) -> ArgOpt -> m ArgOpt)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> ArgOpt -> m ArgOpt)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> ArgOpt -> m ArgOpt)
-> Data ArgOpt
ArgOpt -> Constr
ArgOpt -> DataType
(forall b. Data b => b -> b) -> ArgOpt -> ArgOpt
forall a.
Typeable a =>
(forall (c :: * -> *).
 (forall d b. Data d => c (d -> b) -> d -> c b)
 -> (forall g. g -> c g) -> a -> c a)
-> (forall (c :: * -> *).
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c a)
-> (a -> Constr)
-> (a -> DataType)
-> (forall (t :: * -> *) (c :: * -> *).
    Typeable t =>
    (forall d. Data d => c (t d)) -> Maybe (c a))
-> (forall (t :: * -> * -> *) (c :: * -> *).
    Typeable t =>
    (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c a))
-> ((forall b. Data b => b -> b) -> a -> a)
-> (forall r r'.
    (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall r r'.
    (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall u. (forall d. Data d => d -> u) -> a -> [u])
-> (forall u. Int -> (forall d. Data d => d -> u) -> a -> u)
-> (forall (m :: * -> *).
    Monad m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> Data a
forall u. Int -> (forall d. Data d => d -> u) -> ArgOpt -> u
forall u. (forall d. Data d => d -> u) -> ArgOpt -> [u]
forall r r'.
(r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> ArgOpt -> r
forall r r'.
(r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> ArgOpt -> r
forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> ArgOpt -> m ArgOpt
forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> ArgOpt -> m ArgOpt
forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c ArgOpt
forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> ArgOpt -> c ArgOpt
forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c ArgOpt)
forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c ArgOpt)
$cgfoldl :: forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> ArgOpt -> c ArgOpt
gfoldl :: forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> ArgOpt -> c ArgOpt
$cgunfold :: forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c ArgOpt
gunfold :: forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c ArgOpt
$ctoConstr :: ArgOpt -> Constr
toConstr :: ArgOpt -> Constr
$cdataTypeOf :: ArgOpt -> DataType
dataTypeOf :: ArgOpt -> DataType
$cdataCast1 :: forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c ArgOpt)
dataCast1 :: forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c ArgOpt)
$cdataCast2 :: forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c ArgOpt)
dataCast2 :: forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c ArgOpt)
$cgmapT :: (forall b. Data b => b -> b) -> ArgOpt -> ArgOpt
gmapT :: (forall b. Data b => b -> b) -> ArgOpt -> ArgOpt
$cgmapQl :: forall r r'.
(r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> ArgOpt -> r
gmapQl :: forall r r'.
(r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> ArgOpt -> r
$cgmapQr :: forall r r'.
(r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> ArgOpt -> r
gmapQr :: forall r r'.
(r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> ArgOpt -> r
$cgmapQ :: forall u. (forall d. Data d => d -> u) -> ArgOpt -> [u]
gmapQ :: forall u. (forall d. Data d => d -> u) -> ArgOpt -> [u]
$cgmapQi :: forall u. Int -> (forall d. Data d => d -> u) -> ArgOpt -> u
gmapQi :: forall u. Int -> (forall d. Data d => d -> u) -> ArgOpt -> u
$cgmapM :: forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> ArgOpt -> m ArgOpt
gmapM :: forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> ArgOpt -> m ArgOpt
$cgmapMp :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> ArgOpt -> m ArgOpt
gmapMp :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> ArgOpt -> m ArgOpt
$cgmapMo :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> ArgOpt -> m ArgOpt
gmapMo :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> ArgOpt -> m ArgOpt
Data, (forall x. ArgOpt -> Rep ArgOpt x)
-> (forall x. Rep ArgOpt x -> ArgOpt) -> Generic ArgOpt
forall x. Rep ArgOpt x -> ArgOpt
forall x. ArgOpt -> Rep ArgOpt x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cfrom :: forall x. ArgOpt -> Rep ArgOpt x
from :: forall x. ArgOpt -> Rep ArgOpt x
$cto :: forall x. Rep ArgOpt x -> ArgOpt
to :: forall x. Rep ArgOpt x -> ArgOpt
Generic, Typeable)

instance Sized a => Sized (PArg' a) where
  size :: PArg' a -> Int
size (PImp Int
p Bool
_ [ArgOpt]
l Name
nm a
trm)            = Int
1 Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Name -> Int
forall a. Sized a => a -> Int
size Name
nm Int -> Int -> Int
forall a. Num a => a -> a -> a
+ a -> Int
forall a. Sized a => a -> Int
size a
trm
  size (PExp Int
p [ArgOpt]
l Name
nm a
trm)              = Int
1 Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Name -> Int
forall a. Sized a => a -> Int
size Name
nm Int -> Int -> Int
forall a. Num a => a -> a -> a
+ a -> Int
forall a. Sized a => a -> Int
size a
trm
  size (PConstraint Int
p [ArgOpt]
l Name
nm a
trm)       = Int
1 Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Name -> Int
forall a. Sized a => a -> Int
size Name
nm Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Name -> Int
forall a. Sized a => a -> Int
size Name
nm  Int -> Int -> Int
forall a. Num a => a -> a -> a
+  a -> Int
forall a. Sized a => a -> Int
size a
trm
  size (PTacImplicit Int
p [ArgOpt]
l Name
nm a
scr a
trm)  = Int
1 Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Name -> Int
forall a. Sized a => a -> Int
size Name
nm Int -> Int -> Int
forall a. Num a => a -> a -> a
+ a -> Int
forall a. Sized a => a -> Int
size a
scr Int -> Int -> Int
forall a. Num a => a -> a -> a
+ a -> Int
forall a. Sized a => a -> Int
size a
trm

{-!
deriving instance Binary PArg'
!-}

pimp :: Name -> t -> Bool -> PArg' t
pimp Name
n t
t Bool
mach = Int -> Bool -> [ArgOpt] -> Name -> t -> PArg' t
forall t. Int -> Bool -> [ArgOpt] -> Name -> t -> PArg' t
PImp Int
1 Bool
mach [] Name
n t
t
pexp :: t -> PArg' t
pexp t
t        = Int -> [ArgOpt] -> Name -> t -> PArg' t
forall t. Int -> [ArgOpt] -> Name -> t -> PArg' t
PExp Int
1 [] (Int -> String -> Name
sMN Int
0 String
"arg") t
t
pconst :: t -> PArg' t
pconst t
t      = Int -> [ArgOpt] -> Name -> t -> PArg' t
forall t. Int -> [ArgOpt] -> Name -> t -> PArg' t
PConstraint Int
1 [] (Int -> String -> Name
sMN Int
0 String
"carg") t
t
ptacimp :: Name -> t -> t -> PArg' t
ptacimp Name
n t
s t
t = Int -> [ArgOpt] -> Name -> t -> t -> PArg' t
forall t. Int -> [ArgOpt] -> Name -> t -> t -> PArg' t
PTacImplicit Int
2 [] Name
n t
s t
t

type PArg = PArg' PTerm

-- | Get the highest FC in a term, if one exists
highestFC :: PTerm -> Maybe FC
highestFC :: PTerm -> Maybe FC
highestFC (PQuote Raw
_)              = Maybe FC
forall a. Maybe a
Nothing
highestFC (PRef FC
fc [FC]
_ Name
_)           = FC -> Maybe FC
forall a. a -> Maybe a
Just FC
fc
highestFC (PInferRef FC
fc [FC]
_ Name
_)      = FC -> Maybe FC
forall a. a -> Maybe a
Just FC
fc
highestFC (PPatvar FC
fc Name
_)          = FC -> Maybe FC
forall a. a -> Maybe a
Just FC
fc
highestFC (PLam FC
fc Name
_ FC
_ PTerm
_ PTerm
_)       = FC -> Maybe FC
forall a. a -> Maybe a
Just FC
fc
highestFC (PPi Plicity
_ Name
_ FC
_ PTerm
_ PTerm
_)         = Maybe FC
forall a. Maybe a
Nothing
highestFC (PLet FC
fc RigCount
_ Name
_ FC
_ PTerm
_ PTerm
_ PTerm
_)   = FC -> Maybe FC
forall a. a -> Maybe a
Just FC
fc
highestFC (PTyped PTerm
tm PTerm
ty)          = PTerm -> Maybe FC
highestFC PTerm
tm Maybe FC -> Maybe FC -> Maybe FC
forall a. Maybe a -> Maybe a -> Maybe a
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> PTerm -> Maybe FC
highestFC PTerm
ty
highestFC (PApp FC
fc PTerm
_ [PArg]
_)           = FC -> Maybe FC
forall a. a -> Maybe a
Just FC
fc
highestFC (PAppBind FC
fc PTerm
_ [PArg]
_)       = FC -> Maybe FC
forall a. a -> Maybe a
Just FC
fc
highestFC (PMatchApp FC
fc Name
_)        = FC -> Maybe FC
forall a. a -> Maybe a
Just FC
fc
highestFC (PCase FC
fc PTerm
_ [(PTerm, PTerm)]
_)          = FC -> Maybe FC
forall a. a -> Maybe a
Just FC
fc
highestFC (PIfThenElse FC
fc PTerm
_ PTerm
_ PTerm
_)  = FC -> Maybe FC
forall a. a -> Maybe a
Just FC
fc
highestFC (PTrue FC
fc PunInfo
_)            = FC -> Maybe FC
forall a. a -> Maybe a
Just FC
fc
highestFC (PResolveTC FC
fc)         = FC -> Maybe FC
forall a. a -> Maybe a
Just FC
fc
highestFC (PRewrite FC
fc Maybe Name
_ PTerm
_ PTerm
_ Maybe PTerm
_)   = FC -> Maybe FC
forall a. a -> Maybe a
Just FC
fc
highestFC (PPair FC
fc [FC]
_ PunInfo
_ PTerm
_ PTerm
_)      = FC -> Maybe FC
forall a. a -> Maybe a
Just FC
fc
highestFC (PDPair FC
fc [FC]
_ PunInfo
_ PTerm
_ PTerm
_ PTerm
_)   = FC -> Maybe FC
forall a. a -> Maybe a
Just FC
fc
highestFC (PAs FC
fc Name
_ PTerm
_)            = FC -> Maybe FC
forall a. a -> Maybe a
Just FC
fc
highestFC (PAlternative [(Name, Name)]
_ PAltType
_ [PTerm]
args) =
  case (PTerm -> Maybe FC) -> [PTerm] -> [FC]
forall a b. (a -> Maybe b) -> [a] -> [b]
mapMaybe PTerm -> Maybe FC
highestFC [PTerm]
args of
    [] -> Maybe FC
forall a. Maybe a
Nothing
    (FC
fc:[FC]
_) -> FC -> Maybe FC
forall a. a -> Maybe a
Just FC
fc
highestFC (PHidden PTerm
_)             = Maybe FC
forall a. Maybe a
Nothing
highestFC (PType FC
fc)              = FC -> Maybe FC
forall a. a -> Maybe a
Just FC
fc
highestFC (PUniverse FC
_ Universe
_)         = Maybe FC
forall a. Maybe a
Nothing
highestFC (PGoal FC
fc PTerm
_ Name
_ PTerm
_)        = FC -> Maybe FC
forall a. a -> Maybe a
Just FC
fc
highestFC (PConstant FC
fc Const
_)        = FC -> Maybe FC
forall a. a -> Maybe a
Just FC
fc
highestFC PTerm
Placeholder             = Maybe FC
forall a. Maybe a
Nothing
highestFC (PDoBlock [PDo]
lines) =
  case (PDo -> FC) -> [PDo] -> [FC]
forall a b. (a -> b) -> [a] -> [b]
map PDo -> FC
forall {t}. PDo' t -> FC
getDoFC [PDo]
lines of
    [] -> Maybe FC
forall a. Maybe a
Nothing
    (FC
fc:[FC]
_) -> FC -> Maybe FC
forall a. a -> Maybe a
Just FC
fc
  where
    getDoFC :: PDo' t -> FC
getDoFC (DoExp FC
fc t
t)          = FC
fc
    getDoFC (DoBind FC
fc Name
nm FC
nfc t
t)  = FC
fc
    getDoFC (DoBindP FC
fc t
l t
r [(t, t)]
alts) = FC
fc
    getDoFC (DoLet FC
fc RigCount
rc Name
nm FC
nfc t
l t
r) = FC
fc
    getDoFC (DoLetP FC
fc t
l t
r [(t, t)]
alts)  = FC
fc
    getDoFC (DoRewrite FC
fc t
h)      = FC
fc

highestFC (PIdiom FC
fc PTerm
_)           = FC -> Maybe FC
forall a. a -> Maybe a
Just FC
fc
highestFC (PMetavar FC
fc Name
_)         = FC -> Maybe FC
forall a. a -> Maybe a
Just FC
fc
highestFC (PProof [PTactic]
_)              = Maybe FC
forall a. Maybe a
Nothing
highestFC (PTactics [PTactic]
_)            = Maybe FC
forall a. Maybe a
Nothing
highestFC (PElabError Err
_)          = Maybe FC
forall a. Maybe a
Nothing
highestFC PTerm
PImpossible             = Maybe FC
forall a. Maybe a
Nothing
highestFC (PCoerced PTerm
tm)           = PTerm -> Maybe FC
highestFC PTerm
tm
highestFC (PDisamb [[Text]]
_ PTerm
opts)        = PTerm -> Maybe FC
highestFC PTerm
opts
highestFC (PUnifyLog PTerm
tm)          = PTerm -> Maybe FC
highestFC PTerm
tm
highestFC (PNoImplicits PTerm
tm)       = PTerm -> Maybe FC
highestFC PTerm
tm
highestFC (PQuasiquote PTerm
_ Maybe PTerm
_)       = Maybe FC
forall a. Maybe a
Nothing
highestFC (PUnquote PTerm
tm)           = PTerm -> Maybe FC
highestFC PTerm
tm
highestFC (PQuoteName Name
_ Bool
_ FC
fc)     = FC -> Maybe FC
forall a. a -> Maybe a
Just FC
fc
highestFC (PRunElab FC
fc PTerm
_ [String]
_)       = FC -> Maybe FC
forall a. a -> Maybe a
Just FC
fc
highestFC (PConstSugar FC
fc PTerm
_)      = FC -> Maybe FC
forall a. a -> Maybe a
Just FC
fc
highestFC (PAppImpl PTerm
t [ImplicitInfo]
_)          = PTerm -> Maybe FC
highestFC PTerm
t

-- Interface data

data InterfaceInfo = CI {
    InterfaceInfo -> Name
implementationCtorName             :: Name
  , InterfaceInfo -> [(Name, (Bool, [FnOpt], PTerm))]
interface_methods                  :: [(Name, (Bool, FnOpts, PTerm))] -- ^ flag whether it's a "data" method
  , InterfaceInfo -> [(Name, (Name, PDecl' PTerm))]
interface_defaults                 :: [(Name, (Name, PDecl))]         -- ^ method name -> default impl
  , InterfaceInfo -> [PDecl' PTerm]
interface_default_super_interfaces :: [PDecl]
  , InterfaceInfo -> [Name]
interface_impparams                :: [Name]
  , InterfaceInfo -> [Name]
interface_params                   :: [Name]
  , InterfaceInfo -> [PTerm]
interface_constraints              :: [PTerm]
  , InterfaceInfo -> [(Name, Bool)]
interface_implementations          :: [(Name, Bool)] -- ^ the Bool is whether to include in implementation search, so named implementations are excluded
  , InterfaceInfo -> [Int]
interface_determiners              :: [Int]
  } deriving (Int -> InterfaceInfo -> ShowS
[InterfaceInfo] -> ShowS
InterfaceInfo -> String
(Int -> InterfaceInfo -> ShowS)
-> (InterfaceInfo -> String)
-> ([InterfaceInfo] -> ShowS)
-> Show InterfaceInfo
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> InterfaceInfo -> ShowS
showsPrec :: Int -> InterfaceInfo -> ShowS
$cshow :: InterfaceInfo -> String
show :: InterfaceInfo -> String
$cshowList :: [InterfaceInfo] -> ShowS
showList :: [InterfaceInfo] -> ShowS
Show, (forall x. InterfaceInfo -> Rep InterfaceInfo x)
-> (forall x. Rep InterfaceInfo x -> InterfaceInfo)
-> Generic InterfaceInfo
forall x. Rep InterfaceInfo x -> InterfaceInfo
forall x. InterfaceInfo -> Rep InterfaceInfo x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cfrom :: forall x. InterfaceInfo -> Rep InterfaceInfo x
from :: forall x. InterfaceInfo -> Rep InterfaceInfo x
$cto :: forall x. Rep InterfaceInfo x -> InterfaceInfo
to :: forall x. Rep InterfaceInfo x -> InterfaceInfo
Generic)
{-!
deriving instance Binary InterfaceInfo
!-}

-- Record data
data RecordInfo = RI {
    RecordInfo -> [(Name, PTerm)]
record_parameters  :: [(Name,PTerm)]
  , RecordInfo -> Name
record_constructor :: Name
  , RecordInfo -> [Name]
record_projections :: [Name]
  } deriving (Int -> RecordInfo -> ShowS
[RecordInfo] -> ShowS
RecordInfo -> String
(Int -> RecordInfo -> ShowS)
-> (RecordInfo -> String)
-> ([RecordInfo] -> ShowS)
-> Show RecordInfo
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> RecordInfo -> ShowS
showsPrec :: Int -> RecordInfo -> ShowS
$cshow :: RecordInfo -> String
show :: RecordInfo -> String
$cshowList :: [RecordInfo] -> ShowS
showList :: [RecordInfo] -> ShowS
Show, (forall x. RecordInfo -> Rep RecordInfo x)
-> (forall x. Rep RecordInfo x -> RecordInfo) -> Generic RecordInfo
forall x. Rep RecordInfo x -> RecordInfo
forall x. RecordInfo -> Rep RecordInfo x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cfrom :: forall x. RecordInfo -> Rep RecordInfo x
from :: forall x. RecordInfo -> Rep RecordInfo x
$cto :: forall x. Rep RecordInfo x -> RecordInfo
to :: forall x. Rep RecordInfo x -> RecordInfo
Generic)

-- Type inference data

data TIData = TIPartial         -- ^ a function with a partially defined type
            | TISolution [Term] -- ^ possible solutions to a metavariable in a type
    deriving (Int -> TIData -> ShowS
[TIData] -> ShowS
TIData -> String
(Int -> TIData -> ShowS)
-> (TIData -> String) -> ([TIData] -> ShowS) -> Show TIData
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> TIData -> ShowS
showsPrec :: Int -> TIData -> ShowS
$cshow :: TIData -> String
show :: TIData -> String
$cshowList :: [TIData] -> ShowS
showList :: [TIData] -> ShowS
Show, (forall x. TIData -> Rep TIData x)
-> (forall x. Rep TIData x -> TIData) -> Generic TIData
forall x. Rep TIData x -> TIData
forall x. TIData -> Rep TIData x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cfrom :: forall x. TIData -> Rep TIData x
from :: forall x. TIData -> Rep TIData x
$cto :: forall x. Rep TIData x -> TIData
to :: forall x. Rep TIData x -> TIData
Generic)

-- | Miscellaneous information about functions
data FnInfo = FnInfo { FnInfo -> [Int]
fn_params :: [Int] }
    deriving (Int -> FnInfo -> ShowS
[FnInfo] -> ShowS
FnInfo -> String
(Int -> FnInfo -> ShowS)
-> (FnInfo -> String) -> ([FnInfo] -> ShowS) -> Show FnInfo
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> FnInfo -> ShowS
showsPrec :: Int -> FnInfo -> ShowS
$cshow :: FnInfo -> String
show :: FnInfo -> String
$cshowList :: [FnInfo] -> ShowS
showList :: [FnInfo] -> ShowS
Show, (forall x. FnInfo -> Rep FnInfo x)
-> (forall x. Rep FnInfo x -> FnInfo) -> Generic FnInfo
forall x. Rep FnInfo x -> FnInfo
forall x. FnInfo -> Rep FnInfo x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cfrom :: forall x. FnInfo -> Rep FnInfo x
from :: forall x. FnInfo -> Rep FnInfo x
$cto :: forall x. Rep FnInfo x -> FnInfo
to :: forall x. Rep FnInfo x -> FnInfo
Generic)
{-!
deriving instance Binary FnInfo
!-}

data OptInfo = Optimise {
    OptInfo -> [(Int, Name)]
inaccessible :: [(Int,Name)]  -- includes names for error reporting
  , OptInfo -> Bool
detaggable :: Bool
  , OptInfo -> [Int]
forceable :: [Int] -- argument positions which are forced by other values
  } deriving (Int -> OptInfo -> ShowS
[OptInfo] -> ShowS
OptInfo -> String
(Int -> OptInfo -> ShowS)
-> (OptInfo -> String) -> ([OptInfo] -> ShowS) -> Show OptInfo
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> OptInfo -> ShowS
showsPrec :: Int -> OptInfo -> ShowS
$cshow :: OptInfo -> String
show :: OptInfo -> String
$cshowList :: [OptInfo] -> ShowS
showList :: [OptInfo] -> ShowS
Show, (forall x. OptInfo -> Rep OptInfo x)
-> (forall x. Rep OptInfo x -> OptInfo) -> Generic OptInfo
forall x. Rep OptInfo x -> OptInfo
forall x. OptInfo -> Rep OptInfo x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cfrom :: forall x. OptInfo -> Rep OptInfo x
from :: forall x. OptInfo -> Rep OptInfo x
$cto :: forall x. Rep OptInfo x -> OptInfo
to :: forall x. Rep OptInfo x -> OptInfo
Generic)
{-!
deriving instance Binary OptInfo
!-}

-- | Syntactic sugar info
data DSL' t = DSL {
    forall t. DSL' t -> t
dsl_bind    :: t
  , forall t. DSL' t -> t
dsl_apply   :: t
  , forall t. DSL' t -> t
dsl_pure    :: t
  , forall t. DSL' t -> Maybe t
dsl_var     :: Maybe t
  , forall t. DSL' t -> Maybe t
index_first :: Maybe t
  , forall t. DSL' t -> Maybe t
index_next  :: Maybe t
  , forall t. DSL' t -> Maybe t
dsl_lambda  :: Maybe t
  , forall t. DSL' t -> Maybe t
dsl_let     :: Maybe t
  , forall t. DSL' t -> Maybe t
dsl_pi      :: Maybe t
  } deriving (Int -> DSL' t -> ShowS
[DSL' t] -> ShowS
DSL' t -> String
(Int -> DSL' t -> ShowS)
-> (DSL' t -> String) -> ([DSL' t] -> ShowS) -> Show (DSL' t)
forall t. Show t => Int -> DSL' t -> ShowS
forall t. Show t => [DSL' t] -> ShowS
forall t. Show t => DSL' t -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: forall t. Show t => Int -> DSL' t -> ShowS
showsPrec :: Int -> DSL' t -> ShowS
$cshow :: forall t. Show t => DSL' t -> String
show :: DSL' t -> String
$cshowList :: forall t. Show t => [DSL' t] -> ShowS
showList :: [DSL' t] -> ShowS
Show, (forall a b. (a -> b) -> DSL' a -> DSL' b)
-> (forall a b. a -> DSL' b -> DSL' a) -> Functor DSL'
forall a b. a -> DSL' b -> DSL' a
forall a b. (a -> b) -> DSL' a -> DSL' b
forall (f :: * -> *).
(forall a b. (a -> b) -> f a -> f b)
-> (forall a b. a -> f b -> f a) -> Functor f
$cfmap :: forall a b. (a -> b) -> DSL' a -> DSL' b
fmap :: forall a b. (a -> b) -> DSL' a -> DSL' b
$c<$ :: forall a b. a -> DSL' b -> DSL' a
<$ :: forall a b. a -> DSL' b -> DSL' a
Functor, (forall x. DSL' t -> Rep (DSL' t) x)
-> (forall x. Rep (DSL' t) x -> DSL' t) -> Generic (DSL' t)
forall x. Rep (DSL' t) x -> DSL' t
forall x. DSL' t -> Rep (DSL' t) x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
forall t x. Rep (DSL' t) x -> DSL' t
forall t x. DSL' t -> Rep (DSL' t) x
$cfrom :: forall t x. DSL' t -> Rep (DSL' t) x
from :: forall x. DSL' t -> Rep (DSL' t) x
$cto :: forall t x. Rep (DSL' t) x -> DSL' t
to :: forall x. Rep (DSL' t) x -> DSL' t
Generic)
{-!
deriving instance Binary DSL'
!-}

type DSL = DSL' PTerm

data SynContext = PatternSyntax
                | TermSyntax
                | AnySyntax
    deriving (Int -> SynContext -> ShowS
[SynContext] -> ShowS
SynContext -> String
(Int -> SynContext -> ShowS)
-> (SynContext -> String)
-> ([SynContext] -> ShowS)
-> Show SynContext
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> SynContext -> ShowS
showsPrec :: Int -> SynContext -> ShowS
$cshow :: SynContext -> String
show :: SynContext -> String
$cshowList :: [SynContext] -> ShowS
showList :: [SynContext] -> ShowS
Show, (forall x. SynContext -> Rep SynContext x)
-> (forall x. Rep SynContext x -> SynContext) -> Generic SynContext
forall x. Rep SynContext x -> SynContext
forall x. SynContext -> Rep SynContext x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cfrom :: forall x. SynContext -> Rep SynContext x
from :: forall x. SynContext -> Rep SynContext x
$cto :: forall x. Rep SynContext x -> SynContext
to :: forall x. Rep SynContext x -> SynContext
Generic)
{-!
deriving instance Binary SynContext
!-}

data Syntax = Rule [SSymbol] PTerm SynContext
            | DeclRule [SSymbol] [PDecl]
    deriving (Int -> Syntax -> ShowS
[Syntax] -> ShowS
Syntax -> String
(Int -> Syntax -> ShowS)
-> (Syntax -> String) -> ([Syntax] -> ShowS) -> Show Syntax
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> Syntax -> ShowS
showsPrec :: Int -> Syntax -> ShowS
$cshow :: Syntax -> String
show :: Syntax -> String
$cshowList :: [Syntax] -> ShowS
showList :: [Syntax] -> ShowS
Show, (forall x. Syntax -> Rep Syntax x)
-> (forall x. Rep Syntax x -> Syntax) -> Generic Syntax
forall x. Rep Syntax x -> Syntax
forall x. Syntax -> Rep Syntax x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cfrom :: forall x. Syntax -> Rep Syntax x
from :: forall x. Syntax -> Rep Syntax x
$cto :: forall x. Rep Syntax x -> Syntax
to :: forall x. Rep Syntax x -> Syntax
Generic)

syntaxNames :: Syntax -> [Name]
syntaxNames :: Syntax -> [Name]
syntaxNames (Rule [SSymbol]
syms PTerm
_ SynContext
_) = (SSymbol -> Maybe Name) -> [SSymbol] -> [Name]
forall a b. (a -> Maybe b) -> [a] -> [b]
mapMaybe SSymbol -> Maybe Name
ename [SSymbol]
syms
           where ename :: SSymbol -> Maybe Name
ename (Keyword Name
n)  = Name -> Maybe Name
forall a. a -> Maybe a
Just Name
n
                 ename SSymbol
_            = Maybe Name
forall a. Maybe a
Nothing
syntaxNames (DeclRule [SSymbol]
syms [PDecl' PTerm]
_) = (SSymbol -> Maybe Name) -> [SSymbol] -> [Name]
forall a b. (a -> Maybe b) -> [a] -> [b]
mapMaybe SSymbol -> Maybe Name
ename [SSymbol]
syms
           where ename :: SSymbol -> Maybe Name
ename (Keyword Name
n)  = Name -> Maybe Name
forall a. a -> Maybe a
Just Name
n
                 ename SSymbol
_            = Maybe Name
forall a. Maybe a
Nothing

syntaxSymbols :: Syntax -> [SSymbol]
syntaxSymbols :: Syntax -> [SSymbol]
syntaxSymbols (Rule [SSymbol]
ss PTerm
_ SynContext
_) = [SSymbol]
ss
syntaxSymbols (DeclRule [SSymbol]
ss [PDecl' PTerm]
_) = [SSymbol]
ss
{-!
deriving instance Binary Syntax
!-}

data SSymbol = Keyword Name
             | Symbol String
             | Binding Name
             | Expr Name
             | SimpleExpr Name
    deriving (Int -> SSymbol -> ShowS
[SSymbol] -> ShowS
SSymbol -> String
(Int -> SSymbol -> ShowS)
-> (SSymbol -> String) -> ([SSymbol] -> ShowS) -> Show SSymbol
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> SSymbol -> ShowS
showsPrec :: Int -> SSymbol -> ShowS
$cshow :: SSymbol -> String
show :: SSymbol -> String
$cshowList :: [SSymbol] -> ShowS
showList :: [SSymbol] -> ShowS
Show, SSymbol -> SSymbol -> Bool
(SSymbol -> SSymbol -> Bool)
-> (SSymbol -> SSymbol -> Bool) -> Eq SSymbol
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: SSymbol -> SSymbol -> Bool
== :: SSymbol -> SSymbol -> Bool
$c/= :: SSymbol -> SSymbol -> Bool
/= :: SSymbol -> SSymbol -> Bool
Eq, (forall x. SSymbol -> Rep SSymbol x)
-> (forall x. Rep SSymbol x -> SSymbol) -> Generic SSymbol
forall x. Rep SSymbol x -> SSymbol
forall x. SSymbol -> Rep SSymbol x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cfrom :: forall x. SSymbol -> Rep SSymbol x
from :: forall x. SSymbol -> Rep SSymbol x
$cto :: forall x. Rep SSymbol x -> SSymbol
to :: forall x. Rep SSymbol x -> SSymbol
Generic)


{-!
deriving instance Binary SSymbol
!-}

newtype SyntaxRules = SyntaxRules { SyntaxRules -> [Syntax]
syntaxRulesList :: [Syntax] }
  deriving (forall x. SyntaxRules -> Rep SyntaxRules x)
-> (forall x. Rep SyntaxRules x -> SyntaxRules)
-> Generic SyntaxRules
forall x. Rep SyntaxRules x -> SyntaxRules
forall x. SyntaxRules -> Rep SyntaxRules x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cfrom :: forall x. SyntaxRules -> Rep SyntaxRules x
from :: forall x. SyntaxRules -> Rep SyntaxRules x
$cto :: forall x. Rep SyntaxRules x -> SyntaxRules
to :: forall x. Rep SyntaxRules x -> SyntaxRules
Generic

emptySyntaxRules :: SyntaxRules
emptySyntaxRules :: SyntaxRules
emptySyntaxRules = [Syntax] -> SyntaxRules
SyntaxRules []

updateSyntaxRules :: [Syntax] -> SyntaxRules -> SyntaxRules
updateSyntaxRules :: [Syntax] -> SyntaxRules -> SyntaxRules
updateSyntaxRules [Syntax]
rules (SyntaxRules [Syntax]
sr) = [Syntax] -> SyntaxRules
SyntaxRules [Syntax]
newRules
  where
    newRules :: [Syntax]
newRules = (Syntax -> Syntax -> Ordering) -> [Syntax] -> [Syntax]
forall a. (a -> a -> Ordering) -> [a] -> [a]
sortBy ([SSymbol] -> [SSymbol] -> Ordering
ruleSort ([SSymbol] -> [SSymbol] -> Ordering)
-> (Syntax -> [SSymbol]) -> Syntax -> Syntax -> Ordering
forall b c a. (b -> b -> c) -> (a -> b) -> a -> a -> c
`on` Syntax -> [SSymbol]
syntaxSymbols) ([Syntax]
rules [Syntax] -> [Syntax] -> [Syntax]
forall a. [a] -> [a] -> [a]
++ [Syntax]
sr)

    ruleSort :: [SSymbol] -> [SSymbol] -> Ordering
ruleSort [] []  = Ordering
EQ
    ruleSort [] [SSymbol]
_   = Ordering
LT
    ruleSort [SSymbol]
_ []   = Ordering
GT
    ruleSort (SSymbol
s1:[SSymbol]
ss1) (SSymbol
s2:[SSymbol]
ss2) =
      case SSymbol -> SSymbol -> Ordering
symCompare SSymbol
s1 SSymbol
s2 of
        Ordering
EQ -> [SSymbol] -> [SSymbol] -> Ordering
ruleSort [SSymbol]
ss1 [SSymbol]
ss2
        Ordering
r -> Ordering
r

    -- Better than creating Ord implementation for SSymbol since
    -- in general this ordering does not really make sense.
    symCompare :: SSymbol -> SSymbol -> Ordering
symCompare (Keyword Name
n1) (Keyword Name
n2)        = Name -> Name -> Ordering
forall a. Ord a => a -> a -> Ordering
compare Name
n1 Name
n2
    symCompare (Keyword Name
_) SSymbol
_                    = Ordering
LT
    symCompare (Symbol String
_) (Keyword Name
_)           = Ordering
GT
    symCompare (Symbol String
s1) (Symbol String
s2)          = String -> String -> Ordering
forall a. Ord a => a -> a -> Ordering
compare String
s1 String
s2
    symCompare (Symbol String
_) SSymbol
_                     = Ordering
LT
    symCompare (Binding Name
_) (Keyword Name
_)          = Ordering
GT
    symCompare (Binding Name
_) (Symbol String
_)           = Ordering
GT
    symCompare (Binding Name
b1) (Binding Name
b2)        = Name -> Name -> Ordering
forall a. Ord a => a -> a -> Ordering
compare Name
b1 Name
b2
    symCompare (Binding Name
_) SSymbol
_                    = Ordering
LT
    symCompare (Expr Name
_) (Keyword Name
_)             = Ordering
GT
    symCompare (Expr Name
_) (Symbol String
_)              = Ordering
GT
    symCompare (Expr Name
_) (Binding Name
_)             = Ordering
GT
    symCompare (Expr Name
e1) (Expr Name
e2)              = Name -> Name -> Ordering
forall a. Ord a => a -> a -> Ordering
compare Name
e1 Name
e2
    symCompare (Expr Name
_) SSymbol
_                       = Ordering
LT
    symCompare (SimpleExpr Name
_) (Keyword Name
_)       = Ordering
GT
    symCompare (SimpleExpr Name
_) (Symbol String
_)        = Ordering
GT
    symCompare (SimpleExpr Name
_) (Binding Name
_)       = Ordering
GT
    symCompare (SimpleExpr Name
_) (Expr Name
_)          = Ordering
GT
    symCompare (SimpleExpr Name
e1) (SimpleExpr Name
e2)  = Name -> Name -> Ordering
forall a. Ord a => a -> a -> Ordering
compare Name
e1 Name
e2

initDSL :: DSL
initDSL = PTerm
-> PTerm
-> PTerm
-> Maybe PTerm
-> Maybe PTerm
-> Maybe PTerm
-> Maybe PTerm
-> Maybe PTerm
-> Maybe PTerm
-> DSL
forall t.
t
-> t
-> t
-> Maybe t
-> Maybe t
-> Maybe t
-> Maybe t
-> Maybe t
-> Maybe t
-> DSL' t
DSL (FC -> [FC] -> Name -> PTerm
PRef FC
f [] (String -> Name
sUN String
">>="))
              (FC -> [FC] -> Name -> PTerm
PRef FC
f [] (String -> Name
sUN String
"<*>"))
              (FC -> [FC] -> Name -> PTerm
PRef FC
f [] (String -> Name
sUN String
"pure"))
              Maybe PTerm
forall a. Maybe a
Nothing
              Maybe PTerm
forall a. Maybe a
Nothing
              Maybe PTerm
forall a. Maybe a
Nothing
              Maybe PTerm
forall a. Maybe a
Nothing
              Maybe PTerm
forall a. Maybe a
Nothing
              Maybe PTerm
forall a. Maybe a
Nothing
  where f :: FC
f = String -> FC
fileFC String
"(builtin)"

data Using = UImplicit Name PTerm
           | UConstraint Name [Name]
    deriving (Int -> Using -> ShowS
[Using] -> ShowS
Using -> String
(Int -> Using -> ShowS)
-> (Using -> String) -> ([Using] -> ShowS) -> Show Using
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> Using -> ShowS
showsPrec :: Int -> Using -> ShowS
$cshow :: Using -> String
show :: Using -> String
$cshowList :: [Using] -> ShowS
showList :: [Using] -> ShowS
Show, Using -> Using -> Bool
(Using -> Using -> Bool) -> (Using -> Using -> Bool) -> Eq Using
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: Using -> Using -> Bool
== :: Using -> Using -> Bool
$c/= :: Using -> Using -> Bool
/= :: Using -> Using -> Bool
Eq, Typeable Using
Typeable Using =>
(forall (c :: * -> *).
 (forall d b. Data d => c (d -> b) -> d -> c b)
 -> (forall g. g -> c g) -> Using -> c Using)
-> (forall (c :: * -> *).
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c Using)
-> (Using -> Constr)
-> (Using -> DataType)
-> (forall (t :: * -> *) (c :: * -> *).
    Typeable t =>
    (forall d. Data d => c (t d)) -> Maybe (c Using))
-> (forall (t :: * -> * -> *) (c :: * -> *).
    Typeable t =>
    (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c Using))
-> ((forall b. Data b => b -> b) -> Using -> Using)
-> (forall r r'.
    (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> Using -> r)
-> (forall r r'.
    (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> Using -> r)
-> (forall u. (forall d. Data d => d -> u) -> Using -> [u])
-> (forall u. Int -> (forall d. Data d => d -> u) -> Using -> u)
-> (forall (m :: * -> *).
    Monad m =>
    (forall d. Data d => d -> m d) -> Using -> m Using)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> Using -> m Using)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> Using -> m Using)
-> Data Using
Using -> Constr
Using -> DataType
(forall b. Data b => b -> b) -> Using -> Using
forall a.
Typeable a =>
(forall (c :: * -> *).
 (forall d b. Data d => c (d -> b) -> d -> c b)
 -> (forall g. g -> c g) -> a -> c a)
-> (forall (c :: * -> *).
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c a)
-> (a -> Constr)
-> (a -> DataType)
-> (forall (t :: * -> *) (c :: * -> *).
    Typeable t =>
    (forall d. Data d => c (t d)) -> Maybe (c a))
-> (forall (t :: * -> * -> *) (c :: * -> *).
    Typeable t =>
    (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c a))
-> ((forall b. Data b => b -> b) -> a -> a)
-> (forall r r'.
    (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall r r'.
    (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall u. (forall d. Data d => d -> u) -> a -> [u])
-> (forall u. Int -> (forall d. Data d => d -> u) -> a -> u)
-> (forall (m :: * -> *).
    Monad m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> Data a
forall u. Int -> (forall d. Data d => d -> u) -> Using -> u
forall u. (forall d. Data d => d -> u) -> Using -> [u]
forall r r'.
(r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> Using -> r
forall r r'.
(r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> Using -> r
forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> Using -> m Using
forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> Using -> m Using
forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c Using
forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> Using -> c Using
forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c Using)
forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c Using)
$cgfoldl :: forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> Using -> c Using
gfoldl :: forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> Using -> c Using
$cgunfold :: forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c Using
gunfold :: forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c Using
$ctoConstr :: Using -> Constr
toConstr :: Using -> Constr
$cdataTypeOf :: Using -> DataType
dataTypeOf :: Using -> DataType
$cdataCast1 :: forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c Using)
dataCast1 :: forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c Using)
$cdataCast2 :: forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c Using)
dataCast2 :: forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c Using)
$cgmapT :: (forall b. Data b => b -> b) -> Using -> Using
gmapT :: (forall b. Data b => b -> b) -> Using -> Using
$cgmapQl :: forall r r'.
(r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> Using -> r
gmapQl :: forall r r'.
(r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> Using -> r
$cgmapQr :: forall r r'.
(r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> Using -> r
gmapQr :: forall r r'.
(r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> Using -> r
$cgmapQ :: forall u. (forall d. Data d => d -> u) -> Using -> [u]
gmapQ :: forall u. (forall d. Data d => d -> u) -> Using -> [u]
$cgmapQi :: forall u. Int -> (forall d. Data d => d -> u) -> Using -> u
gmapQi :: forall u. Int -> (forall d. Data d => d -> u) -> Using -> u
$cgmapM :: forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> Using -> m Using
gmapM :: forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> Using -> m Using
$cgmapMp :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> Using -> m Using
gmapMp :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> Using -> m Using
$cgmapMo :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> Using -> m Using
gmapMo :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> Using -> m Using
Data, (forall x. Using -> Rep Using x)
-> (forall x. Rep Using x -> Using) -> Generic Using
forall x. Rep Using x -> Using
forall x. Using -> Rep Using x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cfrom :: forall x. Using -> Rep Using x
from :: forall x. Using -> Rep Using x
$cto :: forall x. Rep Using x -> Using
to :: forall x. Rep Using x -> Using
Generic, Typeable)
{-!
deriving instance Binary Using
!-}

data SyntaxInfo = Syn {
    SyntaxInfo -> [Using]
using             :: [Using]
  , SyntaxInfo -> [(Name, PTerm)]
syn_params        :: [(Name, PTerm)]
  , SyntaxInfo -> [String]
syn_namespace     :: [String]
  , SyntaxInfo -> [Name]
no_imp            :: [Name]
  , SyntaxInfo -> [Name]
imp_methods       :: [Name]
  -- ^ interface methods. When expanding implicits, these should be
  -- expanded even under binders
  , SyntaxInfo -> Name -> Name
decoration        :: Name -> Name
  , SyntaxInfo -> Bool
inPattern         :: Bool
  , SyntaxInfo -> Bool
implicitAllowed   :: Bool
  , SyntaxInfo -> Bool
constraintAllowed :: Bool
  , SyntaxInfo -> Maybe Int
maxline           :: Maybe Int
  , SyntaxInfo -> Int
mut_nesting       :: Int
  , SyntaxInfo -> DSL
dsl_info          :: DSL
  , SyntaxInfo -> Int
syn_in_quasiquote :: Int
  , SyntaxInfo -> Bool
syn_toplevel      :: Bool
  , SyntaxInfo -> Bool
withAppAllowed    :: Bool
  } deriving (Int -> SyntaxInfo -> ShowS
[SyntaxInfo] -> ShowS
SyntaxInfo -> String
(Int -> SyntaxInfo -> ShowS)
-> (SyntaxInfo -> String)
-> ([SyntaxInfo] -> ShowS)
-> Show SyntaxInfo
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> SyntaxInfo -> ShowS
showsPrec :: Int -> SyntaxInfo -> ShowS
$cshow :: SyntaxInfo -> String
show :: SyntaxInfo -> String
$cshowList :: [SyntaxInfo] -> ShowS
showList :: [SyntaxInfo] -> ShowS
Show, (forall x. SyntaxInfo -> Rep SyntaxInfo x)
-> (forall x. Rep SyntaxInfo x -> SyntaxInfo) -> Generic SyntaxInfo
forall x. Rep SyntaxInfo x -> SyntaxInfo
forall x. SyntaxInfo -> Rep SyntaxInfo x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cfrom :: forall x. SyntaxInfo -> Rep SyntaxInfo x
from :: forall x. SyntaxInfo -> Rep SyntaxInfo x
$cto :: forall x. Rep SyntaxInfo x -> SyntaxInfo
to :: forall x. Rep SyntaxInfo x -> SyntaxInfo
Generic)
{-!
deriving instance Binary SyntaxInfo
!-}

defaultSyntax :: SyntaxInfo
defaultSyntax = [Using]
-> [(Name, PTerm)]
-> [String]
-> [Name]
-> [Name]
-> (Name -> Name)
-> Bool
-> Bool
-> Bool
-> Maybe Int
-> Int
-> DSL
-> Int
-> Bool
-> Bool
-> SyntaxInfo
Syn [] [] [] [] [] Name -> Name
forall a. a -> a
id Bool
False Bool
False Bool
False Maybe Int
forall a. Maybe a
Nothing Int
0 DSL
initDSL Int
0 Bool
True Bool
True

expandNS :: SyntaxInfo -> Name -> Name
expandNS :: SyntaxInfo -> Name -> Name
expandNS SyntaxInfo
syn n :: Name
n@(NS Name
_ [Text]
_) = Name
n
expandNS SyntaxInfo
syn Name
n = case SyntaxInfo -> [String]
syn_namespace SyntaxInfo
syn of
                        [] -> Name
n
                        [String]
xs -> Name -> [String] -> Name
sNS Name
n [String]
xs


-- For inferring types of things

bi :: FC
bi = String -> FC
fileFC String
"builtin"
primfc :: FC
primfc = String -> FC
fileFC String
"(primitive)"

inferTy :: Name
inferTy   = Int -> String -> Name
sMN Int
0 String
"__Infer"
inferCon :: Name
inferCon  = Int -> String -> Name
sMN Int
0 String
"__infer"
inferDecl :: PData
inferDecl = Name
-> FC
-> PTerm
-> [(Docstring (Either Err PTerm),
     [(Name, Docstring (Either Err PTerm))], Name, FC, PTerm, FC,
     [Name])]
-> PData
forall t.
Name
-> FC
-> t
-> [(Docstring (Either Err PTerm),
     [(Name, Docstring (Either Err PTerm))], Name, FC, t, FC, [Name])]
-> PData' t
PDatadecl Name
inferTy FC
primfc
                      (FC -> PTerm
PType FC
bi)
                      [(Docstring (Either Err PTerm)
forall a. Docstring a
emptyDocstring, [], Name
inferCon, FC
primfc, Plicity -> Name -> FC -> PTerm -> PTerm -> PTerm
PPi Plicity
impl (Int -> String -> Name
sMN Int
0 String
"iType") FC
primfc (FC -> PTerm
PType FC
bi) (
                                                   Plicity -> Name -> FC -> PTerm -> PTerm -> PTerm
PPi Plicity
expl_linear (Int -> String -> Name
sMN Int
0 String
"ival") FC
primfc (FC -> [FC] -> Name -> PTerm
PRef FC
bi [] (Int -> String -> Name
sMN Int
0 String
"iType"))
                                                   (FC -> [FC] -> Name -> PTerm
PRef FC
bi [] Name
inferTy)), FC
bi, [])]
inferOpts :: [a]
inferOpts = []

infTerm :: PTerm -> PTerm
infTerm PTerm
t = FC -> PTerm -> [PArg] -> PTerm
PApp FC
bi (FC -> [FC] -> Name -> PTerm
PRef FC
bi [] Name
inferCon) [Name -> PTerm -> Bool -> PArg
forall {t}. Name -> t -> Bool -> PArg' t
pimp (Int -> String -> Name
sMN Int
0 String
"iType") PTerm
Placeholder Bool
True, PTerm -> PArg
forall {t}. t -> PArg' t
pexp PTerm
t]
infP :: Term
infP = NameType -> Name -> Term -> Term
forall n. NameType -> n -> TT n -> TT n
P (Int -> Int -> NameType
TCon Int
6 Int
0) Name
inferTy (UExp -> Term
forall n. UExp -> TT n
TType (Int -> UExp
UVal Int
0))

getInferTerm, getInferType :: Term -> Term
getInferTerm :: Term -> Term
getInferTerm (Bind Name
n Binder Term
b Term
sc) = Name -> Binder Term -> Term -> Term
forall n. n -> Binder (TT n) -> TT n -> TT n
Bind Name
n Binder Term
b (Term -> Term) -> Term -> Term
forall a b. (a -> b) -> a -> b
$ Term -> Term
getInferTerm Term
sc
getInferTerm (App AppStatus Name
_ (App AppStatus Name
_ Term
_ Term
_) Term
tm) = Term
tm
getInferTerm Term
tm = Term
tm -- error ("getInferTerm " ++ show tm)

getInferType :: Term -> Term
getInferType (Bind Name
n Binder Term
b Term
sc)  = Name -> Binder Term -> Term -> Term
forall n. n -> Binder (TT n) -> TT n -> TT n
Bind Name
n (Binder Term -> Binder Term
forall {n}. Binder (TT n) -> Binder (TT n)
toTy Binder Term
b) (Term -> Term) -> Term -> Term
forall a b. (a -> b) -> a -> b
$ Term -> Term
getInferType Term
sc
  where toTy :: Binder (TT n) -> Binder (TT n)
toTy (Lam RigCount
r TT n
t)      = RigCount -> Maybe ImplicitInfo -> TT n -> TT n -> Binder (TT n)
forall b. RigCount -> Maybe ImplicitInfo -> b -> b -> Binder b
Pi RigCount
r Maybe ImplicitInfo
forall a. Maybe a
Nothing TT n
t (UExp -> TT n
forall n. UExp -> TT n
TType (String -> Int -> UExp
UVar [] Int
0))
        toTy (PVar RigCount
_ TT n
t)     = TT n -> Binder (TT n)
forall b. b -> Binder b
PVTy TT n
t
        toTy Binder (TT n)
b              = Binder (TT n)
b
getInferType (App AppStatus Name
_ (App AppStatus Name
_ Term
_ Term
ty) Term
_) = Term
ty



-- Handy primitives: Unit, False, Pair, MkPair, =, mkForeign

primNames :: [Name]
primNames = [Name
inferTy, Name
inferCon]

unitTy :: Name
unitTy   = String -> Name
sUN String
"Unit"
unitCon :: Name
unitCon  = String -> Name
sUN String
"MkUnit"

falseDoc :: Docstring (Err' t)
falseDoc = (() -> Err' t) -> Docstring () -> Docstring (Err' t)
forall a b. (a -> b) -> Docstring a -> Docstring b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (Err' t -> () -> Err' t
forall a b. a -> b -> a
const (Err' t -> () -> Err' t) -> Err' t -> () -> Err' t
forall a b. (a -> b) -> a -> b
$ String -> Err' t
forall t. String -> Err' t
Msg String
"") (Docstring () -> Docstring (Err' t))
-> (String -> Docstring ()) -> String -> Docstring (Err' t)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Text -> Docstring ()
parseDocstring (Text -> Docstring ())
-> (String -> Text) -> String -> Docstring ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> Text
T.pack (String -> Docstring (Err' t)) -> String -> Docstring (Err' t)
forall a b. (a -> b) -> a -> b
$
             String
"The empty type, also known as the trivially false proposition." String -> ShowS
forall a. [a] -> [a] -> [a]
++
             String
"\n\n" String -> ShowS
forall a. [a] -> [a] -> [a]
++
             String
"Use `void` or `absurd` to prove anything if you have a variable " String -> ShowS
forall a. [a] -> [a] -> [a]
++
             String
"of type `Void` in scope."
falseTy :: Name
falseTy   = String -> Name
sUN String
"Void"

pairTy :: Name
pairTy    = Name -> [String] -> Name
sNS (String -> Name
sUN String
"Pair") [String
"Builtins"]
pairCon :: Name
pairCon   = Name -> [String] -> Name
sNS (String -> Name
sUN String
"MkPair") [String
"Builtins"]

upairTy :: Name
upairTy    = Name -> [String] -> Name
sNS (String -> Name
sUN String
"UPair") [String
"Builtins"]
upairCon :: Name
upairCon   = Name -> [String] -> Name
sNS (String -> Name
sUN String
"MkUPair") [String
"Builtins"]

eqTy :: Name
eqTy  = String -> Name
sUN String
"="
eqCon :: Name
eqCon = String -> Name
sUN String
"Refl"
eqDoc :: Docstring (Either (Err' t) b)
eqDoc = (() -> Either (Err' t) b)
-> Docstring () -> Docstring (Either (Err' t) b)
forall a b. (a -> b) -> Docstring a -> Docstring b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (Either (Err' t) b -> () -> Either (Err' t) b
forall a b. a -> b -> a
const (Err' t -> Either (Err' t) b
forall a b. a -> Either a b
Left (Err' t -> Either (Err' t) b) -> Err' t -> Either (Err' t) b
forall a b. (a -> b) -> a -> b
$ String -> Err' t
forall t. String -> Err' t
Msg String
"")) (Docstring () -> Docstring (Either (Err' t) b))
-> (String -> Docstring ())
-> String
-> Docstring (Either (Err' t) b)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Text -> Docstring ()
parseDocstring (Text -> Docstring ())
-> (String -> Text) -> String -> Docstring ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> Text
T.pack (String -> Docstring (Either (Err' t) b))
-> String -> Docstring (Either (Err' t) b)
forall a b. (a -> b) -> a -> b
$
          String
"The propositional equality type. A proof that `x` = `y`." String -> ShowS
forall a. [a] -> [a] -> [a]
++
          String
"\n\n" String -> ShowS
forall a. [a] -> [a] -> [a]
++
          String
"To use such a proof, pattern-match on it, and the two equal things will " String -> ShowS
forall a. [a] -> [a] -> [a]
++
          String
"then need to be the _same_ pattern." String -> ShowS
forall a. [a] -> [a] -> [a]
++
          String
"\n\n" String -> ShowS
forall a. [a] -> [a] -> [a]
++
          String
"**Note**: Idris's equality type is potentially _heterogeneous_, which means that it " String -> ShowS
forall a. [a] -> [a] -> [a]
++
          String
"is possible to state equalities between values of potentially different " String -> ShowS
forall a. [a] -> [a] -> [a]
++
          String
"types. However, Idris will attempt the homogeneous case unless it fails to typecheck." String -> ShowS
forall a. [a] -> [a] -> [a]
++
          String
"\n\n" String -> ShowS
forall a. [a] -> [a] -> [a]
++
          String
"You may need to use `(~=~)` to explicitly request heterogeneous equality."

eqDecl :: PData
eqDecl = Name
-> FC
-> PTerm
-> [(Docstring (Either Err PTerm),
     [(Name, Docstring (Either Err PTerm))], Name, FC, PTerm, FC,
     [Name])]
-> PData
forall t.
Name
-> FC
-> t
-> [(Docstring (Either Err PTerm),
     [(Name, Docstring (Either Err PTerm))], Name, FC, t, FC, [Name])]
-> PData' t
PDatadecl Name
eqTy FC
primfc (Plicity -> [(Name, PTerm)] -> PTerm -> PTerm
piBindp Plicity
impl [(String -> Name
n String
"A", FC -> PTerm
PType FC
bi), (String -> Name
n String
"B", FC -> PTerm
PType FC
bi)]
                                      ([(Name, PTerm)] -> PTerm -> PTerm
piBind [(String -> Name
n String
"x", FC -> [FC] -> Name -> PTerm
PRef FC
bi [] (String -> Name
n String
"A")), (String -> Name
n String
"y", FC -> [FC] -> Name -> PTerm
PRef FC
bi [] (String -> Name
n String
"B"))]
                                      (FC -> PTerm
PType FC
bi)))
                [(Docstring (Either Err PTerm)
forall {t} {b}. Docstring (Either (Err' t) b)
reflDoc, [(Name, Docstring (Either Err PTerm))]
forall {t} {b}. [(Name, Docstring (Either (Err' t) b))]
reflParamDoc,
                  Name
eqCon, FC
primfc, Plicity -> Name -> FC -> PTerm -> PTerm -> PTerm
PPi Plicity
impl (String -> Name
n String
"A") FC
primfc (FC -> PTerm
PType FC
bi) (
                                        Plicity -> Name -> FC -> PTerm -> PTerm -> PTerm
PPi Plicity
impl (String -> Name
n String
"x") FC
primfc (FC -> [FC] -> Name -> PTerm
PRef FC
bi [] (String -> Name
n String
"A"))
                                            (FC -> PTerm -> [PArg] -> PTerm
PApp FC
bi (FC -> [FC] -> Name -> PTerm
PRef FC
bi [] Name
eqTy) [Name -> PTerm -> Bool -> PArg
forall {t}. Name -> t -> Bool -> PArg' t
pimp (String -> Name
n String
"A") PTerm
Placeholder Bool
False,
                                                                     Name -> PTerm -> Bool -> PArg
forall {t}. Name -> t -> Bool -> PArg' t
pimp (String -> Name
n String
"B") PTerm
Placeholder Bool
False,
                                                                     PTerm -> PArg
forall {t}. t -> PArg' t
pexp (FC -> [FC] -> Name -> PTerm
PRef FC
bi [] (String -> Name
n String
"x")),
                                                                     PTerm -> PArg
forall {t}. t -> PArg' t
pexp (FC -> [FC] -> Name -> PTerm
PRef FC
bi [] (String -> Name
n String
"x"))])), FC
bi, [])]
    where n :: String -> Name
n String
a = String -> Name
sUN String
a
          reflDoc :: Docstring (Either (Err' t) b)
reflDoc = (String -> Either (Err' t) b)
-> Docstring () -> Docstring (Either (Err' t) b)
forall a b. (String -> b) -> Docstring a -> Docstring b
annotCode (Either (Err' t) b -> String -> Either (Err' t) b
forall a b. a -> b -> a
const (Err' t -> Either (Err' t) b
forall a b. a -> Either a b
Left (Err' t -> Either (Err' t) b) -> Err' t -> Either (Err' t) b
forall a b. (a -> b) -> a -> b
$ String -> Err' t
forall t. String -> Err' t
Msg String
"")) (Docstring () -> Docstring (Either (Err' t) b))
-> (String -> Docstring ())
-> String
-> Docstring (Either (Err' t) b)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Text -> Docstring ()
parseDocstring (Text -> Docstring ())
-> (String -> Text) -> String -> Docstring ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> Text
T.pack (String -> Docstring (Either (Err' t) b))
-> String -> Docstring (Either (Err' t) b)
forall a b. (a -> b) -> a -> b
$
                      String
"A proof that `x` in fact equals `x`. To construct this, you must have already " String -> ShowS
forall a. [a] -> [a] -> [a]
++
                      String
"shown that both sides are in fact equal."
          reflParamDoc :: [(Name, Docstring (Either (Err' t) b))]
reflParamDoc = [(String -> Name
n String
"A",  (String -> Either (Err' t) b)
-> Docstring () -> Docstring (Either (Err' t) b)
forall a b. (String -> b) -> Docstring a -> Docstring b
annotCode (Either (Err' t) b -> String -> Either (Err' t) b
forall a b. a -> b -> a
const (Err' t -> Either (Err' t) b
forall a b. a -> Either a b
Left (Err' t -> Either (Err' t) b) -> Err' t -> Either (Err' t) b
forall a b. (a -> b) -> a -> b
$ String -> Err' t
forall t. String -> Err' t
Msg String
"")) (Docstring () -> Docstring (Either (Err' t) b))
-> (String -> Docstring ())
-> String
-> Docstring (Either (Err' t) b)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Text -> Docstring ()
parseDocstring (Text -> Docstring ())
-> (String -> Text) -> String -> Docstring ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> Text
T.pack (String -> Docstring (Either (Err' t) b))
-> String -> Docstring (Either (Err' t) b)
forall a b. (a -> b) -> a -> b
$ String
"the type at which the equality is proven"),
                          (String -> Name
n String
"x",  (String -> Either (Err' t) b)
-> Docstring () -> Docstring (Either (Err' t) b)
forall a b. (String -> b) -> Docstring a -> Docstring b
annotCode (Either (Err' t) b -> String -> Either (Err' t) b
forall a b. a -> b -> a
const (Err' t -> Either (Err' t) b
forall a b. a -> Either a b
Left (Err' t -> Either (Err' t) b) -> Err' t -> Either (Err' t) b
forall a b. (a -> b) -> a -> b
$ String -> Err' t
forall t. String -> Err' t
Msg String
"")) (Docstring () -> Docstring (Either (Err' t) b))
-> (String -> Docstring ())
-> String
-> Docstring (Either (Err' t) b)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Text -> Docstring ()
parseDocstring (Text -> Docstring ())
-> (String -> Text) -> String -> Docstring ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> Text
T.pack (String -> Docstring (Either (Err' t) b))
-> String -> Docstring (Either (Err' t) b)
forall a b. (a -> b) -> a -> b
$ String
"the element shown to be equal to itself.")]

eqParamDoc :: [(Name, Docstring (Either (Err' t) b))]
eqParamDoc = [(String -> Name
n String
"A", (String -> Either (Err' t) b)
-> Docstring () -> Docstring (Either (Err' t) b)
forall a b. (String -> b) -> Docstring a -> Docstring b
annotCode (Either (Err' t) b -> String -> Either (Err' t) b
forall a b. a -> b -> a
const (Err' t -> Either (Err' t) b
forall a b. a -> Either a b
Left (Err' t -> Either (Err' t) b) -> Err' t -> Either (Err' t) b
forall a b. (a -> b) -> a -> b
$ String -> Err' t
forall t. String -> Err' t
Msg String
"")) (Docstring () -> Docstring (Either (Err' t) b))
-> (String -> Docstring ())
-> String
-> Docstring (Either (Err' t) b)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Text -> Docstring ()
parseDocstring (Text -> Docstring ())
-> (String -> Text) -> String -> Docstring ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> Text
T.pack (String -> Docstring (Either (Err' t) b))
-> String -> Docstring (Either (Err' t) b)
forall a b. (a -> b) -> a -> b
$ String
"the type of the left side of the equality"),
              (String -> Name
n String
"B", (String -> Either (Err' t) b)
-> Docstring () -> Docstring (Either (Err' t) b)
forall a b. (String -> b) -> Docstring a -> Docstring b
annotCode (Either (Err' t) b -> String -> Either (Err' t) b
forall a b. a -> b -> a
const (Err' t -> Either (Err' t) b
forall a b. a -> Either a b
Left (Err' t -> Either (Err' t) b) -> Err' t -> Either (Err' t) b
forall a b. (a -> b) -> a -> b
$ String -> Err' t
forall t. String -> Err' t
Msg String
"")) (Docstring () -> Docstring (Either (Err' t) b))
-> (String -> Docstring ())
-> String
-> Docstring (Either (Err' t) b)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Text -> Docstring ()
parseDocstring (Text -> Docstring ())
-> (String -> Text) -> String -> Docstring ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> Text
T.pack (String -> Docstring (Either (Err' t) b))
-> String -> Docstring (Either (Err' t) b)
forall a b. (a -> b) -> a -> b
$ String
"the type of the right side of the equality")
              ]
    where n :: String -> Name
n String
a = String -> Name
sUN String
a

eqOpts :: [a]
eqOpts = []

-- | The special name to be used in the module documentation context -
-- not for use in the main definition context. The namespace around it
-- will determine the module to which the docs adhere.
modDocName :: Name
modDocName :: Name
modDocName = Int -> String -> Name
sMN Int
0 String
"ModuleDocs"

-- Defined in builtins.idr
sigmaTy :: Name
sigmaTy   = Name -> [String] -> Name
sNS (String -> Name
sUN String
"DPair") [String
"Builtins"]
sigmaCon :: Name
sigmaCon = Name -> [String] -> Name
sNS (String -> Name
sUN String
"MkDPair") [String
"Builtins"]

piBind :: [(Name, PTerm)] -> PTerm -> PTerm
piBind :: [(Name, PTerm)] -> PTerm -> PTerm
piBind = Plicity -> [(Name, PTerm)] -> PTerm -> PTerm
piBindp Plicity
expl

piBindp :: Plicity -> [(Name, PTerm)] -> PTerm -> PTerm
piBindp :: Plicity -> [(Name, PTerm)] -> PTerm -> PTerm
piBindp Plicity
p [] PTerm
t = PTerm
t
piBindp Plicity
p ((Name
n, PTerm
ty):[(Name, PTerm)]
ns) PTerm
t = Plicity -> Name -> FC -> PTerm -> PTerm -> PTerm
PPi Plicity
p Name
n FC
NoFC PTerm
ty (Plicity -> [(Name, PTerm)] -> PTerm -> PTerm
piBindp Plicity
p [(Name, PTerm)]
ns PTerm
t)


-- Pretty-printing declarations and terms

-- These "show" implementations render to an absurdly wide screen because inserted line breaks
-- could interfere with interactive editing, which calls "show".

instance Show PTerm where
  showsPrec :: Int -> PTerm -> ShowS
showsPrec Int
_ PTerm
tm = (SimpleDoc OutputAnnotation -> ShowS
forall a. SimpleDoc a -> ShowS
displayS (SimpleDoc OutputAnnotation -> ShowS)
-> (PTerm -> SimpleDoc OutputAnnotation) -> PTerm -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Float -> Int -> Doc OutputAnnotation -> SimpleDoc OutputAnnotation
forall a. Float -> Int -> Doc a -> SimpleDoc a
renderPretty Float
1.0 Int
10000000 (Doc OutputAnnotation -> SimpleDoc OutputAnnotation)
-> (PTerm -> Doc OutputAnnotation)
-> PTerm
-> SimpleDoc OutputAnnotation
forall b c a. (b -> c) -> (a -> b) -> a -> c
. PPOption -> PTerm -> Doc OutputAnnotation
prettyImp PPOption
defaultPPOption) PTerm
tm

instance Show PDecl where
  showsPrec :: Int -> PDecl' PTerm -> ShowS
showsPrec Int
_ PDecl' PTerm
d = (SimpleDoc OutputAnnotation -> ShowS
forall a. SimpleDoc a -> ShowS
displayS (SimpleDoc OutputAnnotation -> ShowS)
-> (PDecl' PTerm -> SimpleDoc OutputAnnotation)
-> PDecl' PTerm
-> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Float -> Int -> Doc OutputAnnotation -> SimpleDoc OutputAnnotation
forall a. Float -> Int -> Doc a -> SimpleDoc a
renderPretty Float
1.0 Int
10000000 (Doc OutputAnnotation -> SimpleDoc OutputAnnotation)
-> (PDecl' PTerm -> Doc OutputAnnotation)
-> PDecl' PTerm
-> SimpleDoc OutputAnnotation
forall b c a. (b -> c) -> (a -> b) -> a -> c
. PPOption -> PDecl' PTerm -> Doc OutputAnnotation
showDeclImp PPOption
verbosePPOption) PDecl' PTerm
d

instance Show PClause where
  showsPrec :: Int -> PClause' PTerm -> ShowS
showsPrec Int
_ PClause' PTerm
c = (SimpleDoc OutputAnnotation -> ShowS
forall a. SimpleDoc a -> ShowS
displayS (SimpleDoc OutputAnnotation -> ShowS)
-> (PClause' PTerm -> SimpleDoc OutputAnnotation)
-> PClause' PTerm
-> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Float -> Int -> Doc OutputAnnotation -> SimpleDoc OutputAnnotation
forall a. Float -> Int -> Doc a -> SimpleDoc a
renderPretty Float
1.0 Int
10000000 (Doc OutputAnnotation -> SimpleDoc OutputAnnotation)
-> (PClause' PTerm -> Doc OutputAnnotation)
-> PClause' PTerm
-> SimpleDoc OutputAnnotation
forall b c a. (b -> c) -> (a -> b) -> a -> c
. PPOption -> PClause' PTerm -> Doc OutputAnnotation
showCImp PPOption
verbosePPOption) PClause' PTerm
c

instance Show PData where
  showsPrec :: Int -> PData -> ShowS
showsPrec Int
_ PData
d = (SimpleDoc OutputAnnotation -> ShowS
forall a. SimpleDoc a -> ShowS
displayS (SimpleDoc OutputAnnotation -> ShowS)
-> (PData -> SimpleDoc OutputAnnotation) -> PData -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Float -> Int -> Doc OutputAnnotation -> SimpleDoc OutputAnnotation
forall a. Float -> Int -> Doc a -> SimpleDoc a
renderPretty Float
1.0 Int
10000000 (Doc OutputAnnotation -> SimpleDoc OutputAnnotation)
-> (PData -> Doc OutputAnnotation)
-> PData
-> SimpleDoc OutputAnnotation
forall b c a. (b -> c) -> (a -> b) -> a -> c
. PPOption -> PData -> Doc OutputAnnotation
showDImp PPOption
defaultPPOption) PData
d

instance Pretty PTerm OutputAnnotation where
  pretty :: PTerm -> Doc OutputAnnotation
pretty = PPOption -> PTerm -> Doc OutputAnnotation
prettyImp PPOption
defaultPPOption

-- | Colourise annotations according to an Idris state. It ignores the
-- names in the annotation, as there's no good way to show extended
-- information on a terminal.
annotationColour :: IState -> OutputAnnotation -> Maybe IdrisColour
annotationColour :: IState -> OutputAnnotation -> Maybe IdrisColour
annotationColour IState
ist OutputAnnotation
_ | Bool -> Bool
not (IState -> Bool
idris_colourRepl IState
ist) = Maybe IdrisColour
forall a. Maybe a
Nothing
annotationColour IState
ist (AnnConst Const
c) =
    let theme :: ColourTheme
theme = IState -> ColourTheme
idris_colourTheme IState
ist
    in IdrisColour -> Maybe IdrisColour
forall a. a -> Maybe a
Just (IdrisColour -> Maybe IdrisColour)
-> IdrisColour -> Maybe IdrisColour
forall a b. (a -> b) -> a -> b
$ if Const -> Bool
constIsType Const
c
                then ColourTheme -> IdrisColour
typeColour ColourTheme
theme
                else ColourTheme -> IdrisColour
dataColour ColourTheme
theme
annotationColour IState
ist (AnnData String
_ String
_)          = IdrisColour -> Maybe IdrisColour
forall a. a -> Maybe a
Just (IdrisColour -> Maybe IdrisColour)
-> IdrisColour -> Maybe IdrisColour
forall a b. (a -> b) -> a -> b
$ ColourTheme -> IdrisColour
dataColour (IState -> ColourTheme
idris_colourTheme IState
ist)
annotationColour IState
ist (AnnType String
_ String
_)          = IdrisColour -> Maybe IdrisColour
forall a. a -> Maybe a
Just (IdrisColour -> Maybe IdrisColour)
-> IdrisColour -> Maybe IdrisColour
forall a b. (a -> b) -> a -> b
$ ColourTheme -> IdrisColour
typeColour (IState -> ColourTheme
idris_colourTheme IState
ist)
annotationColour IState
ist (AnnBoundName Name
_ Bool
True)  = IdrisColour -> Maybe IdrisColour
forall a. a -> Maybe a
Just (IdrisColour -> Maybe IdrisColour)
-> IdrisColour -> Maybe IdrisColour
forall a b. (a -> b) -> a -> b
$ ColourTheme -> IdrisColour
implicitColour (IState -> ColourTheme
idris_colourTheme IState
ist)
annotationColour IState
ist (AnnBoundName Name
_ Bool
False) = IdrisColour -> Maybe IdrisColour
forall a. a -> Maybe a
Just (IdrisColour -> Maybe IdrisColour)
-> IdrisColour -> Maybe IdrisColour
forall a b. (a -> b) -> a -> b
$ ColourTheme -> IdrisColour
boundVarColour (IState -> ColourTheme
idris_colourTheme IState
ist)
annotationColour IState
ist OutputAnnotation
AnnKeyword             = IdrisColour -> Maybe IdrisColour
forall a. a -> Maybe a
Just (IdrisColour -> Maybe IdrisColour)
-> IdrisColour -> Maybe IdrisColour
forall a b. (a -> b) -> a -> b
$ ColourTheme -> IdrisColour
keywordColour (IState -> ColourTheme
idris_colourTheme IState
ist)
annotationColour IState
ist (AnnName Name
n Maybe NameOutput
_ Maybe String
_ Maybe String
_) =
  let ctxt :: Context
ctxt = IState -> Context
tt_ctxt IState
ist
      theme :: ColourTheme
theme = IState -> ColourTheme
idris_colourTheme IState
ist
  in case () of
       ()
_ | Name -> Context -> Bool
isDConName Name
n Context
ctxt     -> IdrisColour -> Maybe IdrisColour
forall a. a -> Maybe a
Just (IdrisColour -> Maybe IdrisColour)
-> IdrisColour -> Maybe IdrisColour
forall a b. (a -> b) -> a -> b
$ ColourTheme -> IdrisColour
dataColour ColourTheme
theme
       ()
_ | Name -> Context -> Bool
isFnName Name
n Context
ctxt       -> IdrisColour -> Maybe IdrisColour
forall a. a -> Maybe a
Just (IdrisColour -> Maybe IdrisColour)
-> IdrisColour -> Maybe IdrisColour
forall a b. (a -> b) -> a -> b
$ ColourTheme -> IdrisColour
functionColour ColourTheme
theme
       ()
_ | Name -> Context -> Bool
isTConName Name
n Context
ctxt     -> IdrisColour -> Maybe IdrisColour
forall a. a -> Maybe a
Just (IdrisColour -> Maybe IdrisColour)
-> IdrisColour -> Maybe IdrisColour
forall a b. (a -> b) -> a -> b
$ ColourTheme -> IdrisColour
typeColour ColourTheme
theme
       ()
_ | Name -> IState -> Bool
isPostulateName Name
n IState
ist -> IdrisColour -> Maybe IdrisColour
forall a. a -> Maybe a
Just (IdrisColour -> Maybe IdrisColour)
-> IdrisColour -> Maybe IdrisColour
forall a b. (a -> b) -> a -> b
$ ColourTheme -> IdrisColour
postulateColour ColourTheme
theme
       ()
_ | Bool
otherwise             -> Maybe IdrisColour
forall a. Maybe a
Nothing -- don't colourise unknown names
annotationColour IState
ist (AnnTextFmt TextFormatting
fmt) = IdrisColour -> Maybe IdrisColour
forall a. a -> Maybe a
Just (TextFormatting -> IdrisColour
colour TextFormatting
fmt)
  where colour :: TextFormatting -> IdrisColour
colour TextFormatting
BoldText      = Maybe Color -> Bool -> Bool -> Bool -> Bool -> IdrisColour
IdrisColour Maybe Color
forall a. Maybe a
Nothing Bool
True Bool
False Bool
True Bool
False
        colour TextFormatting
UnderlineText = Maybe Color -> Bool -> Bool -> Bool -> Bool -> IdrisColour
IdrisColour Maybe Color
forall a. Maybe a
Nothing Bool
True Bool
True Bool
False Bool
False
        colour TextFormatting
ItalicText    = Maybe Color -> Bool -> Bool -> Bool -> Bool -> IdrisColour
IdrisColour Maybe Color
forall a. Maybe a
Nothing Bool
True Bool
False Bool
False Bool
True
annotationColour IState
ist OutputAnnotation
_ = Maybe IdrisColour
forall a. Maybe a
Nothing


-- | Colourise annotations according to an Idris state. It ignores the
-- names in the annotation, as there's no good way to show extended
-- information on a terminal. Note that strings produced this way will
-- not be coloured on Windows, so the use of the colour rendering
-- functions in Idris.Output is to be preferred.
consoleDecorate :: IState -> OutputAnnotation -> String -> String
consoleDecorate :: IState -> OutputAnnotation -> ShowS
consoleDecorate IState
ist OutputAnnotation
ann = ShowS -> (IdrisColour -> ShowS) -> Maybe IdrisColour -> ShowS
forall b a. b -> (a -> b) -> Maybe a -> b
maybe ShowS
forall a. a -> a
id IdrisColour -> ShowS
colourise (IState -> OutputAnnotation -> Maybe IdrisColour
annotationColour IState
ist OutputAnnotation
ann)

isPostulateName :: Name -> IState -> Bool
isPostulateName :: Name -> IState -> Bool
isPostulateName Name
n IState
ist = Name -> Set Name -> Bool
forall a. Ord a => a -> Set a -> Bool
S.member Name
n (IState -> Set Name
idris_postulates IState
ist)

-- | Pretty-print a high-level closed Idris term with no information
-- about precedence/associativity
prettyImp :: PPOption -- ^ pretty printing options
          -> PTerm    -- ^ the term to pretty-print
          -> Doc OutputAnnotation
prettyImp :: PPOption -> PTerm -> Doc OutputAnnotation
prettyImp PPOption
impl = PPOption
-> [(Name, Bool)]
-> [Name]
-> [FixDecl]
-> PTerm
-> Doc OutputAnnotation
pprintPTerm PPOption
impl [] [] []

-- | Serialise something to base64 using its Binary implementation.

-- | Do the right thing for rendering a term in an IState
prettyIst ::  IState -> PTerm -> Doc OutputAnnotation
prettyIst :: IState -> PTerm -> Doc OutputAnnotation
prettyIst IState
ist = PPOption
-> [(Name, Bool)]
-> [Name]
-> [FixDecl]
-> PTerm
-> Doc OutputAnnotation
pprintPTerm PPOption
opt [] [] (IState -> [FixDecl]
idris_infixes IState
ist)
  where
    opt :: PPOption
opt = if LanguageExt
LinearTypes LanguageExt -> [LanguageExt] -> Bool
forall a. Eq a => a -> [a] -> Bool
forall (t :: * -> *) a. (Foldable t, Eq a) => a -> t a -> Bool
`elem` IState -> [LanguageExt]
idris_language_extensions IState
ist
             then (IState -> PPOption
ppOptionIst IState
ist) { ppopt_displayrig = True }
             else IState -> PPOption
ppOptionIst IState
ist

-- | Pretty-print a high-level Idris term in some bindings context
-- with infix info.
pprintPTerm :: PPOption       -- ^ pretty printing options
            -> [(Name, Bool)] -- ^ the currently-bound names and whether they are implicit
            -> [Name]         -- ^ names to always show in pi, even if not used
            -> [FixDecl]      -- ^ Fixity declarations
            -> PTerm          -- ^ the term to pretty-print
            -> Doc OutputAnnotation
pprintPTerm :: PPOption
-> [(Name, Bool)]
-> [Name]
-> [FixDecl]
-> PTerm
-> Doc OutputAnnotation
pprintPTerm PPOption
ppo [(Name, Bool)]
bnd [Name]
docArgs [FixDecl]
infixes = Maybe Int -> Int -> [(Name, Bool)] -> PTerm -> Doc OutputAnnotation
prettySe (PPOption -> Maybe Int
ppopt_depth PPOption
ppo) Int
startPrec [(Name, Bool)]
bnd
  where
    startPrec :: Int
startPrec = Int
0
    funcAppPrec :: Int
funcAppPrec = Int
10
    lbrace :: Doc OutputAnnotation
lbrace = OutputAnnotation -> Doc OutputAnnotation -> Doc OutputAnnotation
forall a. a -> Doc a -> Doc a
annotate (String -> OutputAnnotation
AnnSyntax String
"{") (String -> Doc OutputAnnotation
forall a. String -> Doc a
text String
"{")
    rbrace :: Doc OutputAnnotation
rbrace = OutputAnnotation -> Doc OutputAnnotation -> Doc OutputAnnotation
forall a. a -> Doc a -> Doc a
annotate (String -> OutputAnnotation
AnnSyntax String
"}") (String -> Doc OutputAnnotation
forall a. String -> Doc a
text String
"}")
    percent :: Doc OutputAnnotation
percent = OutputAnnotation -> Doc OutputAnnotation -> Doc OutputAnnotation
forall a. a -> Doc a -> Doc a
annotate (String -> OutputAnnotation
AnnSyntax String
"%") (String -> Doc OutputAnnotation
forall a. String -> Doc a
text String
"%")

    prettySe :: Maybe Int -> Int -> [(Name, Bool)] -> PTerm -> Doc OutputAnnotation
    prettySe :: Maybe Int -> Int -> [(Name, Bool)] -> PTerm -> Doc OutputAnnotation
prettySe Maybe Int
d Int
p [(Name, Bool)]
bnd (PQuote Raw
r) =
        String -> Doc OutputAnnotation
forall a. String -> Doc a
text String
"![" Doc OutputAnnotation
-> Doc OutputAnnotation -> Doc OutputAnnotation
forall a. Doc a -> Doc a -> Doc a
<> Raw -> Doc OutputAnnotation
forall a ty. Pretty a ty => a -> Doc ty
pretty Raw
r Doc OutputAnnotation
-> Doc OutputAnnotation -> Doc OutputAnnotation
forall a. Doc a -> Doc a -> Doc a
<> String -> Doc OutputAnnotation
forall a. String -> Doc a
text String
"]"
    prettySe Maybe Int
d Int
p [(Name, Bool)]
bnd (PPatvar FC
fc Name
n) = Name -> Doc OutputAnnotation
forall a ty. Pretty a ty => a -> Doc ty
pretty Name
n
    prettySe Maybe Int
d Int
p [(Name, Bool)]
bnd PTerm
e
      | Just Doc OutputAnnotation
str <- Maybe Int
-> Int -> [(Name, Bool)] -> PTerm -> Maybe (Doc OutputAnnotation)
slist Maybe Int
d Int
p [(Name, Bool)]
bnd PTerm
e = Maybe Int -> Doc OutputAnnotation -> Doc OutputAnnotation
forall {a} {a}. (Ord a, Num a) => Maybe a -> Doc a -> Doc a
depth Maybe Int
d Doc OutputAnnotation
str
      | Just Integer
n <- PPOption -> Maybe Int -> Int -> PTerm -> Maybe Integer
snat PPOption
ppo Maybe Int
d Int
p PTerm
e = Maybe Int -> Doc OutputAnnotation -> Doc OutputAnnotation
forall {a} {a}. (Ord a, Num a) => Maybe a -> Doc a -> Doc a
depth Maybe Int
d (Doc OutputAnnotation -> Doc OutputAnnotation)
-> Doc OutputAnnotation -> Doc OutputAnnotation
forall a b. (a -> b) -> a -> b
$ OutputAnnotation -> Doc OutputAnnotation -> Doc OutputAnnotation
forall a. a -> Doc a -> Doc a
annotate (String -> String -> OutputAnnotation
AnnData String
"Nat" String
"") (String -> Doc OutputAnnotation
forall a. String -> Doc a
text (Integer -> String
forall a. Show a => a -> String
show Integer
n))
    prettySe Maybe Int
d Int
p [(Name, Bool)]
bnd (PRef FC
fc [FC]
_ Name
n) = Bool -> Bool -> [(Name, Bool)] -> Name -> Doc OutputAnnotation
prettyName Bool
True (PPOption -> Bool
ppopt_impl PPOption
ppo) [(Name, Bool)]
bnd Name
n
    prettySe Maybe Int
d Int
p [(Name, Bool)]
bnd (PLam FC
fc Name
n FC
nfc PTerm
ty PTerm
sc) =
      let ([Name]
ns, PTerm
sc') = [Name] -> PTerm -> ([Name], PTerm)
getLamNames [Name
n] PTerm
sc in
          Maybe Int -> Doc OutputAnnotation -> Doc OutputAnnotation
forall {a} {a}. (Ord a, Num a) => Maybe a -> Doc a -> Doc a
depth Maybe Int
d (Doc OutputAnnotation -> Doc OutputAnnotation)
-> (Doc OutputAnnotation -> Doc OutputAnnotation)
-> Doc OutputAnnotation
-> Doc OutputAnnotation
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int -> Int -> Doc OutputAnnotation -> Doc OutputAnnotation
forall {a} {a}. Ord a => a -> a -> Doc a -> Doc a
bracket Int
p Int
startPrec (Doc OutputAnnotation -> Doc OutputAnnotation)
-> (Doc OutputAnnotation -> Doc OutputAnnotation)
-> Doc OutputAnnotation
-> Doc OutputAnnotation
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Doc OutputAnnotation -> Doc OutputAnnotation
forall a. Doc a -> Doc a
group (Doc OutputAnnotation -> Doc OutputAnnotation)
-> (Doc OutputAnnotation -> Doc OutputAnnotation)
-> Doc OutputAnnotation
-> Doc OutputAnnotation
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Doc OutputAnnotation -> Doc OutputAnnotation
forall a. Doc a -> Doc a
align (Doc OutputAnnotation -> Doc OutputAnnotation)
-> (Doc OutputAnnotation -> Doc OutputAnnotation)
-> Doc OutputAnnotation
-> Doc OutputAnnotation
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int -> Doc OutputAnnotation -> Doc OutputAnnotation
forall a. Int -> Doc a -> Doc a
hang Int
2 (Doc OutputAnnotation -> Doc OutputAnnotation)
-> Doc OutputAnnotation -> Doc OutputAnnotation
forall a b. (a -> b) -> a -> b
$
          (OutputAnnotation -> Doc OutputAnnotation -> Doc OutputAnnotation
forall a. a -> Doc a -> Doc a
annotate (String -> OutputAnnotation
AnnSyntax String
"\\") (String -> Doc OutputAnnotation
forall a. String -> Doc a
text String
"\\"))
          Doc OutputAnnotation
-> Doc OutputAnnotation -> Doc OutputAnnotation
forall a. Doc a -> Doc a -> Doc a
<> [Name] -> Bool -> Doc OutputAnnotation
prettyBindingsOf [Name]
ns Bool
False Doc OutputAnnotation
-> Doc OutputAnnotation -> Doc OutputAnnotation
forall a. Doc a -> Doc a -> Doc a
<+> String -> Doc OutputAnnotation
forall a. String -> Doc a
text String
"=>" Doc OutputAnnotation
-> Doc OutputAnnotation -> Doc OutputAnnotation
forall a. Doc a -> Doc a -> Doc a
<$>
          Maybe Int -> Int -> [(Name, Bool)] -> PTerm -> Doc OutputAnnotation
prettySe (Maybe Int -> Maybe Int
decD Maybe Int
d) Int
startPrec ((Name
n, Bool
False)(Name, Bool) -> [(Name, Bool)] -> [(Name, Bool)]
forall a. a -> [a] -> [a]
:[(Name, Bool)]
bnd) PTerm
sc'
      where
        getLamNames :: [Name] -> PTerm -> ([Name], PTerm)
getLamNames [Name]
acc (PLam FC
fc Name
n FC
nfc PTerm
ty PTerm
sc) = [Name] -> PTerm -> ([Name], PTerm)
getLamNames (Name
n Name -> [Name] -> [Name]
forall a. a -> [a] -> [a]
: [Name]
acc) PTerm
sc
        getLamNames [Name]
acc PTerm
sc = ([Name] -> [Name]
forall a. [a] -> [a]
reverse [Name]
acc, PTerm
sc)

        prettyBindingsOf :: [Name] -> Bool -> Doc OutputAnnotation
prettyBindingsOf [] Bool
t = String -> Doc OutputAnnotation
forall a. String -> Doc a
text String
""
        prettyBindingsOf [Name
n] Bool
t = Name -> Bool -> Doc OutputAnnotation
prettyBindingOf Name
n Bool
t
        prettyBindingsOf (Name
n : [Name]
ns) Bool
t = Name -> Bool -> Doc OutputAnnotation
prettyBindingOf Name
n Bool
t Doc OutputAnnotation
-> Doc OutputAnnotation -> Doc OutputAnnotation
forall a. Doc a -> Doc a -> Doc a
<> String -> Doc OutputAnnotation
forall a. String -> Doc a
text String
"," Doc OutputAnnotation
-> Doc OutputAnnotation -> Doc OutputAnnotation
forall a. Doc a -> Doc a -> Doc a
<+>
                                      [Name] -> Bool -> Doc OutputAnnotation
prettyBindingsOf [Name]
ns Bool
t
    prettySe Maybe Int
d Int
p [(Name, Bool)]
bnd (PLet FC
fc RigCount
rc Name
n FC
nfc PTerm
ty PTerm
v PTerm
sc) =
      Maybe Int -> Doc OutputAnnotation -> Doc OutputAnnotation
forall {a} {a}. (Ord a, Num a) => Maybe a -> Doc a -> Doc a
depth Maybe Int
d (Doc OutputAnnotation -> Doc OutputAnnotation)
-> (Doc OutputAnnotation -> Doc OutputAnnotation)
-> Doc OutputAnnotation
-> Doc OutputAnnotation
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int -> Int -> Doc OutputAnnotation -> Doc OutputAnnotation
forall {a} {a}. Ord a => a -> a -> Doc a -> Doc a
bracket Int
p Int
startPrec (Doc OutputAnnotation -> Doc OutputAnnotation)
-> (Doc OutputAnnotation -> Doc OutputAnnotation)
-> Doc OutputAnnotation
-> Doc OutputAnnotation
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Doc OutputAnnotation -> Doc OutputAnnotation
forall a. Doc a -> Doc a
group (Doc OutputAnnotation -> Doc OutputAnnotation)
-> (Doc OutputAnnotation -> Doc OutputAnnotation)
-> Doc OutputAnnotation
-> Doc OutputAnnotation
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Doc OutputAnnotation -> Doc OutputAnnotation
forall a. Doc a -> Doc a
align (Doc OutputAnnotation -> Doc OutputAnnotation)
-> Doc OutputAnnotation -> Doc OutputAnnotation
forall a b. (a -> b) -> a -> b
$
      String -> Doc OutputAnnotation
kwd String
"let" Doc OutputAnnotation
-> Doc OutputAnnotation -> Doc OutputAnnotation
forall a. Doc a -> Doc a -> Doc a
<+> (Doc OutputAnnotation -> Doc OutputAnnotation
forall a. Doc a -> Doc a
group (Doc OutputAnnotation -> Doc OutputAnnotation)
-> (Doc OutputAnnotation -> Doc OutputAnnotation)
-> Doc OutputAnnotation
-> Doc OutputAnnotation
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Doc OutputAnnotation -> Doc OutputAnnotation
forall a. Doc a -> Doc a
align (Doc OutputAnnotation -> Doc OutputAnnotation)
-> (Doc OutputAnnotation -> Doc OutputAnnotation)
-> Doc OutputAnnotation
-> Doc OutputAnnotation
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int -> Doc OutputAnnotation -> Doc OutputAnnotation
forall a. Int -> Doc a -> Doc a
hang Int
2 (Doc OutputAnnotation -> Doc OutputAnnotation)
-> Doc OutputAnnotation -> Doc OutputAnnotation
forall a b. (a -> b) -> a -> b
$ Name -> Bool -> Doc OutputAnnotation
prettyBindingOf Name
n Bool
False Doc OutputAnnotation
-> Doc OutputAnnotation -> Doc OutputAnnotation
forall a. Doc a -> Doc a -> Doc a
<+> String -> Doc OutputAnnotation
forall a. String -> Doc a
text String
"=" Doc OutputAnnotation
-> Doc OutputAnnotation -> Doc OutputAnnotation
forall a. Doc a -> Doc a -> Doc a
<$> Maybe Int -> Int -> [(Name, Bool)] -> PTerm -> Doc OutputAnnotation
prettySe (Maybe Int -> Maybe Int
decD Maybe Int
d) Int
startPrec [(Name, Bool)]
bnd PTerm
v) Doc OutputAnnotation
-> Doc OutputAnnotation -> Doc OutputAnnotation
forall a. Doc a -> Doc a -> Doc a
</>
      String -> Doc OutputAnnotation
kwd String
"in" Doc OutputAnnotation
-> Doc OutputAnnotation -> Doc OutputAnnotation
forall a. Doc a -> Doc a -> Doc a
<+> (Doc OutputAnnotation -> Doc OutputAnnotation
forall a. Doc a -> Doc a
group (Doc OutputAnnotation -> Doc OutputAnnotation)
-> (Doc OutputAnnotation -> Doc OutputAnnotation)
-> Doc OutputAnnotation
-> Doc OutputAnnotation
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Doc OutputAnnotation -> Doc OutputAnnotation
forall a. Doc a -> Doc a
align (Doc OutputAnnotation -> Doc OutputAnnotation)
-> (Doc OutputAnnotation -> Doc OutputAnnotation)
-> Doc OutputAnnotation
-> Doc OutputAnnotation
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int -> Doc OutputAnnotation -> Doc OutputAnnotation
forall a. Int -> Doc a -> Doc a
hang Int
2 (Doc OutputAnnotation -> Doc OutputAnnotation)
-> Doc OutputAnnotation -> Doc OutputAnnotation
forall a b. (a -> b) -> a -> b
$ Maybe Int -> Int -> [(Name, Bool)] -> PTerm -> Doc OutputAnnotation
prettySe (Maybe Int -> Maybe Int
decD Maybe Int
d) Int
startPrec ((Name
n, Bool
False)(Name, Bool) -> [(Name, Bool)] -> [(Name, Bool)]
forall a. a -> [a] -> [a]
:[(Name, Bool)]
bnd) PTerm
sc)
    prettySe Maybe Int
d Int
p [(Name, Bool)]
bnd (PPi (Exp [ArgOpt]
l Static
s Bool
_ RigCount
rig) Name
n FC
_ PTerm
ty PTerm
sc)
      | RigCount
Rig0 <- RigCount
rig, PPOption -> Bool
ppopt_displayrig PPOption
ppo =
          Maybe Int -> Doc OutputAnnotation -> Doc OutputAnnotation
forall {a} {a}. (Ord a, Num a) => Maybe a -> Doc a -> Doc a
depth Maybe Int
d (Doc OutputAnnotation -> Doc OutputAnnotation)
-> (Doc OutputAnnotation -> Doc OutputAnnotation)
-> Doc OutputAnnotation
-> Doc OutputAnnotation
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int -> Int -> Doc OutputAnnotation -> Doc OutputAnnotation
forall {a} {a}. Ord a => a -> a -> Doc a -> Doc a
bracket Int
p Int
startPrec (Doc OutputAnnotation -> Doc OutputAnnotation)
-> (Doc OutputAnnotation -> Doc OutputAnnotation)
-> Doc OutputAnnotation
-> Doc OutputAnnotation
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Doc OutputAnnotation -> Doc OutputAnnotation
forall a. Doc a -> Doc a
group (Doc OutputAnnotation -> Doc OutputAnnotation)
-> Doc OutputAnnotation -> Doc OutputAnnotation
forall a b. (a -> b) -> a -> b
$
          Doc OutputAnnotation
-> Doc OutputAnnotation
-> Doc OutputAnnotation
-> Doc OutputAnnotation
forall a. Doc a -> Doc a -> Doc a -> Doc a
enclose Doc OutputAnnotation
forall a. Doc a
lparen Doc OutputAnnotation
forall a. Doc a
rparen (Doc OutputAnnotation -> Doc OutputAnnotation
forall a. Doc a -> Doc a
group (Doc OutputAnnotation -> Doc OutputAnnotation)
-> (Doc OutputAnnotation -> Doc OutputAnnotation)
-> Doc OutputAnnotation
-> Doc OutputAnnotation
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Doc OutputAnnotation -> Doc OutputAnnotation
forall a. Doc a -> Doc a
align (Doc OutputAnnotation -> Doc OutputAnnotation)
-> Doc OutputAnnotation -> Doc OutputAnnotation
forall a b. (a -> b) -> a -> b
$ String -> Doc OutputAnnotation
forall a. String -> Doc a
text String
"0" Doc OutputAnnotation
-> Doc OutputAnnotation -> Doc OutputAnnotation
forall a. Doc a -> Doc a -> Doc a
<+> Name -> Bool -> Doc OutputAnnotation
prettyBindingOf Name
n Bool
False Doc OutputAnnotation
-> Doc OutputAnnotation -> Doc OutputAnnotation
forall a. Doc a -> Doc a -> Doc a
<+> Doc OutputAnnotation
forall a. Doc a
colon Doc OutputAnnotation
-> Doc OutputAnnotation -> Doc OutputAnnotation
forall a. Doc a -> Doc a -> Doc a
<+> Maybe Int -> Int -> [(Name, Bool)] -> PTerm -> Doc OutputAnnotation
prettySe (Maybe Int -> Maybe Int
decD Maybe Int
d) Int
startPrec [(Name, Bool)]
bnd PTerm
ty) Doc OutputAnnotation
-> Doc OutputAnnotation -> Doc OutputAnnotation
forall a. Doc a -> Doc a -> Doc a
<+>
          Doc OutputAnnotation
st Doc OutputAnnotation
-> Doc OutputAnnotation -> Doc OutputAnnotation
forall a. Doc a -> Doc a -> Doc a
<> String -> Doc OutputAnnotation
forall a. String -> Doc a
text String
"->" Doc OutputAnnotation
-> Doc OutputAnnotation -> Doc OutputAnnotation
forall a. Doc a -> Doc a -> Doc a
<$> Maybe Int -> Int -> [(Name, Bool)] -> PTerm -> Doc OutputAnnotation
prettySe (Maybe Int -> Maybe Int
decD Maybe Int
d) Int
startPrec ((Name
n, Bool
False)(Name, Bool) -> [(Name, Bool)] -> [(Name, Bool)]
forall a. a -> [a] -> [a]
:[(Name, Bool)]
bnd) PTerm
sc
      | RigCount
Rig1 <- RigCount
rig, PPOption -> Bool
ppopt_displayrig PPOption
ppo =
          Maybe Int -> Doc OutputAnnotation -> Doc OutputAnnotation
forall {a} {a}. (Ord a, Num a) => Maybe a -> Doc a -> Doc a
depth Maybe Int
d (Doc OutputAnnotation -> Doc OutputAnnotation)
-> (Doc OutputAnnotation -> Doc OutputAnnotation)
-> Doc OutputAnnotation
-> Doc OutputAnnotation
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int -> Int -> Doc OutputAnnotation -> Doc OutputAnnotation
forall {a} {a}. Ord a => a -> a -> Doc a -> Doc a
bracket Int
p Int
startPrec (Doc OutputAnnotation -> Doc OutputAnnotation)
-> (Doc OutputAnnotation -> Doc OutputAnnotation)
-> Doc OutputAnnotation
-> Doc OutputAnnotation
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Doc OutputAnnotation -> Doc OutputAnnotation
forall a. Doc a -> Doc a
group (Doc OutputAnnotation -> Doc OutputAnnotation)
-> Doc OutputAnnotation -> Doc OutputAnnotation
forall a b. (a -> b) -> a -> b
$
          Doc OutputAnnotation
-> Doc OutputAnnotation
-> Doc OutputAnnotation
-> Doc OutputAnnotation
forall a. Doc a -> Doc a -> Doc a -> Doc a
enclose Doc OutputAnnotation
forall a. Doc a
lparen Doc OutputAnnotation
forall a. Doc a
rparen (Doc OutputAnnotation -> Doc OutputAnnotation
forall a. Doc a -> Doc a
group (Doc OutputAnnotation -> Doc OutputAnnotation)
-> (Doc OutputAnnotation -> Doc OutputAnnotation)
-> Doc OutputAnnotation
-> Doc OutputAnnotation
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Doc OutputAnnotation -> Doc OutputAnnotation
forall a. Doc a -> Doc a
align (Doc OutputAnnotation -> Doc OutputAnnotation)
-> Doc OutputAnnotation -> Doc OutputAnnotation
forall a b. (a -> b) -> a -> b
$ String -> Doc OutputAnnotation
forall a. String -> Doc a
text String
"1" Doc OutputAnnotation
-> Doc OutputAnnotation -> Doc OutputAnnotation
forall a. Doc a -> Doc a -> Doc a
<+> Name -> Bool -> Doc OutputAnnotation
prettyBindingOf Name
n Bool
False Doc OutputAnnotation
-> Doc OutputAnnotation -> Doc OutputAnnotation
forall a. Doc a -> Doc a -> Doc a
<+> Doc OutputAnnotation
forall a. Doc a
colon Doc OutputAnnotation
-> Doc OutputAnnotation -> Doc OutputAnnotation
forall a. Doc a -> Doc a -> Doc a
<+> Maybe Int -> Int -> [(Name, Bool)] -> PTerm -> Doc OutputAnnotation
prettySe (Maybe Int -> Maybe Int
decD Maybe Int
d) Int
startPrec [(Name, Bool)]
bnd PTerm
ty) Doc OutputAnnotation
-> Doc OutputAnnotation -> Doc OutputAnnotation
forall a. Doc a -> Doc a -> Doc a
<+>
          Doc OutputAnnotation
st Doc OutputAnnotation
-> Doc OutputAnnotation -> Doc OutputAnnotation
forall a. Doc a -> Doc a -> Doc a
<> String -> Doc OutputAnnotation
forall a. String -> Doc a
text String
"->" Doc OutputAnnotation
-> Doc OutputAnnotation -> Doc OutputAnnotation
forall a. Doc a -> Doc a -> Doc a
<$> Maybe Int -> Int -> [(Name, Bool)] -> PTerm -> Doc OutputAnnotation
prettySe (Maybe Int -> Maybe Int
decD Maybe Int
d) Int
startPrec ((Name
n, Bool
False)(Name, Bool) -> [(Name, Bool)] -> [(Name, Bool)]
forall a. a -> [a] -> [a]
:[(Name, Bool)]
bnd) PTerm
sc
      | Name
n Name -> [Name] -> Bool
forall a. Eq a => a -> [a] -> Bool
forall (t :: * -> *) a. (Foldable t, Eq a) => a -> t a -> Bool
`elem` PTerm -> [Name]
allNamesIn PTerm
sc Bool -> Bool -> Bool
|| PPOption -> Bool
ppopt_impl PPOption
ppo Bool -> Bool -> Bool
&& Name -> Bool
uname Name
n Bool -> Bool -> Bool
|| Name
n Name -> [Name] -> Bool
forall a. Eq a => a -> [a] -> Bool
forall (t :: * -> *) a. (Foldable t, Eq a) => a -> t a -> Bool
`elem` [Name]
docArgs
          Bool -> Bool -> Bool
|| PPOption -> Bool
ppopt_pinames PPOption
ppo Bool -> Bool -> Bool
&& Name -> Bool
uname Name
n =
          Maybe Int -> Doc OutputAnnotation -> Doc OutputAnnotation
forall {a} {a}. (Ord a, Num a) => Maybe a -> Doc a -> Doc a
depth Maybe Int
d (Doc OutputAnnotation -> Doc OutputAnnotation)
-> (Doc OutputAnnotation -> Doc OutputAnnotation)
-> Doc OutputAnnotation
-> Doc OutputAnnotation
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int -> Int -> Doc OutputAnnotation -> Doc OutputAnnotation
forall {a} {a}. Ord a => a -> a -> Doc a -> Doc a
bracket Int
p Int
startPrec (Doc OutputAnnotation -> Doc OutputAnnotation)
-> (Doc OutputAnnotation -> Doc OutputAnnotation)
-> Doc OutputAnnotation
-> Doc OutputAnnotation
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Doc OutputAnnotation -> Doc OutputAnnotation
forall a. Doc a -> Doc a
group (Doc OutputAnnotation -> Doc OutputAnnotation)
-> Doc OutputAnnotation -> Doc OutputAnnotation
forall a b. (a -> b) -> a -> b
$
          Doc OutputAnnotation
-> Doc OutputAnnotation
-> Doc OutputAnnotation
-> Doc OutputAnnotation
forall a. Doc a -> Doc a -> Doc a -> Doc a
enclose Doc OutputAnnotation
forall a. Doc a
lparen Doc OutputAnnotation
forall a. Doc a
rparen (Doc OutputAnnotation -> Doc OutputAnnotation
forall a. Doc a -> Doc a
group (Doc OutputAnnotation -> Doc OutputAnnotation)
-> (Doc OutputAnnotation -> Doc OutputAnnotation)
-> Doc OutputAnnotation
-> Doc OutputAnnotation
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Doc OutputAnnotation -> Doc OutputAnnotation
forall a. Doc a -> Doc a
align (Doc OutputAnnotation -> Doc OutputAnnotation)
-> Doc OutputAnnotation -> Doc OutputAnnotation
forall a b. (a -> b) -> a -> b
$ Name -> Bool -> Doc OutputAnnotation
prettyBindingOf Name
n Bool
False Doc OutputAnnotation
-> Doc OutputAnnotation -> Doc OutputAnnotation
forall a. Doc a -> Doc a -> Doc a
<+> Doc OutputAnnotation
forall a. Doc a
colon Doc OutputAnnotation
-> Doc OutputAnnotation -> Doc OutputAnnotation
forall a. Doc a -> Doc a -> Doc a
<+> Maybe Int -> Int -> [(Name, Bool)] -> PTerm -> Doc OutputAnnotation
prettySe (Maybe Int -> Maybe Int
decD Maybe Int
d) Int
startPrec [(Name, Bool)]
bnd PTerm
ty) Doc OutputAnnotation
-> Doc OutputAnnotation -> Doc OutputAnnotation
forall a. Doc a -> Doc a -> Doc a
<+>
          Doc OutputAnnotation
st Doc OutputAnnotation
-> Doc OutputAnnotation -> Doc OutputAnnotation
forall a. Doc a -> Doc a -> Doc a
<> String -> Doc OutputAnnotation
forall a. String -> Doc a
text String
"->" Doc OutputAnnotation
-> Doc OutputAnnotation -> Doc OutputAnnotation
forall a. Doc a -> Doc a -> Doc a
<$> Maybe Int -> Int -> [(Name, Bool)] -> PTerm -> Doc OutputAnnotation
prettySe (Maybe Int -> Maybe Int
decD Maybe Int
d) Int
startPrec ((Name
n, Bool
False)(Name, Bool) -> [(Name, Bool)] -> [(Name, Bool)]
forall a. a -> [a] -> [a]
:[(Name, Bool)]
bnd) PTerm
sc
      | Bool
otherwise                      =
          Maybe Int -> Doc OutputAnnotation -> Doc OutputAnnotation
forall {a} {a}. (Ord a, Num a) => Maybe a -> Doc a -> Doc a
depth Maybe Int
d (Doc OutputAnnotation -> Doc OutputAnnotation)
-> (Doc OutputAnnotation -> Doc OutputAnnotation)
-> Doc OutputAnnotation
-> Doc OutputAnnotation
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int -> Int -> Doc OutputAnnotation -> Doc OutputAnnotation
forall {a} {a}. Ord a => a -> a -> Doc a -> Doc a
bracket Int
p Int
startPrec (Doc OutputAnnotation -> Doc OutputAnnotation)
-> (Doc OutputAnnotation -> Doc OutputAnnotation)
-> Doc OutputAnnotation
-> Doc OutputAnnotation
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Doc OutputAnnotation -> Doc OutputAnnotation
forall a. Doc a -> Doc a
group (Doc OutputAnnotation -> Doc OutputAnnotation)
-> Doc OutputAnnotation -> Doc OutputAnnotation
forall a b. (a -> b) -> a -> b
$
          Doc OutputAnnotation -> Doc OutputAnnotation
forall a. Doc a -> Doc a
group (Maybe Int -> Int -> [(Name, Bool)] -> PTerm -> Doc OutputAnnotation
prettySe (Maybe Int -> Maybe Int
decD Maybe Int
d) (Int
startPrec Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
1) [(Name, Bool)]
bnd PTerm
ty Doc OutputAnnotation
-> Doc OutputAnnotation -> Doc OutputAnnotation
forall a. Doc a -> Doc a -> Doc a
<+> Doc OutputAnnotation
st) Doc OutputAnnotation
-> Doc OutputAnnotation -> Doc OutputAnnotation
forall a. Doc a -> Doc a -> Doc a
<> String -> Doc OutputAnnotation
forall a. String -> Doc a
text String
"->" Doc OutputAnnotation
-> Doc OutputAnnotation -> Doc OutputAnnotation
forall a. Doc a -> Doc a -> Doc a
<$>
          Doc OutputAnnotation -> Doc OutputAnnotation
forall a. Doc a -> Doc a
group (Maybe Int -> Int -> [(Name, Bool)] -> PTerm -> Doc OutputAnnotation
prettySe (Maybe Int -> Maybe Int
decD Maybe Int
d) Int
startPrec ((Name
n, Bool
False)(Name, Bool) -> [(Name, Bool)] -> [(Name, Bool)]
forall a. a -> [a] -> [a]
:[(Name, Bool)]
bnd) PTerm
sc)
      where
        uname :: Name -> Bool
uname (UN Text
n) = case Text -> String
str Text
n of
                            (Char
'_':String
_) -> Bool
False
                            String
_ -> Bool
True
        uname Name
_ = Bool
False

        st :: Doc OutputAnnotation
st =
          case Static
s of
            Static
Static -> Doc OutputAnnotation
percent Doc OutputAnnotation
-> Doc OutputAnnotation -> Doc OutputAnnotation
forall a. Doc a -> Doc a -> Doc a
<> String -> Doc OutputAnnotation
forall a. String -> Doc a
text String
"static" Doc OutputAnnotation
-> Doc OutputAnnotation -> Doc OutputAnnotation
forall a. Doc a -> Doc a -> Doc a
<> Doc OutputAnnotation
forall a. Doc a
space
            Static
_      -> Doc OutputAnnotation
forall a. Doc a
empty
    prettySe Maybe Int
d Int
p [(Name, Bool)]
bnd (PPi (Imp [ArgOpt]
l Static
s Bool
_ Maybe ImplicitInfo
fa Bool
_ RigCount
rig) Name
n FC
_ PTerm
ty PTerm
sc)
      | PPOption -> Bool
ppopt_impl PPOption
ppo =
          Maybe Int -> Doc OutputAnnotation -> Doc OutputAnnotation
forall {a} {a}. (Ord a, Num a) => Maybe a -> Doc a -> Doc a
depth Maybe Int
d (Doc OutputAnnotation -> Doc OutputAnnotation)
-> (Doc OutputAnnotation -> Doc OutputAnnotation)
-> Doc OutputAnnotation
-> Doc OutputAnnotation
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int -> Int -> Doc OutputAnnotation -> Doc OutputAnnotation
forall {a} {a}. Ord a => a -> a -> Doc a -> Doc a
bracket Int
p Int
startPrec (Doc OutputAnnotation -> Doc OutputAnnotation)
-> Doc OutputAnnotation -> Doc OutputAnnotation
forall a b. (a -> b) -> a -> b
$
          Doc OutputAnnotation
lbrace Doc OutputAnnotation
-> Doc OutputAnnotation -> Doc OutputAnnotation
forall a. Doc a -> Doc a -> Doc a
<> RigCount -> Name -> Doc OutputAnnotation
showRig RigCount
rig Name
n Doc OutputAnnotation
-> Doc OutputAnnotation -> Doc OutputAnnotation
forall a. Doc a -> Doc a -> Doc a
<+> Doc OutputAnnotation
forall a. Doc a
colon Doc OutputAnnotation
-> Doc OutputAnnotation -> Doc OutputAnnotation
forall a. Doc a -> Doc a -> Doc a
<+> Maybe Int -> Int -> [(Name, Bool)] -> PTerm -> Doc OutputAnnotation
prettySe (Maybe Int -> Maybe Int
decD Maybe Int
d) Int
startPrec [(Name, Bool)]
bnd PTerm
ty Doc OutputAnnotation
-> Doc OutputAnnotation -> Doc OutputAnnotation
forall a. Doc a -> Doc a -> Doc a
<> Doc OutputAnnotation
rbrace Doc OutputAnnotation
-> Doc OutputAnnotation -> Doc OutputAnnotation
forall a. Doc a -> Doc a -> Doc a
<+>
          Doc OutputAnnotation
st Doc OutputAnnotation
-> Doc OutputAnnotation -> Doc OutputAnnotation
forall a. Doc a -> Doc a -> Doc a
<> String -> Doc OutputAnnotation
forall a. String -> Doc a
text String
"->" Doc OutputAnnotation
-> Doc OutputAnnotation -> Doc OutputAnnotation
forall a. Doc a -> Doc a -> Doc a
</> Maybe Int -> Int -> [(Name, Bool)] -> PTerm -> Doc OutputAnnotation
prettySe (Maybe Int -> Maybe Int
decD Maybe Int
d) Int
startPrec ((Name
n, Bool
True)(Name, Bool) -> [(Name, Bool)] -> [(Name, Bool)]
forall a. a -> [a] -> [a]
:[(Name, Bool)]
bnd) PTerm
sc
      | PTerm -> Bool
isPi PTerm
sc = Maybe Int -> Doc OutputAnnotation -> Doc OutputAnnotation
forall {a} {a}. (Ord a, Num a) => Maybe a -> Doc a -> Doc a
depth Maybe Int
d (Doc OutputAnnotation -> Doc OutputAnnotation)
-> (Doc OutputAnnotation -> Doc OutputAnnotation)
-> Doc OutputAnnotation
-> Doc OutputAnnotation
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int -> Int -> Doc OutputAnnotation -> Doc OutputAnnotation
forall {a} {a}. Ord a => a -> a -> Doc a -> Doc a
bracket Int
p Int
startPrec (Doc OutputAnnotation -> Doc OutputAnnotation)
-> Doc OutputAnnotation -> Doc OutputAnnotation
forall a b. (a -> b) -> a -> b
$ Maybe Int -> Int -> [(Name, Bool)] -> PTerm -> Doc OutputAnnotation
prettySe (Maybe Int -> Maybe Int
decD Maybe Int
d) Int
startPrec ((Name
n, Bool
True)(Name, Bool) -> [(Name, Bool)] -> [(Name, Bool)]
forall a. a -> [a] -> [a]
:[(Name, Bool)]
bnd) PTerm
sc
      | Bool
otherwise = Maybe Int -> Doc OutputAnnotation -> Doc OutputAnnotation
forall {a} {a}. (Ord a, Num a) => Maybe a -> Doc a -> Doc a
depth Maybe Int
d (Doc OutputAnnotation -> Doc OutputAnnotation)
-> Doc OutputAnnotation -> Doc OutputAnnotation
forall a b. (a -> b) -> a -> b
$ Maybe Int -> Int -> [(Name, Bool)] -> PTerm -> Doc OutputAnnotation
prettySe (Maybe Int -> Maybe Int
decD Maybe Int
d) Int
startPrec ((Name
n, Bool
True)(Name, Bool) -> [(Name, Bool)] -> [(Name, Bool)]
forall a. a -> [a] -> [a]
:[(Name, Bool)]
bnd) PTerm
sc
      where
        showRig :: RigCount -> Name -> Doc OutputAnnotation
showRig RigCount
Rig0 Name
n = String -> Doc OutputAnnotation
forall a. String -> Doc a
text String
"0" Doc OutputAnnotation
-> Doc OutputAnnotation -> Doc OutputAnnotation
forall a. Doc a -> Doc a -> Doc a
<+> Name -> Bool -> Doc OutputAnnotation
prettyBindingOf Name
n Bool
True
        showRig RigCount
Rig1 Name
n = String -> Doc OutputAnnotation
forall a. String -> Doc a
text String
"1" Doc OutputAnnotation
-> Doc OutputAnnotation -> Doc OutputAnnotation
forall a. Doc a -> Doc a -> Doc a
<+> Name -> Bool -> Doc OutputAnnotation
prettyBindingOf Name
n Bool
True
        showRig RigCount
_ Name
n = Name -> Bool -> Doc OutputAnnotation
prettyBindingOf Name
n Bool
True

        isPi :: PTerm -> Bool
isPi (PPi (Exp{}) Name
_ FC
_ PTerm
_ PTerm
_) = Bool
True
        isPi (PPi Plicity
_ Name
_ FC
_ PTerm
_ PTerm
sc) = PTerm -> Bool
isPi PTerm
sc
        isPi PTerm
_ = Bool
False

        st :: Doc OutputAnnotation
st =
          case Static
s of
            Static
Static -> Doc OutputAnnotation
percent Doc OutputAnnotation
-> Doc OutputAnnotation -> Doc OutputAnnotation
forall a. Doc a -> Doc a -> Doc a
<> String -> Doc OutputAnnotation
forall a. String -> Doc a
text String
"static" Doc OutputAnnotation
-> Doc OutputAnnotation -> Doc OutputAnnotation
forall a. Doc a -> Doc a -> Doc a
<> Doc OutputAnnotation
forall a. Doc a
space
            Static
_      -> Doc OutputAnnotation
forall a. Doc a
empty
    prettySe Maybe Int
d Int
p [(Name, Bool)]
bnd (PPi (Constraint [ArgOpt]
_ Static
_ RigCount
rig) Name
n FC
_ PTerm
ty PTerm
sc) =
      Maybe Int -> Doc OutputAnnotation -> Doc OutputAnnotation
forall {a} {a}. (Ord a, Num a) => Maybe a -> Doc a -> Doc a
depth Maybe Int
d (Doc OutputAnnotation -> Doc OutputAnnotation)
-> (Doc OutputAnnotation -> Doc OutputAnnotation)
-> Doc OutputAnnotation
-> Doc OutputAnnotation
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int -> Int -> Doc OutputAnnotation -> Doc OutputAnnotation
forall {a} {a}. Ord a => a -> a -> Doc a -> Doc a
bracket Int
p Int
startPrec (Doc OutputAnnotation -> Doc OutputAnnotation)
-> Doc OutputAnnotation -> Doc OutputAnnotation
forall a b. (a -> b) -> a -> b
$
      Maybe Int -> Int -> [(Name, Bool)] -> PTerm -> Doc OutputAnnotation
prettySe (Maybe Int -> Maybe Int
decD Maybe Int
d) (Int
startPrec Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
1) [(Name, Bool)]
bnd PTerm
ty Doc OutputAnnotation
-> Doc OutputAnnotation -> Doc OutputAnnotation
forall a. Doc a -> Doc a -> Doc a
<+> String -> Doc OutputAnnotation
forall a. String -> Doc a
text String
"=>" Doc OutputAnnotation
-> Doc OutputAnnotation -> Doc OutputAnnotation
forall a. Doc a -> Doc a -> Doc a
</> Maybe Int -> Int -> [(Name, Bool)] -> PTerm -> Doc OutputAnnotation
prettySe (Maybe Int -> Maybe Int
decD Maybe Int
d) Int
startPrec ((Name
n, Bool
True)(Name, Bool) -> [(Name, Bool)] -> [(Name, Bool)]
forall a. a -> [a] -> [a]
:[(Name, Bool)]
bnd) PTerm
sc
    prettySe Maybe Int
d Int
p [(Name, Bool)]
bnd (PPi (TacImp [ArgOpt]
_ Static
_ (PTactics [ProofSearch{}]) RigCount
rig) Name
n FC
_ PTerm
ty PTerm
sc) =
      Doc OutputAnnotation
lbrace Doc OutputAnnotation
-> Doc OutputAnnotation -> Doc OutputAnnotation
forall a. Doc a -> Doc a -> Doc a
<> String -> Doc OutputAnnotation
kwd String
"auto" Doc OutputAnnotation
-> Doc OutputAnnotation -> Doc OutputAnnotation
forall a. Doc a -> Doc a -> Doc a
<+> Name -> Doc OutputAnnotation
forall a ty. Pretty a ty => a -> Doc ty
pretty Name
n Doc OutputAnnotation
-> Doc OutputAnnotation -> Doc OutputAnnotation
forall a. Doc a -> Doc a -> Doc a
<+> Doc OutputAnnotation
forall a. Doc a
colon Doc OutputAnnotation
-> Doc OutputAnnotation -> Doc OutputAnnotation
forall a. Doc a -> Doc a -> Doc a
<+> Maybe Int -> Int -> [(Name, Bool)] -> PTerm -> Doc OutputAnnotation
prettySe (Maybe Int -> Maybe Int
decD Maybe Int
d) Int
startPrec [(Name, Bool)]
bnd PTerm
ty Doc OutputAnnotation
-> Doc OutputAnnotation -> Doc OutputAnnotation
forall a. Doc a -> Doc a -> Doc a
<>
      Doc OutputAnnotation
rbrace Doc OutputAnnotation
-> Doc OutputAnnotation -> Doc OutputAnnotation
forall a. Doc a -> Doc a -> Doc a
<+> String -> Doc OutputAnnotation
forall a. String -> Doc a
text String
"->" Doc OutputAnnotation
-> Doc OutputAnnotation -> Doc OutputAnnotation
forall a. Doc a -> Doc a -> Doc a
</> Maybe Int -> Int -> [(Name, Bool)] -> PTerm -> Doc OutputAnnotation
prettySe (Maybe Int -> Maybe Int
decD Maybe Int
d) Int
startPrec ((Name
n, Bool
True)(Name, Bool) -> [(Name, Bool)] -> [(Name, Bool)]
forall a. a -> [a] -> [a]
:[(Name, Bool)]
bnd) PTerm
sc
    prettySe Maybe Int
d Int
p [(Name, Bool)]
bnd (PPi (TacImp [ArgOpt]
_ Static
_ PTerm
s RigCount
rig) Name
n FC
_ PTerm
ty PTerm
sc) =
      Maybe Int -> Doc OutputAnnotation -> Doc OutputAnnotation
forall {a} {a}. (Ord a, Num a) => Maybe a -> Doc a -> Doc a
depth Maybe Int
d (Doc OutputAnnotation -> Doc OutputAnnotation)
-> (Doc OutputAnnotation -> Doc OutputAnnotation)
-> Doc OutputAnnotation
-> Doc OutputAnnotation
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int -> Int -> Doc OutputAnnotation -> Doc OutputAnnotation
forall {a} {a}. Ord a => a -> a -> Doc a -> Doc a
bracket Int
p Int
startPrec (Doc OutputAnnotation -> Doc OutputAnnotation)
-> Doc OutputAnnotation -> Doc OutputAnnotation
forall a b. (a -> b) -> a -> b
$
      Doc OutputAnnotation
lbrace Doc OutputAnnotation
-> Doc OutputAnnotation -> Doc OutputAnnotation
forall a. Doc a -> Doc a -> Doc a
<> String -> Doc OutputAnnotation
kwd String
"default" Doc OutputAnnotation
-> Doc OutputAnnotation -> Doc OutputAnnotation
forall a. Doc a -> Doc a -> Doc a
<+> Maybe Int -> Int -> [(Name, Bool)] -> PTerm -> Doc OutputAnnotation
prettySe (Maybe Int -> Maybe Int
decD Maybe Int
d) (Int
funcAppPrec Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
1) [(Name, Bool)]
bnd PTerm
s Doc OutputAnnotation
-> Doc OutputAnnotation -> Doc OutputAnnotation
forall a. Doc a -> Doc a -> Doc a
<+> Name -> Doc OutputAnnotation
forall a ty. Pretty a ty => a -> Doc ty
pretty Name
n Doc OutputAnnotation
-> Doc OutputAnnotation -> Doc OutputAnnotation
forall a. Doc a -> Doc a -> Doc a
<+> Doc OutputAnnotation
forall a. Doc a
colon Doc OutputAnnotation
-> Doc OutputAnnotation -> Doc OutputAnnotation
forall a. Doc a -> Doc a -> Doc a
<+> Maybe Int -> Int -> [(Name, Bool)] -> PTerm -> Doc OutputAnnotation
prettySe (Maybe Int -> Maybe Int
decD Maybe Int
d) Int
startPrec [(Name, Bool)]
bnd PTerm
ty Doc OutputAnnotation
-> Doc OutputAnnotation -> Doc OutputAnnotation
forall a. Doc a -> Doc a -> Doc a
<>
      Doc OutputAnnotation
rbrace Doc OutputAnnotation
-> Doc OutputAnnotation -> Doc OutputAnnotation
forall a. Doc a -> Doc a -> Doc a
<+> String -> Doc OutputAnnotation
forall a. String -> Doc a
text String
"->" Doc OutputAnnotation
-> Doc OutputAnnotation -> Doc OutputAnnotation
forall a. Doc a -> Doc a -> Doc a
</> Maybe Int -> Int -> [(Name, Bool)] -> PTerm -> Doc OutputAnnotation
prettySe (Maybe Int -> Maybe Int
decD Maybe Int
d) Int
startPrec ((Name
n, Bool
True)(Name, Bool) -> [(Name, Bool)] -> [(Name, Bool)]
forall a. a -> [a] -> [a]
:[(Name, Bool)]
bnd) PTerm
sc
    prettySe Maybe Int
d Int
p [(Name, Bool)]
bnd (PApp FC
_ (PRef FC
_ [FC]
_ Name
neg) [PArg
_, PArg
_, PArg
val])
      | Name -> Name
basename Name
neg Name -> Name -> Bool
forall a. Eq a => a -> a -> Bool
== String -> Name
sUN String
"negate" =
         Doc OutputAnnotation
forall a. Doc a
lparen Doc OutputAnnotation
-> Doc OutputAnnotation -> Doc OutputAnnotation
forall a. Doc a -> Doc a -> Doc a
<> String -> Doc OutputAnnotation
forall a. String -> Doc a
text String
"-" Doc OutputAnnotation
-> Doc OutputAnnotation -> Doc OutputAnnotation
forall a. Doc a -> Doc a -> Doc a
<> Maybe Int -> Int -> [(Name, Bool)] -> PTerm -> Doc OutputAnnotation
prettySe Maybe Int
d Int
funcAppPrec [(Name, Bool)]
bnd (PArg -> PTerm
forall t. PArg' t -> t
getTm PArg
val) Doc OutputAnnotation
-> Doc OutputAnnotation -> Doc OutputAnnotation
forall a. Doc a -> Doc a -> Doc a
<> Doc OutputAnnotation
forall a. Doc a
rparen
    -- This case preserves the behavior of the former constructor PEq.
    -- It should be removed if feasible when the pretty-printing of infix
    -- operators in general is improved.
    prettySe Maybe Int
d Int
p [(Name, Bool)]
bnd (PApp FC
_ (PRef FC
_ [FC]
_ Name
n) [PArg
lt, PArg
rt, PArg
l, PArg
r])
      | Name
n Name -> Name -> Bool
forall a. Eq a => a -> a -> Bool
== Name
eqTy, PPOption -> Bool
ppopt_impl PPOption
ppo =
          Maybe Int -> Doc OutputAnnotation -> Doc OutputAnnotation
forall {a} {a}. (Ord a, Num a) => Maybe a -> Doc a -> Doc a
depth Maybe Int
d (Doc OutputAnnotation -> Doc OutputAnnotation)
-> (Doc OutputAnnotation -> Doc OutputAnnotation)
-> Doc OutputAnnotation
-> Doc OutputAnnotation
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int -> Int -> Doc OutputAnnotation -> Doc OutputAnnotation
forall {a} {a}. Ord a => a -> a -> Doc a -> Doc a
bracket Int
p Int
eqPrec (Doc OutputAnnotation -> Doc OutputAnnotation)
-> Doc OutputAnnotation -> Doc OutputAnnotation
forall a b. (a -> b) -> a -> b
$
            Doc OutputAnnotation
-> Doc OutputAnnotation
-> Doc OutputAnnotation
-> Doc OutputAnnotation
forall a. Doc a -> Doc a -> Doc a -> Doc a
enclose Doc OutputAnnotation
forall a. Doc a
lparen Doc OutputAnnotation
forall a. Doc a
rparen Doc OutputAnnotation
eq Doc OutputAnnotation
-> Doc OutputAnnotation -> Doc OutputAnnotation
forall a. Doc a -> Doc a -> Doc a
<+>
            Doc OutputAnnotation -> Doc OutputAnnotation
forall a. Doc a -> Doc a
align (Doc OutputAnnotation -> Doc OutputAnnotation
forall a. Doc a -> Doc a
group ([Doc OutputAnnotation] -> Doc OutputAnnotation
forall a. [Doc a] -> Doc a
vsep ((PArg -> Doc OutputAnnotation) -> [PArg] -> [Doc OutputAnnotation]
forall a b. (a -> b) -> [a] -> [b]
map (Maybe Int -> [(Name, Bool)] -> PArg -> Doc OutputAnnotation
prettyArgS (Maybe Int -> Maybe Int
decD Maybe Int
d) [(Name, Bool)]
bnd)
                                    [PArg
lt, PArg
rt, PArg
l, PArg
r])))
      | Name
n Name -> Name -> Bool
forall a. Eq a => a -> a -> Bool
== Name
eqTy =
          Maybe Int -> Doc OutputAnnotation -> Doc OutputAnnotation
forall {a} {a}. (Ord a, Num a) => Maybe a -> Doc a -> Doc a
depth Maybe Int
d (Doc OutputAnnotation -> Doc OutputAnnotation)
-> (Doc OutputAnnotation -> Doc OutputAnnotation)
-> Doc OutputAnnotation
-> Doc OutputAnnotation
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int -> Int -> Doc OutputAnnotation -> Doc OutputAnnotation
forall {a} {a}. Ord a => a -> a -> Doc a -> Doc a
bracket Int
p Int
eqPrec (Doc OutputAnnotation -> Doc OutputAnnotation)
-> (Doc OutputAnnotation -> Doc OutputAnnotation)
-> Doc OutputAnnotation
-> Doc OutputAnnotation
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Doc OutputAnnotation -> Doc OutputAnnotation
forall a. Doc a -> Doc a
align (Doc OutputAnnotation -> Doc OutputAnnotation)
-> (Doc OutputAnnotation -> Doc OutputAnnotation)
-> Doc OutputAnnotation
-> Doc OutputAnnotation
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Doc OutputAnnotation -> Doc OutputAnnotation
forall a. Doc a -> Doc a
group (Doc OutputAnnotation -> Doc OutputAnnotation)
-> Doc OutputAnnotation -> Doc OutputAnnotation
forall a b. (a -> b) -> a -> b
$
            PTerm -> Doc OutputAnnotation
prettyTerm (PArg -> PTerm
forall t. PArg' t -> t
getTm PArg
l) Doc OutputAnnotation
-> Doc OutputAnnotation -> Doc OutputAnnotation
forall a. Doc a -> Doc a -> Doc a
<+> Doc OutputAnnotation
eq Doc OutputAnnotation
-> Doc OutputAnnotation -> Doc OutputAnnotation
forall a. Doc a -> Doc a -> Doc a
<$> Doc OutputAnnotation -> Doc OutputAnnotation
forall a. Doc a -> Doc a
group (PTerm -> Doc OutputAnnotation
prettyTerm (PArg -> PTerm
forall t. PArg' t -> t
getTm PArg
r))
      where eq :: Doc OutputAnnotation
eq = Name -> Doc OutputAnnotation -> Doc OutputAnnotation
annName Name
eqTy (String -> Doc OutputAnnotation
forall a. String -> Doc a
text String
"=")
            eqPrec :: Int
eqPrec = Int
startPrec
            prettyTerm :: PTerm -> Doc OutputAnnotation
prettyTerm = Maybe Int -> Int -> [(Name, Bool)] -> PTerm -> Doc OutputAnnotation
prettySe (Maybe Int -> Maybe Int
decD Maybe Int
d) (Int
eqPrec Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
1) [(Name, Bool)]
bnd
    prettySe Maybe Int
d Int
p [(Name, Bool)]
bnd (PApp FC
_ (PRef FC
_ [FC]
_ Name
f) [PArg]
args) -- normal names, no explicit args
      | UN Text
nm <- Name -> Name
basename Name
f
      , Bool -> Bool
not (PPOption -> Bool
ppopt_impl PPOption
ppo) Bool -> Bool -> Bool
&& [PArg] -> Bool
forall a. [a] -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null ([PArg] -> [PArg]
getShowArgs [PArg]
args) =
          Bool -> Bool -> [(Name, Bool)] -> Name -> Doc OutputAnnotation
prettyName Bool
True (PPOption -> Bool
ppopt_impl PPOption
ppo) [(Name, Bool)]
bnd Name
f
    prettySe Maybe Int
d Int
p [(Name, Bool)]
bnd (PAppBind FC
_ (PRef FC
_ [FC]
_ Name
f) [])
      | Bool -> Bool
not (PPOption -> Bool
ppopt_impl PPOption
ppo) = String -> Doc OutputAnnotation
forall a. String -> Doc a
text String
"!" Doc OutputAnnotation
-> Doc OutputAnnotation -> Doc OutputAnnotation
forall a. Doc a -> Doc a -> Doc a
<> Bool -> Bool -> [(Name, Bool)] -> Name -> Doc OutputAnnotation
prettyName Bool
True (PPOption -> Bool
ppopt_impl PPOption
ppo) [(Name, Bool)]
bnd Name
f
    prettySe Maybe Int
d Int
p [(Name, Bool)]
bnd (PApp FC
_ (PRef FC
_ [FC]
_ Name
op) [PArg]
args) -- infix operators
      | UN Text
nm <- Name -> Name
basename Name
op
      , Bool -> Bool
not (Text -> Bool
tnull Text
nm) Bool -> Bool -> Bool
&&
        (Bool -> Bool
not (PPOption -> Bool
ppopt_impl PPOption
ppo)) Bool -> Bool -> Bool
&& (Bool -> Bool
not (Bool -> Bool) -> Bool -> Bool
forall a b. (a -> b) -> a -> b
$ Char -> Bool
isAlpha (Text -> Char
thead Text
nm)) =
          case [PArg] -> [PArg]
getShowArgs [PArg]
args of
            [] -> Bool -> Doc OutputAnnotation
opName Bool
True
            [PArg
x] -> Doc OutputAnnotation -> Doc OutputAnnotation
forall a. Doc a -> Doc a
group (Bool -> Doc OutputAnnotation
opName Bool
True Doc OutputAnnotation
-> Doc OutputAnnotation -> Doc OutputAnnotation
forall a. Doc a -> Doc a -> Doc a
<$> Doc OutputAnnotation -> Doc OutputAnnotation
forall a. Doc a -> Doc a
group (Maybe Int -> Int -> [(Name, Bool)] -> PTerm -> Doc OutputAnnotation
prettySe (Maybe Int -> Maybe Int
decD Maybe Int
d) Int
startPrec [(Name, Bool)]
bnd (PArg -> PTerm
forall t. PArg' t -> t
getTm PArg
x)))
            [PArg
l,PArg
r] -> let precedence :: Int
precedence = Int -> (Fixity -> Int) -> Maybe Fixity -> Int
forall b a. b -> (a -> b) -> Maybe a -> b
maybe (Int
startPrec Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
1) Fixity -> Int
prec Maybe Fixity
f
                     in Maybe Int -> Doc OutputAnnotation -> Doc OutputAnnotation
forall {a} {a}. (Ord a, Num a) => Maybe a -> Doc a -> Doc a
depth Maybe Int
d (Doc OutputAnnotation -> Doc OutputAnnotation)
-> (Doc OutputAnnotation -> Doc OutputAnnotation)
-> Doc OutputAnnotation
-> Doc OutputAnnotation
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int -> Int -> Doc OutputAnnotation -> Doc OutputAnnotation
forall {a} {a}. Ord a => a -> a -> Doc a -> Doc a
bracket Int
p Int
precedence (Doc OutputAnnotation -> Doc OutputAnnotation)
-> Doc OutputAnnotation -> Doc OutputAnnotation
forall a b. (a -> b) -> a -> b
$ PTerm -> PTerm -> Doc OutputAnnotation
inFix (PArg -> PTerm
forall t. PArg' t -> t
getTm PArg
l) (PArg -> PTerm
forall t. PArg' t -> t
getTm PArg
r)
            (l :: PArg
l@(PExp{}) : r :: PArg
r@(PExp{}) : [PArg]
rest) ->
                   Maybe Int -> Doc OutputAnnotation -> Doc OutputAnnotation
forall {a} {a}. (Ord a, Num a) => Maybe a -> Doc a -> Doc a
depth Maybe Int
d (Doc OutputAnnotation -> Doc OutputAnnotation)
-> (Doc OutputAnnotation -> Doc OutputAnnotation)
-> Doc OutputAnnotation
-> Doc OutputAnnotation
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int -> Int -> Doc OutputAnnotation -> Doc OutputAnnotation
forall {a} {a}. Ord a => a -> a -> Doc a -> Doc a
bracket Int
p Int
funcAppPrec (Doc OutputAnnotation -> Doc OutputAnnotation)
-> Doc OutputAnnotation -> Doc OutputAnnotation
forall a b. (a -> b) -> a -> b
$
                          Doc OutputAnnotation
-> Doc OutputAnnotation
-> Doc OutputAnnotation
-> Doc OutputAnnotation
forall a. Doc a -> Doc a -> Doc a -> Doc a
enclose Doc OutputAnnotation
forall a. Doc a
lparen Doc OutputAnnotation
forall a. Doc a
rparen (PTerm -> PTerm -> Doc OutputAnnotation
inFix (PArg -> PTerm
forall t. PArg' t -> t
getTm PArg
l) (PArg -> PTerm
forall t. PArg' t -> t
getTm PArg
r)) Doc OutputAnnotation
-> Doc OutputAnnotation -> Doc OutputAnnotation
forall a. Doc a -> Doc a -> Doc a
<+>
                          Doc OutputAnnotation -> Doc OutputAnnotation
forall a. Doc a -> Doc a
align (Doc OutputAnnotation -> Doc OutputAnnotation
forall a. Doc a -> Doc a
group ([Doc OutputAnnotation] -> Doc OutputAnnotation
forall a. [Doc a] -> Doc a
vsep ((PArg -> Doc OutputAnnotation) -> [PArg] -> [Doc OutputAnnotation]
forall a b. (a -> b) -> [a] -> [b]
map (Maybe Int -> [(Name, Bool)] -> PArg -> Doc OutputAnnotation
prettyArgS Maybe Int
d [(Name, Bool)]
bnd) [PArg]
rest)))
            [PArg]
as -> Bool -> Doc OutputAnnotation
opName Bool
True Doc OutputAnnotation
-> Doc OutputAnnotation -> Doc OutputAnnotation
forall a. Doc a -> Doc a -> Doc a
<+> Doc OutputAnnotation -> Doc OutputAnnotation
forall a. Doc a -> Doc a
align ([Doc OutputAnnotation] -> Doc OutputAnnotation
forall a. [Doc a] -> Doc a
vsep ((PArg -> Doc OutputAnnotation) -> [PArg] -> [Doc OutputAnnotation]
forall a b. (a -> b) -> [a] -> [b]
map (Maybe Int -> [(Name, Bool)] -> PArg -> Doc OutputAnnotation
prettyArgS Maybe Int
d [(Name, Bool)]
bnd) [PArg]
as))
          where opName :: Bool -> Doc OutputAnnotation
opName Bool
isPrefix = Bool -> Bool -> [(Name, Bool)] -> Name -> Doc OutputAnnotation
prettyName Bool
isPrefix (PPOption -> Bool
ppopt_impl PPOption
ppo) [(Name, Bool)]
bnd Name
op
                f :: Maybe Fixity
f = String -> Maybe Fixity
getFixity (Name -> String
opStr Name
op)
                left :: Int
left = case Maybe Fixity
f of
                           Maybe Fixity
Nothing -> Int
funcAppPrec Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
1
                           Just (Infixl Int
p') -> Int
p'
                           Just Fixity
f' -> Fixity -> Int
prec Fixity
f' Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
1
                right :: Int
right = case Maybe Fixity
f of
                            Maybe Fixity
Nothing -> Int
funcAppPrec Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
1
                            Just (Infixr Int
p') -> Int
p'
                            Just Fixity
f' -> Fixity -> Int
prec Fixity
f' Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
1
                inFix :: PTerm -> PTerm -> Doc OutputAnnotation
inFix PTerm
l PTerm
r = Doc OutputAnnotation -> Doc OutputAnnotation
forall a. Doc a -> Doc a
align (Doc OutputAnnotation -> Doc OutputAnnotation)
-> (Doc OutputAnnotation -> Doc OutputAnnotation)
-> Doc OutputAnnotation
-> Doc OutputAnnotation
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Doc OutputAnnotation -> Doc OutputAnnotation
forall a. Doc a -> Doc a
group (Doc OutputAnnotation -> Doc OutputAnnotation)
-> Doc OutputAnnotation -> Doc OutputAnnotation
forall a b. (a -> b) -> a -> b
$
                  (Maybe Int -> Int -> [(Name, Bool)] -> PTerm -> Doc OutputAnnotation
prettySe (Maybe Int -> Maybe Int
decD Maybe Int
d) Int
left [(Name, Bool)]
bnd PTerm
l Doc OutputAnnotation
-> Doc OutputAnnotation -> Doc OutputAnnotation
forall a. Doc a -> Doc a -> Doc a
<+> Bool -> Doc OutputAnnotation
opName Bool
False) Doc OutputAnnotation
-> Doc OutputAnnotation -> Doc OutputAnnotation
forall a. Doc a -> Doc a -> Doc a
<$>
                    Doc OutputAnnotation -> Doc OutputAnnotation
forall a. Doc a -> Doc a
group (Maybe Int -> Int -> [(Name, Bool)] -> PTerm -> Doc OutputAnnotation
prettySe (Maybe Int -> Maybe Int
decD Maybe Int
d) Int
right [(Name, Bool)]
bnd PTerm
r)
    prettySe Maybe Int
d Int
p [(Name, Bool)]
bnd (PApp FC
_ hd :: PTerm
hd@(PRef FC
fc [FC]
_ Name
f) [PArg
tm]) -- symbols, like 'foo
      | PConstant FC
NoFC (Idris.Core.TT.Str String
str) <- PArg -> PTerm
forall t. PArg' t -> t
getTm PArg
tm,
        Name
f Name -> Name -> Bool
forall a. Eq a => a -> a -> Bool
== String -> Name
sUN String
"Symbol_" = OutputAnnotation -> Doc OutputAnnotation -> Doc OutputAnnotation
forall a. a -> Doc a -> Doc a
annotate (String -> String -> OutputAnnotation
AnnType (String
"'" String -> ShowS
forall a. [a] -> [a] -> [a]
++ String
str) (String
"The symbol " String -> ShowS
forall a. [a] -> [a] -> [a]
++ String
str)) (Doc OutputAnnotation -> Doc OutputAnnotation)
-> Doc OutputAnnotation -> Doc OutputAnnotation
forall a b. (a -> b) -> a -> b
$
                               Char -> Doc OutputAnnotation
forall a. Char -> Doc a
char Char
'\'' Doc OutputAnnotation
-> Doc OutputAnnotation -> Doc OutputAnnotation
forall a. Doc a -> Doc a -> Doc a
<> Maybe Int -> Int -> [(Name, Bool)] -> PTerm -> Doc OutputAnnotation
prettySe (Maybe Int -> Maybe Int
decD Maybe Int
d) Int
startPrec [(Name, Bool)]
bnd (FC -> [FC] -> Name -> PTerm
PRef FC
fc [] (String -> Name
sUN String
str))
    prettySe Maybe Int
d Int
p [(Name, Bool)]
bnd (PApp FC
_ PTerm
f [PArg]
as) = -- Normal prefix applications
      let args :: [PArg]
args = [PArg] -> [PArg]
getShowArgs [PArg]
as
          fp :: Doc OutputAnnotation
fp   = Maybe Int -> Int -> [(Name, Bool)] -> PTerm -> Doc OutputAnnotation
prettySe (Maybe Int -> Maybe Int
decD Maybe Int
d) (Int
startPrec Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
1) [(Name, Bool)]
bnd PTerm
f
          shownArgs :: [PArg]
shownArgs = if PPOption -> Bool
ppopt_impl PPOption
ppo then [PArg]
as else [PArg]
args
      in
        Maybe Int -> Doc OutputAnnotation -> Doc OutputAnnotation
forall {a} {a}. (Ord a, Num a) => Maybe a -> Doc a -> Doc a
depth Maybe Int
d (Doc OutputAnnotation -> Doc OutputAnnotation)
-> (Doc OutputAnnotation -> Doc OutputAnnotation)
-> Doc OutputAnnotation
-> Doc OutputAnnotation
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int -> Int -> Doc OutputAnnotation -> Doc OutputAnnotation
forall {a} {a}. Ord a => a -> a -> Doc a -> Doc a
bracket Int
p Int
funcAppPrec (Doc OutputAnnotation -> Doc OutputAnnotation)
-> (Doc OutputAnnotation -> Doc OutputAnnotation)
-> Doc OutputAnnotation
-> Doc OutputAnnotation
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Doc OutputAnnotation -> Doc OutputAnnotation
forall a. Doc a -> Doc a
group (Doc OutputAnnotation -> Doc OutputAnnotation)
-> Doc OutputAnnotation -> Doc OutputAnnotation
forall a b. (a -> b) -> a -> b
$
            if [PArg] -> Bool
forall a. [a] -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null [PArg]
shownArgs
              then Doc OutputAnnotation
fp
              else Doc OutputAnnotation
fp Doc OutputAnnotation
-> Doc OutputAnnotation -> Doc OutputAnnotation
forall a. Doc a -> Doc a -> Doc a
<+> Doc OutputAnnotation -> Doc OutputAnnotation
forall a. Doc a -> Doc a
align ([Doc OutputAnnotation] -> Doc OutputAnnotation
forall a. [Doc a] -> Doc a
vsep ((PArg -> Doc OutputAnnotation) -> [PArg] -> [Doc OutputAnnotation]
forall a b. (a -> b) -> [a] -> [b]
map (Maybe Int -> [(Name, Bool)] -> PArg -> Doc OutputAnnotation
prettyArgS Maybe Int
d [(Name, Bool)]
bnd) [PArg]
shownArgs))
    prettySe Maybe Int
d Int
p [(Name, Bool)]
bnd (PWithApp FC
_ PTerm
f PTerm
a) = Maybe Int -> Int -> [(Name, Bool)] -> PTerm -> Doc OutputAnnotation
prettySe Maybe Int
d Int
p [(Name, Bool)]
bnd PTerm
f Doc OutputAnnotation
-> Doc OutputAnnotation -> Doc OutputAnnotation
forall a. Doc a -> Doc a -> Doc a
<+> String -> Doc OutputAnnotation
forall a. String -> Doc a
text String
"|" Doc OutputAnnotation
-> Doc OutputAnnotation -> Doc OutputAnnotation
forall a. Doc a -> Doc a -> Doc a
<+> Maybe Int -> Int -> [(Name, Bool)] -> PTerm -> Doc OutputAnnotation
prettySe Maybe Int
d Int
p [(Name, Bool)]
bnd PTerm
a
    prettySe Maybe Int
d Int
p [(Name, Bool)]
bnd (PCase FC
_ PTerm
scr [(PTerm, PTerm)]
cases) =
      Int -> Int -> Doc OutputAnnotation -> Doc OutputAnnotation
forall {a} {a}. Ord a => a -> a -> Doc a -> Doc a
bracket Int
p Int
funcAppPrec (Doc OutputAnnotation -> Doc OutputAnnotation)
-> Doc OutputAnnotation -> Doc OutputAnnotation
forall a b. (a -> b) -> a -> b
$
          Doc OutputAnnotation -> Doc OutputAnnotation
forall a. Doc a -> Doc a
align (Doc OutputAnnotation -> Doc OutputAnnotation)
-> Doc OutputAnnotation -> Doc OutputAnnotation
forall a b. (a -> b) -> a -> b
$ String -> Doc OutputAnnotation
kwd String
"case" Doc OutputAnnotation
-> Doc OutputAnnotation -> Doc OutputAnnotation
forall a. Doc a -> Doc a -> Doc a
<+> Maybe Int -> Int -> [(Name, Bool)] -> PTerm -> Doc OutputAnnotation
prettySe (Maybe Int -> Maybe Int
decD Maybe Int
d) Int
startPrec [(Name, Bool)]
bnd PTerm
scr Doc OutputAnnotation
-> Doc OutputAnnotation -> Doc OutputAnnotation
forall a. Doc a -> Doc a -> Doc a
<+> String -> Doc OutputAnnotation
kwd String
"of" Doc OutputAnnotation
-> Doc OutputAnnotation -> Doc OutputAnnotation
forall a. Doc a -> Doc a -> Doc a
<$>
          Maybe Int -> Doc OutputAnnotation -> Doc OutputAnnotation
forall {a} {a}. (Ord a, Num a) => Maybe a -> Doc a -> Doc a
depth Maybe Int
d (Int -> Doc OutputAnnotation -> Doc OutputAnnotation
forall a. Int -> Doc a -> Doc a
indent Int
2 ([Doc OutputAnnotation] -> Doc OutputAnnotation
forall a. [Doc a] -> Doc a
vsep (((PTerm, PTerm) -> Doc OutputAnnotation)
-> [(PTerm, PTerm)] -> [Doc OutputAnnotation]
forall a b. (a -> b) -> [a] -> [b]
map (PTerm, PTerm) -> Doc OutputAnnotation
ppcase [(PTerm, PTerm)]
cases)))
      where
        ppcase :: (PTerm, PTerm) -> Doc OutputAnnotation
ppcase (PTerm
l, PTerm
r) = let prettyCase :: PTerm -> Doc OutputAnnotation
prettyCase = Maybe Int -> Int -> [(Name, Bool)] -> PTerm -> Doc OutputAnnotation
prettySe (Maybe Int -> Maybe Int
decD Maybe Int
d) Int
startPrec
                                         ([(Name
n, Bool
False) | Name
n <- PTerm -> [Name]
vars PTerm
l] [(Name, Bool)] -> [(Name, Bool)] -> [(Name, Bool)]
forall a. [a] -> [a] -> [a]
++ [(Name, Bool)]
bnd)
                        in Int -> Doc OutputAnnotation -> Doc OutputAnnotation
forall a. Int -> Doc a -> Doc a
nest Int
nestingSize (Doc OutputAnnotation -> Doc OutputAnnotation)
-> Doc OutputAnnotation -> Doc OutputAnnotation
forall a b. (a -> b) -> a -> b
$
                             PTerm -> Doc OutputAnnotation
prettyCase PTerm
l Doc OutputAnnotation
-> Doc OutputAnnotation -> Doc OutputAnnotation
forall a. Doc a -> Doc a -> Doc a
<+> String -> Doc OutputAnnotation
forall a. String -> Doc a
text String
"=>" Doc OutputAnnotation
-> Doc OutputAnnotation -> Doc OutputAnnotation
forall a. Doc a -> Doc a -> Doc a
<+> PTerm -> Doc OutputAnnotation
prettyCase PTerm
r
        -- Warning: this is a bit of a hack. At this stage, we don't have the
        -- global context, so we can't determine which names are constructors,
        -- which are types, and which are pattern variables on the LHS of the
        -- case pattern. We use the heuristic that names without a namespace
        -- are patvars, because right now case blocks in PTerms are always
        -- delaborated from TT before being sent to the pretty-printer. If they
        -- start getting printed directly, THIS WILL BREAK.
        -- Potential solution: add a list of known patvars to the cases in
        -- PCase, and have the delaborator fill it out, kind of like the pun
        -- disambiguation on PDPair.
        vars :: PTerm -> [Name]
vars PTerm
tm = (Name -> Bool) -> [Name] -> [Name]
forall a. (a -> Bool) -> [a] -> [a]
filter Name -> Bool
noNS (PTerm -> [Name]
allNamesIn PTerm
tm)
        noNS :: Name -> Bool
noNS (NS Name
_ [Text]
_) = Bool
False
        noNS Name
_        = Bool
True

    prettySe Maybe Int
d Int
p [(Name, Bool)]
bnd (PIfThenElse FC
_ PTerm
c PTerm
t PTerm
f) =
      Maybe Int -> Doc OutputAnnotation -> Doc OutputAnnotation
forall {a} {a}. (Ord a, Num a) => Maybe a -> Doc a -> Doc a
depth Maybe Int
d (Doc OutputAnnotation -> Doc OutputAnnotation)
-> ([Doc OutputAnnotation] -> Doc OutputAnnotation)
-> [Doc OutputAnnotation]
-> Doc OutputAnnotation
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int -> Int -> Doc OutputAnnotation -> Doc OutputAnnotation
forall {a} {a}. Ord a => a -> a -> Doc a -> Doc a
bracket Int
p Int
funcAppPrec (Doc OutputAnnotation -> Doc OutputAnnotation)
-> ([Doc OutputAnnotation] -> Doc OutputAnnotation)
-> [Doc OutputAnnotation]
-> Doc OutputAnnotation
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Doc OutputAnnotation -> Doc OutputAnnotation
forall a. Doc a -> Doc a
group (Doc OutputAnnotation -> Doc OutputAnnotation)
-> ([Doc OutputAnnotation] -> Doc OutputAnnotation)
-> [Doc OutputAnnotation]
-> Doc OutputAnnotation
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Doc OutputAnnotation -> Doc OutputAnnotation
forall a. Doc a -> Doc a
align (Doc OutputAnnotation -> Doc OutputAnnotation)
-> ([Doc OutputAnnotation] -> Doc OutputAnnotation)
-> [Doc OutputAnnotation]
-> Doc OutputAnnotation
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int -> Doc OutputAnnotation -> Doc OutputAnnotation
forall a. Int -> Doc a -> Doc a
hang Int
2 (Doc OutputAnnotation -> Doc OutputAnnotation)
-> ([Doc OutputAnnotation] -> Doc OutputAnnotation)
-> [Doc OutputAnnotation]
-> Doc OutputAnnotation
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [Doc OutputAnnotation] -> Doc OutputAnnotation
forall a. [Doc a] -> Doc a
vsep ([Doc OutputAnnotation] -> Doc OutputAnnotation)
-> [Doc OutputAnnotation] -> Doc OutputAnnotation
forall a b. (a -> b) -> a -> b
$
        [ String -> Doc OutputAnnotation
kwd String
"if"   Doc OutputAnnotation
-> Doc OutputAnnotation -> Doc OutputAnnotation
forall a. Doc a -> Doc a -> Doc a
<+> Maybe Int -> Int -> [(Name, Bool)] -> PTerm -> Doc OutputAnnotation
prettySe (Maybe Int -> Maybe Int
decD Maybe Int
d) Int
startPrec [(Name, Bool)]
bnd PTerm
c
        , String -> Doc OutputAnnotation
kwd String
"then" Doc OutputAnnotation
-> Doc OutputAnnotation -> Doc OutputAnnotation
forall a. Doc a -> Doc a -> Doc a
<+> Maybe Int -> Int -> [(Name, Bool)] -> PTerm -> Doc OutputAnnotation
prettySe (Maybe Int -> Maybe Int
decD Maybe Int
d) Int
startPrec [(Name, Bool)]
bnd PTerm
t
        , String -> Doc OutputAnnotation
kwd String
"else" Doc OutputAnnotation
-> Doc OutputAnnotation -> Doc OutputAnnotation
forall a. Doc a -> Doc a -> Doc a
<+> Maybe Int -> Int -> [(Name, Bool)] -> PTerm -> Doc OutputAnnotation
prettySe (Maybe Int -> Maybe Int
decD Maybe Int
d) Int
startPrec [(Name, Bool)]
bnd PTerm
f
        ]
    prettySe Maybe Int
d Int
p [(Name, Bool)]
bnd (PHidden PTerm
tm)         = String -> Doc OutputAnnotation
forall a. String -> Doc a
text String
"." Doc OutputAnnotation
-> Doc OutputAnnotation -> Doc OutputAnnotation
forall a. Doc a -> Doc a -> Doc a
<> Maybe Int -> Int -> [(Name, Bool)] -> PTerm -> Doc OutputAnnotation
prettySe (Maybe Int -> Maybe Int
decD Maybe Int
d) Int
funcAppPrec [(Name, Bool)]
bnd PTerm
tm
    prettySe Maybe Int
d Int
p [(Name, Bool)]
bnd (PResolveTC FC
_)       = Doc OutputAnnotation
percent Doc OutputAnnotation
-> Doc OutputAnnotation -> Doc OutputAnnotation
forall a. Doc a -> Doc a -> Doc a
<> String -> Doc OutputAnnotation
kwd String
"implementation"
    prettySe Maybe Int
d Int
p [(Name, Bool)]
bnd (PTrue FC
_ PunInfo
IsType)     = Name -> Doc OutputAnnotation -> Doc OutputAnnotation
annName Name
unitTy (Doc OutputAnnotation -> Doc OutputAnnotation)
-> Doc OutputAnnotation -> Doc OutputAnnotation
forall a b. (a -> b) -> a -> b
$ String -> Doc OutputAnnotation
forall a. String -> Doc a
text String
"()"
    prettySe Maybe Int
d Int
p [(Name, Bool)]
bnd (PTrue FC
_ PunInfo
IsTerm)     = Name -> Doc OutputAnnotation -> Doc OutputAnnotation
annName Name
unitCon (Doc OutputAnnotation -> Doc OutputAnnotation)
-> Doc OutputAnnotation -> Doc OutputAnnotation
forall a b. (a -> b) -> a -> b
$ String -> Doc OutputAnnotation
forall a. String -> Doc a
text String
"()"
    prettySe Maybe Int
d Int
p [(Name, Bool)]
bnd (PTrue FC
_ PunInfo
TypeOrTerm) = String -> Doc OutputAnnotation
forall a. String -> Doc a
text String
"()"
    prettySe Maybe Int
d Int
p [(Name, Bool)]
bnd (PRewrite FC
_ Maybe Name
by PTerm
l PTerm
r Maybe PTerm
_)   =
      Maybe Int -> Doc OutputAnnotation -> Doc OutputAnnotation
forall {a} {a}. (Ord a, Num a) => Maybe a -> Doc a -> Doc a
depth Maybe Int
d (Doc OutputAnnotation -> Doc OutputAnnotation)
-> (Doc OutputAnnotation -> Doc OutputAnnotation)
-> Doc OutputAnnotation
-> Doc OutputAnnotation
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int -> Int -> Doc OutputAnnotation -> Doc OutputAnnotation
forall {a} {a}. Ord a => a -> a -> Doc a -> Doc a
bracket Int
p Int
startPrec (Doc OutputAnnotation -> Doc OutputAnnotation)
-> Doc OutputAnnotation -> Doc OutputAnnotation
forall a b. (a -> b) -> a -> b
$
      String -> Doc OutputAnnotation
forall a. String -> Doc a
text String
"rewrite" Doc OutputAnnotation
-> Doc OutputAnnotation -> Doc OutputAnnotation
forall a. Doc a -> Doc a -> Doc a
<+> Maybe Int -> Int -> [(Name, Bool)] -> PTerm -> Doc OutputAnnotation
prettySe (Maybe Int -> Maybe Int
decD Maybe Int
d) (Int
startPrec Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
1) [(Name, Bool)]
bnd PTerm
l
      Doc OutputAnnotation
-> Doc OutputAnnotation -> Doc OutputAnnotation
forall a. Doc a -> Doc a -> Doc a
<+> (case Maybe Name
by of
               Maybe Name
Nothing -> Doc OutputAnnotation
forall a. Doc a
empty
               Just Name
fn -> String -> Doc OutputAnnotation
forall a. String -> Doc a
text String
"using" Doc OutputAnnotation
-> Doc OutputAnnotation -> Doc OutputAnnotation
forall a. Doc a -> Doc a -> Doc a
<+>
                              Bool -> Bool -> [(Name, Bool)] -> Name -> Doc OutputAnnotation
prettyName Bool
True (PPOption -> Bool
ppopt_impl PPOption
ppo) [(Name, Bool)]
bnd Name
fn) Doc OutputAnnotation
-> Doc OutputAnnotation -> Doc OutputAnnotation
forall a. Doc a -> Doc a -> Doc a
<+>
          String -> Doc OutputAnnotation
forall a. String -> Doc a
text String
"in" Doc OutputAnnotation
-> Doc OutputAnnotation -> Doc OutputAnnotation
forall a. Doc a -> Doc a -> Doc a
<+> Maybe Int -> Int -> [(Name, Bool)] -> PTerm -> Doc OutputAnnotation
prettySe (Maybe Int -> Maybe Int
decD Maybe Int
d) Int
startPrec [(Name, Bool)]
bnd PTerm
r
    prettySe Maybe Int
d Int
p [(Name, Bool)]
bnd (PTyped PTerm
l PTerm
r) =
      Doc OutputAnnotation
forall a. Doc a
lparen Doc OutputAnnotation
-> Doc OutputAnnotation -> Doc OutputAnnotation
forall a. Doc a -> Doc a -> Doc a
<> Maybe Int -> Int -> [(Name, Bool)] -> PTerm -> Doc OutputAnnotation
prettySe (Maybe Int -> Maybe Int
decD Maybe Int
d) Int
startPrec [(Name, Bool)]
bnd PTerm
l Doc OutputAnnotation
-> Doc OutputAnnotation -> Doc OutputAnnotation
forall a. Doc a -> Doc a -> Doc a
<+> Doc OutputAnnotation
forall a. Doc a
colon Doc OutputAnnotation
-> Doc OutputAnnotation -> Doc OutputAnnotation
forall a. Doc a -> Doc a -> Doc a
<+> Maybe Int -> Int -> [(Name, Bool)] -> PTerm -> Doc OutputAnnotation
prettySe (Maybe Int -> Maybe Int
decD Maybe Int
d) Int
startPrec [(Name, Bool)]
bnd PTerm
r Doc OutputAnnotation
-> Doc OutputAnnotation -> Doc OutputAnnotation
forall a. Doc a -> Doc a -> Doc a
<> Doc OutputAnnotation
forall a. Doc a
rparen
    prettySe Maybe Int
d Int
p [(Name, Bool)]
bnd pair :: PTerm
pair@(PPair FC
_ [FC]
_ PunInfo
pun PTerm
_ PTerm
_) -- flatten tuples to the right, like parser
      | Just [PTerm]
elts <- PTerm -> Maybe [PTerm]
pairElts PTerm
pair = Maybe Int -> Doc OutputAnnotation -> Doc OutputAnnotation
forall {a} {a}. (Ord a, Num a) => Maybe a -> Doc a -> Doc a
depth Maybe Int
d (Doc OutputAnnotation -> Doc OutputAnnotation)
-> ([Doc OutputAnnotation] -> Doc OutputAnnotation)
-> [Doc OutputAnnotation]
-> Doc OutputAnnotation
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Doc OutputAnnotation
-> Doc OutputAnnotation
-> Doc OutputAnnotation
-> Doc OutputAnnotation
forall a. Doc a -> Doc a -> Doc a -> Doc a
enclose (Doc OutputAnnotation -> Doc OutputAnnotation
ann Doc OutputAnnotation
forall a. Doc a
lparen) (Doc OutputAnnotation -> Doc OutputAnnotation
ann Doc OutputAnnotation
forall a. Doc a
rparen) (Doc OutputAnnotation -> Doc OutputAnnotation)
-> ([Doc OutputAnnotation] -> Doc OutputAnnotation)
-> [Doc OutputAnnotation]
-> Doc OutputAnnotation
forall b c a. (b -> c) -> (a -> b) -> a -> c
.
                                     Doc OutputAnnotation -> Doc OutputAnnotation
forall a. Doc a -> Doc a
align (Doc OutputAnnotation -> Doc OutputAnnotation)
-> ([Doc OutputAnnotation] -> Doc OutputAnnotation)
-> [Doc OutputAnnotation]
-> Doc OutputAnnotation
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Doc OutputAnnotation -> Doc OutputAnnotation
forall a. Doc a -> Doc a
group (Doc OutputAnnotation -> Doc OutputAnnotation)
-> ([Doc OutputAnnotation] -> Doc OutputAnnotation)
-> [Doc OutputAnnotation]
-> Doc OutputAnnotation
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [Doc OutputAnnotation] -> Doc OutputAnnotation
forall a. [Doc a] -> Doc a
vsep ([Doc OutputAnnotation] -> Doc OutputAnnotation)
-> ([Doc OutputAnnotation] -> [Doc OutputAnnotation])
-> [Doc OutputAnnotation]
-> Doc OutputAnnotation
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Doc OutputAnnotation
-> [Doc OutputAnnotation] -> [Doc OutputAnnotation]
forall a. Doc a -> [Doc a] -> [Doc a]
punctuate (Doc OutputAnnotation -> Doc OutputAnnotation
ann Doc OutputAnnotation
forall a. Doc a
comma) ([Doc OutputAnnotation] -> Doc OutputAnnotation)
-> [Doc OutputAnnotation] -> Doc OutputAnnotation
forall a b. (a -> b) -> a -> b
$
                                     (PTerm -> Doc OutputAnnotation)
-> [PTerm] -> [Doc OutputAnnotation]
forall a b. (a -> b) -> [a] -> [b]
map (Maybe Int -> Int -> [(Name, Bool)] -> PTerm -> Doc OutputAnnotation
prettySe (Maybe Int -> Maybe Int
decD Maybe Int
d) Int
startPrec [(Name, Bool)]
bnd) [PTerm]
elts
        where ann :: Doc OutputAnnotation -> Doc OutputAnnotation
ann = case PunInfo
pun of
                      PunInfo
TypeOrTerm -> Doc OutputAnnotation -> Doc OutputAnnotation
forall a. a -> a
id
                      PunInfo
IsType -> Name -> Doc OutputAnnotation -> Doc OutputAnnotation
annName Name
pairTy
                      PunInfo
IsTerm -> Name -> Doc OutputAnnotation -> Doc OutputAnnotation
annName Name
pairCon
    prettySe Maybe Int
d Int
p [(Name, Bool)]
bnd dpair :: PTerm
dpair@(PDPair FC
_ [FC]
_ PunInfo
pun PTerm
l PTerm
t PTerm
r)
      | Just [(PTerm, PTerm)]
elts <- PTerm -> Maybe [(PTerm, PTerm)]
dPairElts PTerm
dpair
      = Maybe Int -> Doc OutputAnnotation -> Doc OutputAnnotation
forall {a} {a}. (Ord a, Num a) => Maybe a -> Doc a -> Doc a
depth Maybe Int
d (Doc OutputAnnotation -> Doc OutputAnnotation)
-> ([Doc OutputAnnotation] -> Doc OutputAnnotation)
-> [Doc OutputAnnotation]
-> Doc OutputAnnotation
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Doc OutputAnnotation
-> Doc OutputAnnotation
-> Doc OutputAnnotation
-> Doc OutputAnnotation
forall a. Doc a -> Doc a -> Doc a -> Doc a
enclose (Doc OutputAnnotation -> Doc OutputAnnotation
annotated Doc OutputAnnotation
forall a. Doc a
lparen) (Doc OutputAnnotation -> Doc OutputAnnotation
annotated Doc OutputAnnotation
forall a. Doc a
rparen) (Doc OutputAnnotation -> Doc OutputAnnotation)
-> ([Doc OutputAnnotation] -> Doc OutputAnnotation)
-> [Doc OutputAnnotation]
-> Doc OutputAnnotation
forall b c a. (b -> c) -> (a -> b) -> a -> c
.
        Doc OutputAnnotation -> Doc OutputAnnotation
forall a. Doc a -> Doc a
align (Doc OutputAnnotation -> Doc OutputAnnotation)
-> ([Doc OutputAnnotation] -> Doc OutputAnnotation)
-> [Doc OutputAnnotation]
-> Doc OutputAnnotation
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Doc OutputAnnotation -> Doc OutputAnnotation
forall a. Doc a -> Doc a
group (Doc OutputAnnotation -> Doc OutputAnnotation)
-> ([Doc OutputAnnotation] -> Doc OutputAnnotation)
-> [Doc OutputAnnotation]
-> Doc OutputAnnotation
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [Doc OutputAnnotation] -> Doc OutputAnnotation
forall a. [Doc a] -> Doc a
vsep ([Doc OutputAnnotation] -> Doc OutputAnnotation)
-> ([Doc OutputAnnotation] -> [Doc OutputAnnotation])
-> [Doc OutputAnnotation]
-> Doc OutputAnnotation
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Doc OutputAnnotation
-> [Doc OutputAnnotation] -> [Doc OutputAnnotation]
forall a. Doc a -> [Doc a] -> [Doc a]
punctuate (Doc OutputAnnotation
forall a. Doc a
space Doc OutputAnnotation
-> Doc OutputAnnotation -> Doc OutputAnnotation
forall a. Doc a -> Doc a -> Doc a
<> Doc OutputAnnotation -> Doc OutputAnnotation
annotated (String -> Doc OutputAnnotation
forall a. String -> Doc a
text String
"**")) ([Doc OutputAnnotation] -> Doc OutputAnnotation)
-> [Doc OutputAnnotation] -> Doc OutputAnnotation
forall a b. (a -> b) -> a -> b
$
        [(PTerm, PTerm)] -> [(Name, Bool)] -> [Doc OutputAnnotation]
ppElts [(PTerm, PTerm)]
elts [(Name, Bool)]
bnd
      | Bool
otherwise
      = Maybe Int -> Doc OutputAnnotation -> Doc OutputAnnotation
forall {a} {a}. (Ord a, Num a) => Maybe a -> Doc a -> Doc a
depth Maybe Int
d (Doc OutputAnnotation -> Doc OutputAnnotation)
-> Doc OutputAnnotation -> Doc OutputAnnotation
forall a b. (a -> b) -> a -> b
$
        Doc OutputAnnotation -> Doc OutputAnnotation
annotated Doc OutputAnnotation
forall a. Doc a
lparen Doc OutputAnnotation
-> Doc OutputAnnotation -> Doc OutputAnnotation
forall a. Doc a -> Doc a -> Doc a
<>
        Doc OutputAnnotation
left Doc OutputAnnotation
-> Doc OutputAnnotation -> Doc OutputAnnotation
forall a. Doc a -> Doc a -> Doc a
<+>
        Doc OutputAnnotation -> Doc OutputAnnotation
annotated (String -> Doc OutputAnnotation
forall a. String -> Doc a
text String
"**") Doc OutputAnnotation
-> Doc OutputAnnotation -> Doc OutputAnnotation
forall a. Doc a -> Doc a -> Doc a
<+>
        Maybe Int -> Int -> [(Name, Bool)] -> PTerm -> Doc OutputAnnotation
prettySe (Maybe Int -> Maybe Int
decD Maybe Int
d) Int
startPrec ([(Name, Bool)] -> [(Name, Bool)]
addBinding [(Name, Bool)]
bnd) PTerm
r Doc OutputAnnotation
-> Doc OutputAnnotation -> Doc OutputAnnotation
forall a. Doc a -> Doc a -> Doc a
<>
        Doc OutputAnnotation -> Doc OutputAnnotation
annotated Doc OutputAnnotation
forall a. Doc a
rparen
      where annotated :: Doc OutputAnnotation -> Doc OutputAnnotation
annotated = case PunInfo
pun of
              PunInfo
IsType -> Name -> Doc OutputAnnotation -> Doc OutputAnnotation
annName Name
sigmaTy
              PunInfo
IsTerm -> Name -> Doc OutputAnnotation -> Doc OutputAnnotation
annName Name
sigmaCon
              PunInfo
TypeOrTerm -> Doc OutputAnnotation -> Doc OutputAnnotation
forall a. a -> a
id

            (Doc OutputAnnotation
left, [(Name, Bool)] -> [(Name, Bool)]
addBinding) = case (PTerm
l, PunInfo
pun) of
              (PRef FC
_ [FC]
_ Name
n, PunInfo
IsType) -> (Name -> Bool -> Doc OutputAnnotation
bindingOf Name
n Bool
False Doc OutputAnnotation
-> Doc OutputAnnotation -> Doc OutputAnnotation
forall a. Doc a -> Doc a -> Doc a
<+> String -> Doc OutputAnnotation
forall a. String -> Doc a
text String
":" Doc OutputAnnotation
-> Doc OutputAnnotation -> Doc OutputAnnotation
forall a. Doc a -> Doc a -> Doc a
<+> Maybe Int -> Int -> [(Name, Bool)] -> PTerm -> Doc OutputAnnotation
prettySe (Maybe Int -> Maybe Int
decD Maybe Int
d) Int
startPrec [(Name, Bool)]
bnd PTerm
t, ((Name
n, Bool
False) (Name, Bool) -> [(Name, Bool)] -> [(Name, Bool)]
forall a. a -> [a] -> [a]
:))
              (PTerm, PunInfo)
_ ->                    (Maybe Int -> Int -> [(Name, Bool)] -> PTerm -> Doc OutputAnnotation
prettySe (Maybe Int -> Maybe Int
decD Maybe Int
d) Int
startPrec [(Name, Bool)]
bnd PTerm
l, [(Name, Bool)] -> [(Name, Bool)]
forall a. a -> a
id)

            ppElts :: [(PTerm, PTerm)] -> [(Name, Bool)] -> [Doc OutputAnnotation]
ppElts [] [(Name, Bool)]
bs = []
            ppElts [(PTerm
_, PTerm
v)] [(Name, Bool)]
bs = [Maybe Int -> Int -> [(Name, Bool)] -> PTerm -> Doc OutputAnnotation
prettySe (Maybe Int -> Maybe Int
decD Maybe Int
d) Int
startPrec [(Name, Bool)]
bs PTerm
v]
            ppElts ((PRef FC
_ [FC]
_ Name
n, PTerm
t):[(PTerm, PTerm)]
rs) [(Name, Bool)]
bs
              | PunInfo
IsType <- PunInfo
pun
              =  (Name -> Bool -> Doc OutputAnnotation
bindingOf Name
n Bool
False Doc OutputAnnotation
-> Doc OutputAnnotation -> Doc OutputAnnotation
forall a. Doc a -> Doc a -> Doc a
<+> Doc OutputAnnotation
forall a. Doc a
colon Doc OutputAnnotation
-> Doc OutputAnnotation -> Doc OutputAnnotation
forall a. Doc a -> Doc a -> Doc a
<+>
                  Maybe Int -> Int -> [(Name, Bool)] -> PTerm -> Doc OutputAnnotation
prettySe (Maybe Int -> Maybe Int
decD Maybe Int
d) Int
startPrec [(Name, Bool)]
bs PTerm
t) Doc OutputAnnotation
-> [Doc OutputAnnotation] -> [Doc OutputAnnotation]
forall a. a -> [a] -> [a]
: [(PTerm, PTerm)] -> [(Name, Bool)] -> [Doc OutputAnnotation]
ppElts [(PTerm, PTerm)]
rs ((Name
n, Bool
False)(Name, Bool) -> [(Name, Bool)] -> [(Name, Bool)]
forall a. a -> [a] -> [a]
:[(Name, Bool)]
bs)
            ppElts ((PTerm
l, PTerm
t):[(PTerm, PTerm)]
rs) [(Name, Bool)]
bs
              = (Maybe Int -> Int -> [(Name, Bool)] -> PTerm -> Doc OutputAnnotation
prettySe (Maybe Int -> Maybe Int
decD Maybe Int
d) Int
startPrec [(Name, Bool)]
bs PTerm
l) Doc OutputAnnotation
-> [Doc OutputAnnotation] -> [Doc OutputAnnotation]
forall a. a -> [a] -> [a]
: [(PTerm, PTerm)] -> [(Name, Bool)] -> [Doc OutputAnnotation]
ppElts [(PTerm, PTerm)]
rs [(Name, Bool)]
bs
    prettySe Maybe Int
d Int
p [(Name, Bool)]
bnd (PAlternative [(Name, Name)]
ns PAltType
a [PTerm]
as) =
      Doc OutputAnnotation
forall a. Doc a
lparen Doc OutputAnnotation
-> Doc OutputAnnotation -> Doc OutputAnnotation
forall a. Doc a -> Doc a -> Doc a
<> String -> Doc OutputAnnotation
forall a. String -> Doc a
text String
"|" Doc OutputAnnotation
-> Doc OutputAnnotation -> Doc OutputAnnotation
forall a. Doc a -> Doc a -> Doc a
<> Doc OutputAnnotation
prettyAs Doc OutputAnnotation
-> Doc OutputAnnotation -> Doc OutputAnnotation
forall a. Doc a -> Doc a -> Doc a
<> String -> Doc OutputAnnotation
forall a. String -> Doc a
text String
"|" Doc OutputAnnotation
-> Doc OutputAnnotation -> Doc OutputAnnotation
forall a. Doc a -> Doc a -> Doc a
<> Doc OutputAnnotation
forall a. Doc a
rparen
        where
          prettyAs :: Doc OutputAnnotation
prettyAs =
            (PTerm -> Doc OutputAnnotation -> Doc OutputAnnotation)
-> Doc OutputAnnotation -> [PTerm] -> Doc OutputAnnotation
forall a b. (a -> b -> b) -> b -> [a] -> b
forall (t :: * -> *) a b.
Foldable t =>
(a -> b -> b) -> b -> t a -> b
foldr ((\ Doc OutputAnnotation
l Doc OutputAnnotation
r -> Doc OutputAnnotation
l Doc OutputAnnotation
-> Doc OutputAnnotation -> Doc OutputAnnotation
forall a. Doc a -> Doc a -> Doc a
<+> String -> Doc OutputAnnotation
forall a. String -> Doc a
text String
"," Doc OutputAnnotation
-> Doc OutputAnnotation -> Doc OutputAnnotation
forall a. Doc a -> Doc a -> Doc a
<+> Doc OutputAnnotation
r) (Doc OutputAnnotation
 -> Doc OutputAnnotation -> Doc OutputAnnotation)
-> (PTerm -> Doc OutputAnnotation)
-> PTerm
-> Doc OutputAnnotation
-> Doc OutputAnnotation
forall b c a. (b -> c) -> (a -> b) -> a -> c
.
                    Maybe Int -> Doc OutputAnnotation -> Doc OutputAnnotation
forall {a} {a}. (Ord a, Num a) => Maybe a -> Doc a -> Doc a
depth Maybe Int
d (Doc OutputAnnotation -> Doc OutputAnnotation)
-> (PTerm -> Doc OutputAnnotation) -> PTerm -> Doc OutputAnnotation
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Maybe Int -> Int -> [(Name, Bool)] -> PTerm -> Doc OutputAnnotation
prettySe (Maybe Int -> Maybe Int
decD Maybe Int
d) Int
startPrec [(Name, Bool)]
bnd)
                  Doc OutputAnnotation
forall a. Doc a
empty [PTerm]
as
    prettySe Maybe Int
d Int
p [(Name, Bool)]
bnd (PType FC
_)        = OutputAnnotation -> Doc OutputAnnotation -> Doc OutputAnnotation
forall a. a -> Doc a -> Doc a
annotate (String -> String -> OutputAnnotation
AnnType String
"Type" String
"The type of types") (Doc OutputAnnotation -> Doc OutputAnnotation)
-> Doc OutputAnnotation -> Doc OutputAnnotation
forall a b. (a -> b) -> a -> b
$ String -> Doc OutputAnnotation
forall a. String -> Doc a
text String
"Type"
    prettySe Maybe Int
d Int
p [(Name, Bool)]
bnd (PUniverse FC
_ Universe
u)  = OutputAnnotation -> Doc OutputAnnotation -> Doc OutputAnnotation
forall a. a -> Doc a -> Doc a
annotate (String -> String -> OutputAnnotation
AnnType (Universe -> String
forall a. Show a => a -> String
show Universe
u) String
"The type of unique types") (Doc OutputAnnotation -> Doc OutputAnnotation)
-> Doc OutputAnnotation -> Doc OutputAnnotation
forall a b. (a -> b) -> a -> b
$ String -> Doc OutputAnnotation
forall a. String -> Doc a
text (Universe -> String
forall a. Show a => a -> String
show Universe
u)
    prettySe Maybe Int
d Int
p [(Name, Bool)]
bnd (PConstant FC
_ Const
c)  = OutputAnnotation -> Doc OutputAnnotation -> Doc OutputAnnotation
forall a. a -> Doc a -> Doc a
annotate (Const -> OutputAnnotation
AnnConst Const
c) (String -> Doc OutputAnnotation
forall a. String -> Doc a
text (Const -> String
forall a. Show a => a -> String
show Const
c))
    -- XXX: add pretty for tactics
    prettySe Maybe Int
d Int
p [(Name, Bool)]
bnd (PProof [PTactic]
ts)      =
      String -> Doc OutputAnnotation
kwd String
"proof" Doc OutputAnnotation
-> Doc OutputAnnotation -> Doc OutputAnnotation
forall a. Doc a -> Doc a -> Doc a
<+> Doc OutputAnnotation
lbrace Doc OutputAnnotation
-> Doc OutputAnnotation -> Doc OutputAnnotation
forall a. Doc a -> Doc a -> Doc a
<> Doc OutputAnnotation
forall a. Doc a
ellipsis Doc OutputAnnotation
-> Doc OutputAnnotation -> Doc OutputAnnotation
forall a. Doc a -> Doc a -> Doc a
<> Doc OutputAnnotation
rbrace
    prettySe Maybe Int
d Int
p [(Name, Bool)]
bnd (PTactics [PTactic]
ts)    =
      String -> Doc OutputAnnotation
kwd String
"tactics" Doc OutputAnnotation
-> Doc OutputAnnotation -> Doc OutputAnnotation
forall a. Doc a -> Doc a -> Doc a
<+> Doc OutputAnnotation
lbrace Doc OutputAnnotation
-> Doc OutputAnnotation -> Doc OutputAnnotation
forall a. Doc a -> Doc a -> Doc a
<> Doc OutputAnnotation
forall a. Doc a
ellipsis Doc OutputAnnotation
-> Doc OutputAnnotation -> Doc OutputAnnotation
forall a. Doc a -> Doc a -> Doc a
<> Doc OutputAnnotation
rbrace
    prettySe Maybe Int
d Int
p [(Name, Bool)]
bnd (PMetavar FC
_ Name
n)   = OutputAnnotation -> Doc OutputAnnotation -> Doc OutputAnnotation
forall a. a -> Doc a -> Doc a
annotate (Name
-> Maybe NameOutput
-> Maybe String
-> Maybe String
-> OutputAnnotation
AnnName Name
n (NameOutput -> Maybe NameOutput
forall a. a -> Maybe a
Just NameOutput
MetavarOutput) Maybe String
forall a. Maybe a
Nothing Maybe String
forall a. Maybe a
Nothing) (Doc OutputAnnotation -> Doc OutputAnnotation)
-> Doc OutputAnnotation -> Doc OutputAnnotation
forall a b. (a -> b) -> a -> b
$  String -> Doc OutputAnnotation
forall a. String -> Doc a
text String
"?" Doc OutputAnnotation
-> Doc OutputAnnotation -> Doc OutputAnnotation
forall a. Doc a -> Doc a -> Doc a
<> Name -> Doc OutputAnnotation
forall a ty. Pretty a ty => a -> Doc ty
pretty Name
n
    prettySe Maybe Int
d Int
p [(Name, Bool)]
bnd PTerm
PImpossible      = String -> Doc OutputAnnotation
kwd String
"impossible"
    prettySe Maybe Int
d Int
p [(Name, Bool)]
bnd PTerm
Placeholder      = String -> Doc OutputAnnotation
forall a. String -> Doc a
text String
"_"
    prettySe Maybe Int
d Int
p [(Name, Bool)]
bnd (PDoBlock [PDo]
dos)   =
      Int -> Int -> Doc OutputAnnotation -> Doc OutputAnnotation
forall {a} {a}. Ord a => a -> a -> Doc a -> Doc a
bracket Int
p Int
startPrec (Doc OutputAnnotation -> Doc OutputAnnotation)
-> Doc OutputAnnotation -> Doc OutputAnnotation
forall a b. (a -> b) -> a -> b
$
      String -> Doc OutputAnnotation
kwd String
"do" Doc OutputAnnotation
-> Doc OutputAnnotation -> Doc OutputAnnotation
forall a. Doc a -> Doc a -> Doc a
<+> Doc OutputAnnotation -> Doc OutputAnnotation
forall a. Doc a -> Doc a
align ([Doc OutputAnnotation] -> Doc OutputAnnotation
forall a. [Doc a] -> Doc a
vsep ((Doc OutputAnnotation -> Doc OutputAnnotation)
-> [Doc OutputAnnotation] -> [Doc OutputAnnotation]
forall a b. (a -> b) -> [a] -> [b]
map (Doc OutputAnnotation -> Doc OutputAnnotation
forall a. Doc a -> Doc a
group (Doc OutputAnnotation -> Doc OutputAnnotation)
-> (Doc OutputAnnotation -> Doc OutputAnnotation)
-> Doc OutputAnnotation
-> Doc OutputAnnotation
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Doc OutputAnnotation -> Doc OutputAnnotation
forall a. Doc a -> Doc a
align (Doc OutputAnnotation -> Doc OutputAnnotation)
-> (Doc OutputAnnotation -> Doc OutputAnnotation)
-> Doc OutputAnnotation
-> Doc OutputAnnotation
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int -> Doc OutputAnnotation -> Doc OutputAnnotation
forall a. Int -> Doc a -> Doc a
hang Int
2) ([(Name, Bool)] -> [PDo] -> [Doc OutputAnnotation]
ppdo [(Name, Bool)]
bnd [PDo]
dos)))
       where ppdo :: [(Name, Bool)] -> [PDo] -> [Doc OutputAnnotation]
ppdo [(Name, Bool)]
bnd (DoExp FC
_ PTerm
tm:[PDo]
dos) = Maybe Int -> Int -> [(Name, Bool)] -> PTerm -> Doc OutputAnnotation
prettySe (Maybe Int -> Maybe Int
decD Maybe Int
d) Int
startPrec [(Name, Bool)]
bnd PTerm
tm Doc OutputAnnotation
-> [Doc OutputAnnotation] -> [Doc OutputAnnotation]
forall a. a -> [a] -> [a]
: [(Name, Bool)] -> [PDo] -> [Doc OutputAnnotation]
ppdo [(Name, Bool)]
bnd [PDo]
dos
             ppdo [(Name, Bool)]
bnd (DoBind FC
_ Name
bn FC
_ PTerm
tm : [PDo]
dos) =
               (Name -> Bool -> Doc OutputAnnotation
prettyBindingOf Name
bn Bool
False Doc OutputAnnotation
-> Doc OutputAnnotation -> Doc OutputAnnotation
forall a. Doc a -> Doc a -> Doc a
<+> String -> Doc OutputAnnotation
forall a. String -> Doc a
text String
"<-" Doc OutputAnnotation
-> Doc OutputAnnotation -> Doc OutputAnnotation
forall a. Doc a -> Doc a -> Doc a
<+>
                Doc OutputAnnotation -> Doc OutputAnnotation
forall a. Doc a -> Doc a
group (Doc OutputAnnotation -> Doc OutputAnnotation
forall a. Doc a -> Doc a
align (Int -> Doc OutputAnnotation -> Doc OutputAnnotation
forall a. Int -> Doc a -> Doc a
hang Int
2 (Maybe Int -> Int -> [(Name, Bool)] -> PTerm -> Doc OutputAnnotation
prettySe (Maybe Int -> Maybe Int
decD Maybe Int
d) Int
startPrec [(Name, Bool)]
bnd PTerm
tm)))) Doc OutputAnnotation
-> [Doc OutputAnnotation] -> [Doc OutputAnnotation]
forall a. a -> [a] -> [a]
:
               [(Name, Bool)] -> [PDo] -> [Doc OutputAnnotation]
ppdo ((Name
bn, Bool
False)(Name, Bool) -> [(Name, Bool)] -> [(Name, Bool)]
forall a. a -> [a] -> [a]
:[(Name, Bool)]
bnd) [PDo]
dos
             ppdo [(Name, Bool)]
bnd (DoBindP FC
_ PTerm
_ PTerm
_ [(PTerm, PTerm)]
_ : [PDo]
dos) = -- ok because never made by delab
               String -> Doc OutputAnnotation
forall a. String -> Doc a
text String
"no pretty printer for pattern-matching do binding" Doc OutputAnnotation
-> [Doc OutputAnnotation] -> [Doc OutputAnnotation]
forall a. a -> [a] -> [a]
:
               [(Name, Bool)] -> [PDo] -> [Doc OutputAnnotation]
ppdo [(Name, Bool)]
bnd [PDo]
dos
             ppdo [(Name, Bool)]
bnd (DoLet FC
_ RigCount
_ Name
ln FC
_ PTerm
ty PTerm
v : [PDo]
dos) =
               (String -> Doc OutputAnnotation
kwd String
"let" Doc OutputAnnotation
-> Doc OutputAnnotation -> Doc OutputAnnotation
forall a. Doc a -> Doc a -> Doc a
<+> Name -> Bool -> Doc OutputAnnotation
prettyBindingOf Name
ln Bool
False Doc OutputAnnotation
-> Doc OutputAnnotation -> Doc OutputAnnotation
forall a. Doc a -> Doc a -> Doc a
<+>
                (if PTerm
ty PTerm -> PTerm -> Bool
forall a. Eq a => a -> a -> Bool
/= PTerm
Placeholder
                   then Doc OutputAnnotation
forall a. Doc a
colon Doc OutputAnnotation
-> Doc OutputAnnotation -> Doc OutputAnnotation
forall a. Doc a -> Doc a -> Doc a
<+> Maybe Int -> Int -> [(Name, Bool)] -> PTerm -> Doc OutputAnnotation
prettySe (Maybe Int -> Maybe Int
decD Maybe Int
d) Int
startPrec [(Name, Bool)]
bnd PTerm
ty Doc OutputAnnotation
-> Doc OutputAnnotation -> Doc OutputAnnotation
forall a. Doc a -> Doc a -> Doc a
<+> String -> Doc OutputAnnotation
forall a. String -> Doc a
text String
"="
                   else String -> Doc OutputAnnotation
forall a. String -> Doc a
text String
"=") Doc OutputAnnotation
-> Doc OutputAnnotation -> Doc OutputAnnotation
forall a. Doc a -> Doc a -> Doc a
<+>
                Doc OutputAnnotation -> Doc OutputAnnotation
forall a. Doc a -> Doc a
group (Doc OutputAnnotation -> Doc OutputAnnotation
forall a. Doc a -> Doc a
align (Int -> Doc OutputAnnotation -> Doc OutputAnnotation
forall a. Int -> Doc a -> Doc a
hang Int
2 (Maybe Int -> Int -> [(Name, Bool)] -> PTerm -> Doc OutputAnnotation
prettySe (Maybe Int -> Maybe Int
decD Maybe Int
d) Int
startPrec [(Name, Bool)]
bnd PTerm
v)))) Doc OutputAnnotation
-> [Doc OutputAnnotation] -> [Doc OutputAnnotation]
forall a. a -> [a] -> [a]
:
               [(Name, Bool)] -> [PDo] -> [Doc OutputAnnotation]
ppdo ((Name
ln, Bool
False)(Name, Bool) -> [(Name, Bool)] -> [(Name, Bool)]
forall a. a -> [a] -> [a]
:[(Name, Bool)]
bnd) [PDo]
dos
             ppdo [(Name, Bool)]
bnd (DoLetP FC
_ PTerm
_ PTerm
_ [(PTerm, PTerm)]
_ : [PDo]
dos) = -- ok because never made by delab
               String -> Doc OutputAnnotation
forall a. String -> Doc a
text String
"no pretty printer for pattern-matching do binding" Doc OutputAnnotation
-> [Doc OutputAnnotation] -> [Doc OutputAnnotation]
forall a. a -> [a] -> [a]
:
               [(Name, Bool)] -> [PDo] -> [Doc OutputAnnotation]
ppdo [(Name, Bool)]
bnd [PDo]
dos
             ppdo [(Name, Bool)]
bnd (DoRewrite FC
_ PTerm
_ : [PDo]
dos) = -- ok because never made by delab
               String -> Doc OutputAnnotation
forall a. String -> Doc a
text String
"no pretty printer for pattern-matching do binding" Doc OutputAnnotation
-> [Doc OutputAnnotation] -> [Doc OutputAnnotation]
forall a. a -> [a] -> [a]
:
               [(Name, Bool)] -> [PDo] -> [Doc OutputAnnotation]
ppdo [(Name, Bool)]
bnd [PDo]
dos
             ppdo [(Name, Bool)]
_ [] = []
    prettySe Maybe Int
d Int
p [(Name, Bool)]
bnd (PCoerced PTerm
t)             = Maybe Int -> Int -> [(Name, Bool)] -> PTerm -> Doc OutputAnnotation
prettySe Maybe Int
d Int
p [(Name, Bool)]
bnd PTerm
t
    prettySe Maybe Int
d Int
p [(Name, Bool)]
bnd (PElabError Err
s)           = Err -> Doc OutputAnnotation
forall a ty. Pretty a ty => a -> Doc ty
pretty Err
s
    -- Quasiquote pprinting ignores bound vars
    prettySe Maybe Int
d Int
p [(Name, Bool)]
bnd (PQuasiquote PTerm
t Maybe PTerm
Nothing)  = String -> Doc OutputAnnotation
forall a. String -> Doc a
text String
"`(" Doc OutputAnnotation
-> Doc OutputAnnotation -> Doc OutputAnnotation
forall a. Doc a -> Doc a -> Doc a
<> Maybe Int -> Int -> [(Name, Bool)] -> PTerm -> Doc OutputAnnotation
prettySe (Maybe Int -> Maybe Int
decD Maybe Int
d) Int
p [] PTerm
t Doc OutputAnnotation
-> Doc OutputAnnotation -> Doc OutputAnnotation
forall a. Doc a -> Doc a -> Doc a
<> String -> Doc OutputAnnotation
forall a. String -> Doc a
text String
")"
    prettySe Maybe Int
d Int
p [(Name, Bool)]
bnd (PQuasiquote PTerm
t (Just PTerm
g)) = String -> Doc OutputAnnotation
forall a. String -> Doc a
text String
"`(" Doc OutputAnnotation
-> Doc OutputAnnotation -> Doc OutputAnnotation
forall a. Doc a -> Doc a -> Doc a
<> Maybe Int -> Int -> [(Name, Bool)] -> PTerm -> Doc OutputAnnotation
prettySe (Maybe Int -> Maybe Int
decD Maybe Int
d) Int
p [] PTerm
t Doc OutputAnnotation
-> Doc OutputAnnotation -> Doc OutputAnnotation
forall a. Doc a -> Doc a -> Doc a
<+> Doc OutputAnnotation
forall a. Doc a
colon Doc OutputAnnotation
-> Doc OutputAnnotation -> Doc OutputAnnotation
forall a. Doc a -> Doc a -> Doc a
<+> Maybe Int -> Int -> [(Name, Bool)] -> PTerm -> Doc OutputAnnotation
prettySe (Maybe Int -> Maybe Int
decD Maybe Int
d) Int
p [] PTerm
g Doc OutputAnnotation
-> Doc OutputAnnotation -> Doc OutputAnnotation
forall a. Doc a -> Doc a -> Doc a
<> String -> Doc OutputAnnotation
forall a. String -> Doc a
text String
")"
    prettySe Maybe Int
d Int
p [(Name, Bool)]
bnd (PUnquote PTerm
t)             = String -> Doc OutputAnnotation
forall a. String -> Doc a
text String
"~" Doc OutputAnnotation
-> Doc OutputAnnotation -> Doc OutputAnnotation
forall a. Doc a -> Doc a -> Doc a
<> Maybe Int -> Int -> [(Name, Bool)] -> PTerm -> Doc OutputAnnotation
prettySe (Maybe Int -> Maybe Int
decD Maybe Int
d) Int
p [(Name, Bool)]
bnd PTerm
t
    prettySe Maybe Int
d Int
p [(Name, Bool)]
bnd (PQuoteName Name
n Bool
res FC
_)     = String -> Doc OutputAnnotation
forall a. String -> Doc a
text String
start Doc OutputAnnotation
-> Doc OutputAnnotation -> Doc OutputAnnotation
forall a. Doc a -> Doc a -> Doc a
<> Bool -> Bool -> [(Name, Bool)] -> Name -> Doc OutputAnnotation
prettyName Bool
True (PPOption -> Bool
ppopt_impl PPOption
ppo) [(Name, Bool)]
bnd Name
n Doc OutputAnnotation
-> Doc OutputAnnotation -> Doc OutputAnnotation
forall a. Doc a -> Doc a -> Doc a
<> String -> Doc OutputAnnotation
forall a. String -> Doc a
text String
end
      where start :: String
start = if Bool
res then String
"`{" else String
"`{{"
            end :: String
end = if Bool
res then String
"}" else String
"}}"
    prettySe Maybe Int
d Int
p [(Name, Bool)]
bnd (PRunElab FC
_ PTerm
tm [String]
_)        =
      Int -> Int -> Doc OutputAnnotation -> Doc OutputAnnotation
forall {a} {a}. Ord a => a -> a -> Doc a -> Doc a
bracket Int
p Int
funcAppPrec (Doc OutputAnnotation -> Doc OutputAnnotation)
-> (Doc OutputAnnotation -> Doc OutputAnnotation)
-> Doc OutputAnnotation
-> Doc OutputAnnotation
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Doc OutputAnnotation -> Doc OutputAnnotation
forall a. Doc a -> Doc a
group (Doc OutputAnnotation -> Doc OutputAnnotation)
-> (Doc OutputAnnotation -> Doc OutputAnnotation)
-> Doc OutputAnnotation
-> Doc OutputAnnotation
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Doc OutputAnnotation -> Doc OutputAnnotation
forall a. Doc a -> Doc a
align (Doc OutputAnnotation -> Doc OutputAnnotation)
-> (Doc OutputAnnotation -> Doc OutputAnnotation)
-> Doc OutputAnnotation
-> Doc OutputAnnotation
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int -> Doc OutputAnnotation -> Doc OutputAnnotation
forall a. Int -> Doc a -> Doc a
hang Int
2 (Doc OutputAnnotation -> Doc OutputAnnotation)
-> Doc OutputAnnotation -> Doc OutputAnnotation
forall a b. (a -> b) -> a -> b
$
      (Doc OutputAnnotation
percent Doc OutputAnnotation
-> Doc OutputAnnotation -> Doc OutputAnnotation
forall a. Doc a -> Doc a -> Doc a
<> String -> Doc OutputAnnotation
forall a. String -> Doc a
text String
"runElab") Doc OutputAnnotation
-> Doc OutputAnnotation -> Doc OutputAnnotation
forall a. Doc a -> Doc a -> Doc a
<$>
      Maybe Int -> Int -> [(Name, Bool)] -> PTerm -> Doc OutputAnnotation
prettySe (Maybe Int -> Maybe Int
decD Maybe Int
d) Int
funcAppPrec [(Name, Bool)]
bnd PTerm
tm
    prettySe Maybe Int
d Int
p [(Name, Bool)]
bnd (PConstSugar FC
fc PTerm
tm)      = Maybe Int -> Int -> [(Name, Bool)] -> PTerm -> Doc OutputAnnotation
prettySe Maybe Int
d Int
p [(Name, Bool)]
bnd PTerm
tm -- should never occur, but harmless
    prettySe Maybe Int
d Int
p [(Name, Bool)]
bnd PTerm
_                        = String -> Doc OutputAnnotation
forall a. String -> Doc a
text String
"missing pretty-printer for term"

    prettyBindingOf :: Name -> Bool -> Doc OutputAnnotation
    prettyBindingOf :: Name -> Bool -> Doc OutputAnnotation
prettyBindingOf Name
n Bool
imp = OutputAnnotation -> Doc OutputAnnotation -> Doc OutputAnnotation
forall a. a -> Doc a -> Doc a
annotate (Name -> Bool -> OutputAnnotation
AnnBoundName Name
n Bool
imp) (String -> Doc OutputAnnotation
forall a. String -> Doc a
text (Name -> String
display Name
n))
      where display :: Name -> String
display (UN Text
n)    = Text -> String
T.unpack Text
n
            display (MN Int
_ Text
n)  = Text -> String
T.unpack Text
n
            -- If a namespace is specified on a binding form, we'd better show it regardless of the implicits settings
            display (NS Name
n [Text]
ns) = (String -> [String] -> String
forall a. [a] -> [[a]] -> [a]
intercalate String
"." ([String] -> String) -> ([Text] -> [String]) -> [Text] -> String
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Text -> String) -> [Text] -> [String]
forall a b. (a -> b) -> [a] -> [b]
map Text -> String
T.unpack ([Text] -> [String]) -> ([Text] -> [Text]) -> [Text] -> [String]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [Text] -> [Text]
forall a. [a] -> [a]
reverse) [Text]
ns String -> ShowS
forall a. [a] -> [a] -> [a]
++ String
"." String -> ShowS
forall a. [a] -> [a] -> [a]
++ Name -> String
display Name
n
            display Name
n         = Name -> String
forall a. Show a => a -> String
show Name
n

    prettyArgS :: Maybe Int -> [(Name, Bool)] -> PArg -> Doc OutputAnnotation
prettyArgS Maybe Int
d [(Name, Bool)]
bnd (PImp Int
_ Bool
_ [ArgOpt]
_ Name
n PTerm
tm)          = Maybe Int
-> [(Name, Bool)] -> (Name, PTerm) -> Doc OutputAnnotation
forall {a}.
Pretty a OutputAnnotation =>
Maybe Int -> [(Name, Bool)] -> (a, PTerm) -> Doc OutputAnnotation
prettyArgSi Maybe Int
d [(Name, Bool)]
bnd (Name
n, PTerm
tm)
    prettyArgS Maybe Int
d [(Name, Bool)]
bnd (PExp Int
_ [ArgOpt]
_ Name
_ PTerm
tm)            = Maybe Int -> [(Name, Bool)] -> PTerm -> Doc OutputAnnotation
prettyArgSe Maybe Int
d [(Name, Bool)]
bnd PTerm
tm
    prettyArgS Maybe Int
d [(Name, Bool)]
bnd (PConstraint Int
_ [ArgOpt]
_ Name
_ PTerm
tm)     = Maybe Int -> [(Name, Bool)] -> PTerm -> Doc OutputAnnotation
prettyArgSc Maybe Int
d [(Name, Bool)]
bnd PTerm
tm
    prettyArgS Maybe Int
d [(Name, Bool)]
bnd (PTacImplicit Int
_ [ArgOpt]
_ Name
n PTerm
_ PTerm
tm)  = Maybe Int
-> [(Name, Bool)] -> (Name, PTerm) -> Doc OutputAnnotation
forall {a}.
Pretty a OutputAnnotation =>
Maybe Int -> [(Name, Bool)] -> (a, PTerm) -> Doc OutputAnnotation
prettyArgSti Maybe Int
d [(Name, Bool)]
bnd (Name
n, PTerm
tm)

    prettyArgSe :: Maybe Int -> [(Name, Bool)] -> PTerm -> Doc OutputAnnotation
prettyArgSe Maybe Int
d [(Name, Bool)]
bnd PTerm
arg       = Maybe Int -> Int -> [(Name, Bool)] -> PTerm -> Doc OutputAnnotation
prettySe (Maybe Int -> Maybe Int
decD Maybe Int
d) (Int
funcAppPrec Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
1) [(Name, Bool)]
bnd PTerm
arg
    prettyArgSi :: Maybe Int -> [(Name, Bool)] -> (a, PTerm) -> Doc OutputAnnotation
prettyArgSi Maybe Int
d [(Name, Bool)]
bnd (a
n, PTerm
val)  = Doc OutputAnnotation
lbrace Doc OutputAnnotation
-> Doc OutputAnnotation -> Doc OutputAnnotation
forall a. Doc a -> Doc a -> Doc a
<> a -> Doc OutputAnnotation
forall a ty. Pretty a ty => a -> Doc ty
pretty a
n Doc OutputAnnotation
-> Doc OutputAnnotation -> Doc OutputAnnotation
forall a. Doc a -> Doc a -> Doc a
<+> String -> Doc OutputAnnotation
forall a. String -> Doc a
text String
"=" Doc OutputAnnotation
-> Doc OutputAnnotation -> Doc OutputAnnotation
forall a. Doc a -> Doc a -> Doc a
<+> Maybe Int -> Int -> [(Name, Bool)] -> PTerm -> Doc OutputAnnotation
prettySe (Maybe Int -> Maybe Int
decD Maybe Int
d) Int
startPrec [(Name, Bool)]
bnd PTerm
val Doc OutputAnnotation
-> Doc OutputAnnotation -> Doc OutputAnnotation
forall a. Doc a -> Doc a -> Doc a
<> Doc OutputAnnotation
rbrace
    prettyArgSc :: Maybe Int -> [(Name, Bool)] -> PTerm -> Doc OutputAnnotation
prettyArgSc Maybe Int
d [(Name, Bool)]
bnd PTerm
val       = Doc OutputAnnotation
lbrace Doc OutputAnnotation
-> Doc OutputAnnotation -> Doc OutputAnnotation
forall a. Doc a -> Doc a -> Doc a
<> Doc OutputAnnotation
lbrace Doc OutputAnnotation
-> Doc OutputAnnotation -> Doc OutputAnnotation
forall a. Doc a -> Doc a -> Doc a
<> Maybe Int -> Int -> [(Name, Bool)] -> PTerm -> Doc OutputAnnotation
prettySe (Maybe Int -> Maybe Int
decD Maybe Int
d) Int
startPrec [(Name, Bool)]
bnd PTerm
val Doc OutputAnnotation
-> Doc OutputAnnotation -> Doc OutputAnnotation
forall a. Doc a -> Doc a -> Doc a
<> Doc OutputAnnotation
rbrace Doc OutputAnnotation
-> Doc OutputAnnotation -> Doc OutputAnnotation
forall a. Doc a -> Doc a -> Doc a
<> Doc OutputAnnotation
rbrace
    prettyArgSti :: Maybe Int -> [(Name, Bool)] -> (a, PTerm) -> Doc OutputAnnotation
prettyArgSti Maybe Int
d [(Name, Bool)]
bnd (a
n, PTerm
val) = Doc OutputAnnotation
lbrace Doc OutputAnnotation
-> Doc OutputAnnotation -> Doc OutputAnnotation
forall a. Doc a -> Doc a -> Doc a
<> String -> Doc OutputAnnotation
kwd String
"auto" Doc OutputAnnotation
-> Doc OutputAnnotation -> Doc OutputAnnotation
forall a. Doc a -> Doc a -> Doc a
<+> a -> Doc OutputAnnotation
forall a ty. Pretty a ty => a -> Doc ty
pretty a
n Doc OutputAnnotation
-> Doc OutputAnnotation -> Doc OutputAnnotation
forall a. Doc a -> Doc a -> Doc a
<+> String -> Doc OutputAnnotation
forall a. String -> Doc a
text String
"=" Doc OutputAnnotation
-> Doc OutputAnnotation -> Doc OutputAnnotation
forall a. Doc a -> Doc a -> Doc a
<+> Maybe Int -> Int -> [(Name, Bool)] -> PTerm -> Doc OutputAnnotation
prettySe (Maybe Int -> Maybe Int
decD Maybe Int
d) Int
startPrec [(Name, Bool)]
bnd PTerm
val Doc OutputAnnotation
-> Doc OutputAnnotation -> Doc OutputAnnotation
forall a. Doc a -> Doc a -> Doc a
<> Doc OutputAnnotation
rbrace

    annName :: Name -> Doc OutputAnnotation -> Doc OutputAnnotation
    annName :: Name -> Doc OutputAnnotation -> Doc OutputAnnotation
annName Name
n = OutputAnnotation -> Doc OutputAnnotation -> Doc OutputAnnotation
forall a. a -> Doc a -> Doc a
annotate (Name
-> Maybe NameOutput
-> Maybe String
-> Maybe String
-> OutputAnnotation
AnnName Name
n Maybe NameOutput
forall a. Maybe a
Nothing Maybe String
forall a. Maybe a
Nothing Maybe String
forall a. Maybe a
Nothing)

    opStr :: Name -> String
    opStr :: Name -> String
opStr (NS Name
n [Text]
_)  = Name -> String
opStr Name
n
    opStr (UN Text
n)    = Text -> String
T.unpack Text
n

    slist' :: Maybe Int -> Int -> [(Name, Bool)] -> PTerm -> Maybe [Doc OutputAnnotation]
    slist' :: Maybe Int
-> Int -> [(Name, Bool)] -> PTerm -> Maybe [Doc OutputAnnotation]
slist' (Just Int
d) Int
_ [(Name, Bool)]
_ PTerm
_ | Int
d Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
<= Int
0 = Maybe [Doc OutputAnnotation]
forall a. Maybe a
Nothing
    slist' Maybe Int
d Int
_ [(Name, Bool)]
_ PTerm
e
      | PTerm -> Bool
containsHole PTerm
e = Maybe [Doc OutputAnnotation]
forall a. Maybe a
Nothing
    slist' Maybe Int
d Int
p [(Name, Bool)]
bnd (PApp FC
_ (PRef FC
_ [FC]
_ Name
nil) [PArg]
_)
      | Bool -> Bool
not (PPOption -> Bool
ppopt_impl PPOption
ppo) Bool -> Bool -> Bool
&& Name -> Name
nsroot Name
nil Name -> Name -> Bool
forall a. Eq a => a -> a -> Bool
== String -> Name
sUN String
"Nil" = [Doc OutputAnnotation] -> Maybe [Doc OutputAnnotation]
forall a. a -> Maybe a
Just []
    slist' Maybe Int
d Int
p [(Name, Bool)]
bnd (PRef FC
_ [FC]
_ Name
nil)
      | Bool -> Bool
not (PPOption -> Bool
ppopt_impl PPOption
ppo) Bool -> Bool -> Bool
&& Name -> Name
nsroot Name
nil Name -> Name -> Bool
forall a. Eq a => a -> a -> Bool
== String -> Name
sUN String
"Nil" = [Doc OutputAnnotation] -> Maybe [Doc OutputAnnotation]
forall a. a -> Maybe a
Just []
    slist' Maybe Int
d Int
p [(Name, Bool)]
bnd (PApp FC
_ (PRef FC
_ [FC]
_ Name
cons) [PArg]
args)
      | Name -> Name
nsroot Name
cons Name -> Name -> Bool
forall a. Eq a => a -> a -> Bool
== String -> Name
sUN String
"::",
        (PExp {getTm :: forall t. PArg' t -> t
getTm=PTerm
tl}):(PExp {getTm :: forall t. PArg' t -> t
getTm=PTerm
hd}):[PArg]
imps <- [PArg] -> [PArg]
forall a. [a] -> [a]
reverse [PArg]
args,
        (PArg -> Bool) -> [PArg] -> Bool
forall (t :: * -> *) a. Foldable t => (a -> Bool) -> t a -> Bool
all PArg -> Bool
forall t. PArg' t -> Bool
isImp [PArg]
imps,
        Just [Doc OutputAnnotation]
tl' <- Maybe Int
-> Int -> [(Name, Bool)] -> PTerm -> Maybe [Doc OutputAnnotation]
slist' (Maybe Int -> Maybe Int
decD Maybe Int
d) Int
p [(Name, Bool)]
bnd PTerm
tl
      = [Doc OutputAnnotation] -> Maybe [Doc OutputAnnotation]
forall a. a -> Maybe a
Just (Maybe Int -> Int -> [(Name, Bool)] -> PTerm -> Doc OutputAnnotation
prettySe Maybe Int
d Int
startPrec [(Name, Bool)]
bnd PTerm
hd Doc OutputAnnotation
-> [Doc OutputAnnotation] -> [Doc OutputAnnotation]
forall a. a -> [a] -> [a]
: [Doc OutputAnnotation]
tl')
      where
        isImp :: PArg' t -> Bool
isImp (PImp {}) = Bool
True
        isImp PArg' t
_ = Bool
False
    slist' Maybe Int
_ Int
_ [(Name, Bool)]
_ PTerm
tm = Maybe [Doc OutputAnnotation]
forall a. Maybe a
Nothing

    slist :: Maybe Int
-> Int -> [(Name, Bool)] -> PTerm -> Maybe (Doc OutputAnnotation)
slist Maybe Int
d Int
p [(Name, Bool)]
bnd PTerm
e | Just [Doc OutputAnnotation]
es <- Maybe Int
-> Int -> [(Name, Bool)] -> PTerm -> Maybe [Doc OutputAnnotation]
slist' Maybe Int
d Int
p [(Name, Bool)]
bnd PTerm
e = Doc OutputAnnotation -> Maybe (Doc OutputAnnotation)
forall a. a -> Maybe a
Just (Doc OutputAnnotation -> Maybe (Doc OutputAnnotation))
-> Doc OutputAnnotation -> Maybe (Doc OutputAnnotation)
forall a b. (a -> b) -> a -> b
$
      case [Doc OutputAnnotation]
es of
        [] -> OutputAnnotation -> Doc OutputAnnotation -> Doc OutputAnnotation
forall a. a -> Doc a -> Doc a
annotate (String -> String -> OutputAnnotation
AnnData String
"" String
"") (Doc OutputAnnotation -> Doc OutputAnnotation)
-> Doc OutputAnnotation -> Doc OutputAnnotation
forall a b. (a -> b) -> a -> b
$ String -> Doc OutputAnnotation
forall a. String -> Doc a
text String
"[]"
        [Doc OutputAnnotation
x] -> Doc OutputAnnotation
-> Doc OutputAnnotation
-> Doc OutputAnnotation
-> Doc OutputAnnotation
forall a. Doc a -> Doc a -> Doc a -> Doc a
enclose Doc OutputAnnotation
left Doc OutputAnnotation
right (Doc OutputAnnotation -> Doc OutputAnnotation)
-> (Doc OutputAnnotation -> Doc OutputAnnotation)
-> Doc OutputAnnotation
-> Doc OutputAnnotation
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Doc OutputAnnotation -> Doc OutputAnnotation
forall a. Doc a -> Doc a
group (Doc OutputAnnotation -> Doc OutputAnnotation)
-> Doc OutputAnnotation -> Doc OutputAnnotation
forall a b. (a -> b) -> a -> b
$ Doc OutputAnnotation
x
        [Doc OutputAnnotation]
xs -> Doc OutputAnnotation
-> Doc OutputAnnotation
-> Doc OutputAnnotation
-> Doc OutputAnnotation
forall a. Doc a -> Doc a -> Doc a -> Doc a
enclose Doc OutputAnnotation
left Doc OutputAnnotation
right (Doc OutputAnnotation -> Doc OutputAnnotation)
-> ([Doc OutputAnnotation] -> Doc OutputAnnotation)
-> [Doc OutputAnnotation]
-> Doc OutputAnnotation
forall b c a. (b -> c) -> (a -> b) -> a -> c
.
              Doc OutputAnnotation -> Doc OutputAnnotation
forall a. Doc a -> Doc a
align (Doc OutputAnnotation -> Doc OutputAnnotation)
-> ([Doc OutputAnnotation] -> Doc OutputAnnotation)
-> [Doc OutputAnnotation]
-> Doc OutputAnnotation
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Doc OutputAnnotation -> Doc OutputAnnotation
forall a. Doc a -> Doc a
group (Doc OutputAnnotation -> Doc OutputAnnotation)
-> ([Doc OutputAnnotation] -> Doc OutputAnnotation)
-> [Doc OutputAnnotation]
-> Doc OutputAnnotation
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [Doc OutputAnnotation] -> Doc OutputAnnotation
forall a. [Doc a] -> Doc a
vsep ([Doc OutputAnnotation] -> Doc OutputAnnotation)
-> ([Doc OutputAnnotation] -> [Doc OutputAnnotation])
-> [Doc OutputAnnotation]
-> Doc OutputAnnotation
forall b c a. (b -> c) -> (a -> b) -> a -> c
.
              Doc OutputAnnotation
-> [Doc OutputAnnotation] -> [Doc OutputAnnotation]
forall a. Doc a -> [Doc a] -> [Doc a]
punctuate Doc OutputAnnotation
comma ([Doc OutputAnnotation] -> Doc OutputAnnotation)
-> [Doc OutputAnnotation] -> Doc OutputAnnotation
forall a b. (a -> b) -> a -> b
$ [Doc OutputAnnotation]
xs
      where left :: Doc OutputAnnotation
left  = (OutputAnnotation -> Doc OutputAnnotation -> Doc OutputAnnotation
forall a. a -> Doc a -> Doc a
annotate (String -> String -> OutputAnnotation
AnnData String
"" String
"") (String -> Doc OutputAnnotation
forall a. String -> Doc a
text String
"["))
            right :: Doc OutputAnnotation
right = (OutputAnnotation -> Doc OutputAnnotation -> Doc OutputAnnotation
forall a. a -> Doc a -> Doc a
annotate (String -> String -> OutputAnnotation
AnnData String
"" String
"") (String -> Doc OutputAnnotation
forall a. String -> Doc a
text String
"]"))
            comma :: Doc OutputAnnotation
comma = (OutputAnnotation -> Doc OutputAnnotation -> Doc OutputAnnotation
forall a. a -> Doc a -> Doc a
annotate (String -> String -> OutputAnnotation
AnnData String
"" String
"") (String -> Doc OutputAnnotation
forall a. String -> Doc a
text String
","))
    slist Maybe Int
_ Int
_ [(Name, Bool)]
_ PTerm
_ = Maybe (Doc OutputAnnotation)
forall a. Maybe a
Nothing

    pairElts :: PTerm -> Maybe [PTerm]
    pairElts :: PTerm -> Maybe [PTerm]
pairElts (PPair FC
_ [FC]
_ PunInfo
_ PTerm
x PTerm
y) | Just [PTerm]
elts <- PTerm -> Maybe [PTerm]
pairElts PTerm
y = [PTerm] -> Maybe [PTerm]
forall a. a -> Maybe a
Just (PTerm
xPTerm -> [PTerm] -> [PTerm]
forall a. a -> [a] -> [a]
:[PTerm]
elts)
                               | Bool
otherwise = [PTerm] -> Maybe [PTerm]
forall a. a -> Maybe a
Just [PTerm
x, PTerm
y]
    pairElts PTerm
_ = Maybe [PTerm]
forall a. Maybe a
Nothing

    dPairElts :: PTerm -> Maybe [(PTerm, PTerm)]
    dPairElts :: PTerm -> Maybe [(PTerm, PTerm)]
dPairElts (PDPair FC
_ [FC]
_ PunInfo
_ PTerm
l PTerm
t PTerm
r) | Just [(PTerm, PTerm)]
elts <- PTerm -> Maybe [(PTerm, PTerm)]
dPairElts PTerm
r = [(PTerm, PTerm)] -> Maybe [(PTerm, PTerm)]
forall a. a -> Maybe a
Just ((PTerm
l, PTerm
t)(PTerm, PTerm) -> [(PTerm, PTerm)] -> [(PTerm, PTerm)]
forall a. a -> [a] -> [a]
:[(PTerm, PTerm)]
elts)
                                   | Bool
otherwise = [(PTerm, PTerm)] -> Maybe [(PTerm, PTerm)]
forall a. a -> Maybe a
Just [(PTerm
l, PTerm
t), (PTerm
Placeholder, PTerm
r)]
    dPairElts PTerm
_ = Maybe [(PTerm, PTerm)]
forall a. Maybe a
Nothing

    natns :: String
natns = String
"Prelude.Nat."

    snat :: PPOption -> Maybe Int -> Int -> PTerm -> Maybe Integer
    snat :: PPOption -> Maybe Int -> Int -> PTerm -> Maybe Integer
snat PPOption
ppo Maybe Int
d Int
p PTerm
e
         | PPOption -> Bool
ppopt_desugarnats PPOption
ppo = Maybe Integer
forall a. Maybe a
Nothing
         | Bool
otherwise = Maybe Int -> Int -> PTerm -> Maybe Integer
snat' Maybe Int
d Int
p PTerm
e
         where
             snat' :: Maybe Int -> Int -> PTerm -> Maybe Integer
             snat' :: Maybe Int -> Int -> PTerm -> Maybe Integer
snat' (Just Int
x) Int
_ PTerm
_ | Int
x Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
<= Int
0 = Maybe Integer
forall a. Maybe a
Nothing
             snat' Maybe Int
d Int
p (PRef FC
_ [FC]
_ Name
z)
               | Name -> String
forall a. Show a => a -> String
show Name
z String -> String -> Bool
forall a. Eq a => a -> a -> Bool
== (String
natnsString -> ShowS
forall a. [a] -> [a] -> [a]
++String
"Z") Bool -> Bool -> Bool
|| Name -> String
forall a. Show a => a -> String
show Name
z String -> String -> Bool
forall a. Eq a => a -> a -> Bool
== String
"Z" = Integer -> Maybe Integer
forall a. a -> Maybe a
Just Integer
0
             snat' Maybe Int
d Int
p (PApp FC
_ PTerm
s [PExp {getTm :: forall t. PArg' t -> t
getTm=PTerm
n}])
               | PTerm -> String
forall a. Show a => a -> String
show PTerm
s String -> String -> Bool
forall a. Eq a => a -> a -> Bool
== (String
natnsString -> ShowS
forall a. [a] -> [a] -> [a]
++String
"S") Bool -> Bool -> Bool
|| PTerm -> String
forall a. Show a => a -> String
show PTerm
s String -> String -> Bool
forall a. Eq a => a -> a -> Bool
== String
"S",
                 Just Integer
n' <- Maybe Int -> Int -> PTerm -> Maybe Integer
snat' (Maybe Int -> Maybe Int
decD Maybe Int
d) Int
p PTerm
n
                 = Integer -> Maybe Integer
forall a. a -> Maybe a
Just (Integer -> Maybe Integer) -> Integer -> Maybe Integer
forall a b. (a -> b) -> a -> b
$ Integer
1 Integer -> Integer -> Integer
forall a. Num a => a -> a -> a
+ Integer
n'
             snat' Maybe Int
_ Int
_ PTerm
_ = Maybe Integer
forall a. Maybe a
Nothing

    bracket :: a -> a -> Doc a -> Doc a
bracket a
outer a
inner Doc a
doc
      | a
outer a -> a -> Bool
forall a. Ord a => a -> a -> Bool
> a
inner = Doc a
forall a. Doc a
lparen Doc a -> Doc a -> Doc a
forall a. Doc a -> Doc a -> Doc a
<> Doc a
doc Doc a -> Doc a -> Doc a
forall a. Doc a -> Doc a -> Doc a
<> Doc a
forall a. Doc a
rparen
      | Bool
otherwise     = Doc a
doc

    ellipsis :: Doc a
ellipsis = String -> Doc a
forall a. String -> Doc a
text String
"..."

    depth :: Maybe a -> Doc a -> Doc a
depth Maybe a
Nothing = Doc a -> Doc a
forall a. a -> a
id
    depth (Just a
d) = if a
d a -> a -> Bool
forall a. Ord a => a -> a -> Bool
<= a
0 then Doc a -> Doc a -> Doc a
forall a b. a -> b -> a
const Doc a
forall a. Doc a
ellipsis else Doc a -> Doc a
forall a. a -> a
id

    decD :: Maybe Int -> Maybe Int
decD = (Int -> Int) -> Maybe Int -> Maybe Int
forall a b. (a -> b) -> Maybe a -> Maybe b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (\Int
x -> Int
x Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
1)

    kwd :: String -> Doc OutputAnnotation
kwd = OutputAnnotation -> Doc OutputAnnotation -> Doc OutputAnnotation
forall a. a -> Doc a -> Doc a
annotate OutputAnnotation
AnnKeyword (Doc OutputAnnotation -> Doc OutputAnnotation)
-> (String -> Doc OutputAnnotation)
-> String
-> Doc OutputAnnotation
forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> Doc OutputAnnotation
forall a. String -> Doc a
text

    fixities :: M.Map String Fixity
    fixities :: Map String Fixity
fixities = [(String, Fixity)] -> Map String Fixity
forall k a. Ord k => [(k, a)] -> Map k a
M.fromList [(String
s, Fixity
f) | (Fix Fixity
f String
s) <- [FixDecl]
infixes]

    getFixity :: String -> Maybe Fixity
    getFixity :: String -> Maybe Fixity
getFixity = (String -> Map String Fixity -> Maybe Fixity)
-> Map String Fixity -> String -> Maybe Fixity
forall a b c. (a -> b -> c) -> b -> a -> c
flip String -> Map String Fixity -> Maybe Fixity
forall k a. Ord k => k -> Map k a -> Maybe a
M.lookup Map String Fixity
fixities

-- | Strip away namespace information
basename :: Name -> Name
basename :: Name -> Name
basename (NS Name
n [Text]
_) = Name -> Name
basename Name
n
basename Name
n        = Name
n

-- | Determine whether a name was the one inserted for a hole or guess
-- by the delaborator
isHoleName :: Name -> Bool
isHoleName :: Name -> Bool
isHoleName (UN Text
n) = Text
n Text -> Text -> Bool
forall a. Eq a => a -> a -> Bool
== String -> Text
T.pack String
"[__]"
isHoleName Name
_      = Bool
False

-- | Check whether a PTerm has been delaborated from a Term containing a Hole or Guess
containsHole :: PTerm -> Bool
containsHole :: PTerm -> Bool
containsHole PTerm
pterm = [Bool] -> Bool
forall (t :: * -> *). Foldable t => t Bool -> Bool
or [Name -> Bool
isHoleName Name
n | PRef FC
_ [FC]
_ Name
n <- Int -> [PTerm] -> [PTerm]
forall a. Int -> [a] -> [a]
take Int
1000 ([PTerm] -> [PTerm]) -> [PTerm] -> [PTerm]
forall a b. (a -> b) -> a -> b
$ PTerm -> [PTerm]
forall on. Uniplate on => on -> [on]
universe PTerm
pterm]

-- | Pretty-printer helper for names that attaches the correct annotations
prettyName :: Bool           -- ^ whether the name should be parenthesised if it is an infix operator
           -> Bool           -- ^ whether to show namespaces
           -> [(Name, Bool)] -- ^ the current bound variables and whether they are implicit
           -> Name           -- ^ the name to pprint
           -> Doc OutputAnnotation
prettyName :: Bool -> Bool -> [(Name, Bool)] -> Name -> Doc OutputAnnotation
prettyName Bool
infixParen Bool
showNS [(Name, Bool)]
bnd Name
n
    | (MN Int
_ Text
s)  <- Name
n, String -> String -> Bool
forall a. Eq a => [a] -> [a] -> Bool
isPrefixOf String
"_" (String -> Bool) -> String -> Bool
forall a b. (a -> b) -> a -> b
$ Text -> String
T.unpack Text
s = String -> Doc OutputAnnotation
forall a. String -> Doc a
text String
"_"
    | (UN Text
n')   <- Name
n, String -> String -> Bool
forall a. Eq a => [a] -> [a] -> Bool
isPrefixOf String
"__" (String -> Bool) -> String -> Bool
forall a b. (a -> b) -> a -> b
$ Text -> String
T.unpack Text
n' = String -> Doc OutputAnnotation
forall a. String -> Doc a
text String
"_"
    | (UN Text
n')   <- Name
n, Text -> String
T.unpack Text
n' String -> String -> Bool
forall a. Eq a => a -> a -> Bool
== String
"_" = String -> Doc OutputAnnotation
forall a. String -> Doc a
text String
"_"
    | Just Bool
imp  <- Name -> [(Name, Bool)] -> Maybe Bool
forall a b. Eq a => a -> [(a, b)] -> Maybe b
lookup Name
n [(Name, Bool)]
bnd = OutputAnnotation -> Doc OutputAnnotation -> Doc OutputAnnotation
forall a. a -> Doc a -> Doc a
annotate (Name -> Bool -> OutputAnnotation
AnnBoundName Name
n Bool
imp) Doc OutputAnnotation
forall a. Doc a
fullName
    | Bool
otherwise                 = OutputAnnotation -> Doc OutputAnnotation -> Doc OutputAnnotation
forall a. a -> Doc a -> Doc a
annotate (Name
-> Maybe NameOutput
-> Maybe String
-> Maybe String
-> OutputAnnotation
AnnName Name
n Maybe NameOutput
forall a. Maybe a
Nothing Maybe String
forall a. Maybe a
Nothing Maybe String
forall a. Maybe a
Nothing) Doc OutputAnnotation
forall a. Doc a
fullName
  where fullName :: Doc a
fullName = String -> Doc a
forall a. String -> Doc a
text String
nameSpace Doc a -> Doc a -> Doc a
forall a. Doc a -> Doc a -> Doc a
<> Doc a -> Doc a
forall a. Doc a -> Doc a
parenthesise (String -> Doc a
forall a. String -> Doc a
text (Name -> String
baseName Name
n))
        baseName :: Name -> String
baseName (UN Text
n)     = Text -> String
T.unpack Text
n
        baseName (NS Name
n [Text]
ns)  = Name -> String
baseName Name
n
        baseName (MN Int
i Text
s)   = Text -> String
T.unpack Text
s
        baseName Name
other      = Name -> String
forall a. Show a => a -> String
show Name
other
        nameSpace :: String
nameSpace = case Name
n of
          (NS Name
n' [Text]
ns) -> if Bool
showNS then (ShowS -> [String] -> String
forall (t :: * -> *) a b. Foldable t => (a -> [b]) -> t a -> [b]
concatMap (String -> ShowS
forall a. [a] -> [a] -> [a]
++ String
".") ([String] -> String) -> ([Text] -> [String]) -> [Text] -> String
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Text -> String) -> [Text] -> [String]
forall a b. (a -> b) -> [a] -> [b]
map Text -> String
T.unpack ([Text] -> [String]) -> ([Text] -> [Text]) -> [Text] -> [String]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [Text] -> [Text]
forall a. [a] -> [a]
reverse) [Text]
ns else String
""
          Name
_ -> String
""
        isInfix :: Bool
isInfix = case Name -> String
baseName Name
n of
          String
""      -> Bool
False
          (Char
c : String
_) -> Bool -> Bool
not (Char -> Bool
isAlpha Char
c)
        parenthesise :: Doc a -> Doc a
parenthesise = if Bool
isInfix Bool -> Bool -> Bool
&& Bool
infixParen then Doc a -> Doc a -> Doc a -> Doc a
forall a. Doc a -> Doc a -> Doc a -> Doc a
enclose Doc a
forall a. Doc a
lparen Doc a
forall a. Doc a
rparen else Doc a -> Doc a
forall a. a -> a
id


showCImp :: PPOption -> PClause -> Doc OutputAnnotation
showCImp :: PPOption -> PClause' PTerm -> Doc OutputAnnotation
showCImp PPOption
ppo (PClause FC
_ Name
n PTerm
l [PTerm]
ws PTerm
r [PDecl' PTerm]
w)
 = PPOption -> PTerm -> Doc OutputAnnotation
prettyImp PPOption
ppo PTerm
l Doc OutputAnnotation
-> Doc OutputAnnotation -> Doc OutputAnnotation
forall a. Doc a -> Doc a -> Doc a
<+> [PTerm] -> Doc OutputAnnotation
showWs [PTerm]
ws Doc OutputAnnotation
-> Doc OutputAnnotation -> Doc OutputAnnotation
forall a. Doc a -> Doc a -> Doc a
<+> String -> Doc OutputAnnotation
forall a. String -> Doc a
text String
"=" Doc OutputAnnotation
-> Doc OutputAnnotation -> Doc OutputAnnotation
forall a. Doc a -> Doc a -> Doc a
<+> PPOption -> PTerm -> Doc OutputAnnotation
prettyImp PPOption
ppo PTerm
r
             Doc OutputAnnotation
-> Doc OutputAnnotation -> Doc OutputAnnotation
forall a. Doc a -> Doc a -> Doc a
<+> String -> Doc OutputAnnotation
forall a. String -> Doc a
text String
"where" Doc OutputAnnotation
-> Doc OutputAnnotation -> Doc OutputAnnotation
forall a. Doc a -> Doc a -> Doc a
<+> String -> Doc OutputAnnotation
forall a. String -> Doc a
text ([PDecl' PTerm] -> String
forall a. Show a => a -> String
show [PDecl' PTerm]
w)
  where
    showWs :: [PTerm] -> Doc OutputAnnotation
showWs []       = Doc OutputAnnotation
forall a. Doc a
empty
    showWs (PTerm
x : [PTerm]
xs) = String -> Doc OutputAnnotation
forall a. String -> Doc a
text String
"|" Doc OutputAnnotation
-> Doc OutputAnnotation -> Doc OutputAnnotation
forall a. Doc a -> Doc a -> Doc a
<+> PPOption -> PTerm -> Doc OutputAnnotation
prettyImp PPOption
ppo PTerm
x Doc OutputAnnotation
-> Doc OutputAnnotation -> Doc OutputAnnotation
forall a. Doc a -> Doc a -> Doc a
<+> [PTerm] -> Doc OutputAnnotation
showWs [PTerm]
xs
showCImp PPOption
ppo (PWith FC
_ Name
n PTerm
l [PTerm]
ws PTerm
r Maybe (Name, FC)
pn [PDecl' PTerm]
w)
 = PPOption -> PTerm -> Doc OutputAnnotation
prettyImp PPOption
ppo PTerm
l Doc OutputAnnotation
-> Doc OutputAnnotation -> Doc OutputAnnotation
forall a. Doc a -> Doc a -> Doc a
<+> [PTerm] -> Doc OutputAnnotation
showWs [PTerm]
ws Doc OutputAnnotation
-> Doc OutputAnnotation -> Doc OutputAnnotation
forall a. Doc a -> Doc a -> Doc a
<+> String -> Doc OutputAnnotation
forall a. String -> Doc a
text String
"with" Doc OutputAnnotation
-> Doc OutputAnnotation -> Doc OutputAnnotation
forall a. Doc a -> Doc a -> Doc a
<+> PPOption -> PTerm -> Doc OutputAnnotation
prettyImp PPOption
ppo PTerm
r
                 Doc OutputAnnotation
-> Doc OutputAnnotation -> Doc OutputAnnotation
forall a. Doc a -> Doc a -> Doc a
<+> Doc OutputAnnotation -> Doc OutputAnnotation
forall a. Doc a -> Doc a
braces (String -> Doc OutputAnnotation
forall a. String -> Doc a
text ([PDecl' PTerm] -> String
forall a. Show a => a -> String
show [PDecl' PTerm]
w))
  where
    showWs :: [PTerm] -> Doc OutputAnnotation
showWs []       = Doc OutputAnnotation
forall a. Doc a
empty
    showWs (PTerm
x : [PTerm]
xs) = String -> Doc OutputAnnotation
forall a. String -> Doc a
text String
"|" Doc OutputAnnotation
-> Doc OutputAnnotation -> Doc OutputAnnotation
forall a. Doc a -> Doc a -> Doc a
<+> PPOption -> PTerm -> Doc OutputAnnotation
prettyImp PPOption
ppo PTerm
x Doc OutputAnnotation
-> Doc OutputAnnotation -> Doc OutputAnnotation
forall a. Doc a -> Doc a -> Doc a
<+> [PTerm] -> Doc OutputAnnotation
showWs [PTerm]
xs


showDImp :: PPOption -> PData -> Doc OutputAnnotation
showDImp :: PPOption -> PData -> Doc OutputAnnotation
showDImp PPOption
ppo (PDatadecl Name
n FC
nfc PTerm
ty [(Docstring (Either Err PTerm),
  [(Name, Docstring (Either Err PTerm))], Name, FC, PTerm, FC,
  [Name])]
cons)
 = String -> Doc OutputAnnotation
forall a. String -> Doc a
text String
"data" Doc OutputAnnotation
-> Doc OutputAnnotation -> Doc OutputAnnotation
forall a. Doc a -> Doc a -> Doc a
<+> String -> Doc OutputAnnotation
forall a. String -> Doc a
text (Name -> String
forall a. Show a => a -> String
show Name
n) Doc OutputAnnotation
-> Doc OutputAnnotation -> Doc OutputAnnotation
forall a. Doc a -> Doc a -> Doc a
<+> Doc OutputAnnotation
forall a. Doc a
colon Doc OutputAnnotation
-> Doc OutputAnnotation -> Doc OutputAnnotation
forall a. Doc a -> Doc a -> Doc a
<+> PPOption -> PTerm -> Doc OutputAnnotation
prettyImp PPOption
ppo PTerm
ty Doc OutputAnnotation
-> Doc OutputAnnotation -> Doc OutputAnnotation
forall a. Doc a -> Doc a -> Doc a
<+> String -> Doc OutputAnnotation
forall a. String -> Doc a
text String
"where" Doc OutputAnnotation
-> Doc OutputAnnotation -> Doc OutputAnnotation
forall a. Doc a -> Doc a -> Doc a
<$>
    (Int -> Doc OutputAnnotation -> Doc OutputAnnotation
forall a. Int -> Doc a -> Doc a
indent Int
2 (Doc OutputAnnotation -> Doc OutputAnnotation)
-> Doc OutputAnnotation -> Doc OutputAnnotation
forall a b. (a -> b) -> a -> b
$ [Doc OutputAnnotation] -> Doc OutputAnnotation
forall a. [Doc a] -> Doc a
vsep (((Docstring (Either Err PTerm),
  [(Name, Docstring (Either Err PTerm))], Name, FC, PTerm, FC,
  [Name])
 -> Doc OutputAnnotation)
-> [(Docstring (Either Err PTerm),
     [(Name, Docstring (Either Err PTerm))], Name, FC, PTerm, FC,
     [Name])]
-> [Doc OutputAnnotation]
forall a b. (a -> b) -> [a] -> [b]
map (\ (Docstring (Either Err PTerm)
_, [(Name, Docstring (Either Err PTerm))]
_, Name
n, FC
_, PTerm
t, FC
_, [Name]
_) -> Doc OutputAnnotation
forall a. Doc a
pipe Doc OutputAnnotation
-> Doc OutputAnnotation -> Doc OutputAnnotation
forall a. Doc a -> Doc a -> Doc a
<+> Bool -> Bool -> [(Name, Bool)] -> Name -> Doc OutputAnnotation
prettyName Bool
True Bool
False [] Name
n Doc OutputAnnotation
-> Doc OutputAnnotation -> Doc OutputAnnotation
forall a. Doc a -> Doc a -> Doc a
<+> Doc OutputAnnotation
forall a. Doc a
colon Doc OutputAnnotation
-> Doc OutputAnnotation -> Doc OutputAnnotation
forall a. Doc a -> Doc a -> Doc a
<+> PPOption -> PTerm -> Doc OutputAnnotation
prettyImp PPOption
ppo PTerm
t) [(Docstring (Either Err PTerm),
  [(Name, Docstring (Either Err PTerm))], Name, FC, PTerm, FC,
  [Name])]
cons))

showDecls :: PPOption -> [PDecl] -> Doc OutputAnnotation
showDecls :: PPOption -> [PDecl' PTerm] -> Doc OutputAnnotation
showDecls PPOption
o [PDecl' PTerm]
ds = [Doc OutputAnnotation] -> Doc OutputAnnotation
forall a. [Doc a] -> Doc a
vsep ((PDecl' PTerm -> Doc OutputAnnotation)
-> [PDecl' PTerm] -> [Doc OutputAnnotation]
forall a b. (a -> b) -> [a] -> [b]
map (PPOption -> PDecl' PTerm -> Doc OutputAnnotation
showDeclImp PPOption
o) [PDecl' PTerm]
ds)

showDeclImp :: PPOption -> PDecl' PTerm -> Doc OutputAnnotation
showDeclImp PPOption
_ (PFix FC
_ Fixity
f [String]
ops)        = String -> Doc OutputAnnotation
forall a. String -> Doc a
text (Fixity -> String
forall a. Show a => a -> String
show Fixity
f) Doc OutputAnnotation
-> Doc OutputAnnotation -> Doc OutputAnnotation
forall a. Doc a -> Doc a -> Doc a
<+> [Doc OutputAnnotation] -> Doc OutputAnnotation
forall a. [Doc a] -> Doc a
cat (Doc OutputAnnotation
-> [Doc OutputAnnotation] -> [Doc OutputAnnotation]
forall a. Doc a -> [Doc a] -> [Doc a]
punctuate (String -> Doc OutputAnnotation
forall a. String -> Doc a
text String
",") ((String -> Doc OutputAnnotation)
-> [String] -> [Doc OutputAnnotation]
forall a b. (a -> b) -> [a] -> [b]
map String -> Doc OutputAnnotation
forall a. String -> Doc a
text [String]
ops))
showDeclImp PPOption
o (PTy Docstring (Either Err PTerm)
_ [(Name, Docstring (Either Err PTerm))]
_ SyntaxInfo
_ FC
_ [FnOpt]
_ Name
n FC
_ PTerm
t) = String -> Doc OutputAnnotation
forall a. String -> Doc a
text String
"tydecl" Doc OutputAnnotation
-> Doc OutputAnnotation -> Doc OutputAnnotation
forall a. Doc a -> Doc a -> Doc a
<+> String -> Doc OutputAnnotation
forall a. String -> Doc a
text (Name -> String
showCG Name
n) Doc OutputAnnotation
-> Doc OutputAnnotation -> Doc OutputAnnotation
forall a. Doc a -> Doc a -> Doc a
<+> Doc OutputAnnotation
forall a. Doc a
colon Doc OutputAnnotation
-> Doc OutputAnnotation -> Doc OutputAnnotation
forall a. Doc a -> Doc a -> Doc a
<+> PPOption -> PTerm -> Doc OutputAnnotation
prettyImp PPOption
o PTerm
t
showDeclImp PPOption
o (PClauses FC
_ [FnOpt]
_ Name
n [PClause' PTerm]
cs)   = String -> Doc OutputAnnotation
forall a. String -> Doc a
text String
"pat" Doc OutputAnnotation
-> Doc OutputAnnotation -> Doc OutputAnnotation
forall a. Doc a -> Doc a -> Doc a
<+> String -> Doc OutputAnnotation
forall a. String -> Doc a
text (Name -> String
showCG Name
n) Doc OutputAnnotation
-> Doc OutputAnnotation -> Doc OutputAnnotation
forall a. Doc a -> Doc a -> Doc a
<+> String -> Doc OutputAnnotation
forall a. String -> Doc a
text String
"\t" Doc OutputAnnotation
-> Doc OutputAnnotation -> Doc OutputAnnotation
forall a. Doc a -> Doc a -> Doc a
<+>
                                      Int -> Doc OutputAnnotation -> Doc OutputAnnotation
forall a. Int -> Doc a -> Doc a
indent Int
2 ([Doc OutputAnnotation] -> Doc OutputAnnotation
forall a. [Doc a] -> Doc a
vsep ((PClause' PTerm -> Doc OutputAnnotation)
-> [PClause' PTerm] -> [Doc OutputAnnotation]
forall a b. (a -> b) -> [a] -> [b]
map (PPOption -> PClause' PTerm -> Doc OutputAnnotation
showCImp PPOption
o) [PClause' PTerm]
cs))
showDeclImp PPOption
o (PData Docstring (Either Err PTerm)
_ [(Name, Docstring (Either Err PTerm))]
_ SyntaxInfo
_ FC
_ DataOpts
_ PData
d)   = PPOption -> PData -> Doc OutputAnnotation
showDImp PPOption
o { ppopt_impl = True } PData
d
showDeclImp PPOption
o (PParams FC
_ [(Name, PTerm)]
ns [PDecl' PTerm]
ps)     = String -> Doc OutputAnnotation
forall a. String -> Doc a
text String
"params" Doc OutputAnnotation
-> Doc OutputAnnotation -> Doc OutputAnnotation
forall a. Doc a -> Doc a -> Doc a
<+> Doc OutputAnnotation -> Doc OutputAnnotation
forall a. Doc a -> Doc a
braces (String -> Doc OutputAnnotation
forall a. String -> Doc a
text ([(Name, PTerm)] -> String
forall a. Show a => a -> String
show [(Name, PTerm)]
ns) Doc OutputAnnotation
-> Doc OutputAnnotation -> Doc OutputAnnotation
forall a. Doc a -> Doc a -> Doc a
<> Doc OutputAnnotation
forall a. Doc a
line Doc OutputAnnotation
-> Doc OutputAnnotation -> Doc OutputAnnotation
forall a. Doc a -> Doc a -> Doc a
<> PPOption -> [PDecl' PTerm] -> Doc OutputAnnotation
showDecls PPOption
o [PDecl' PTerm]
ps Doc OutputAnnotation
-> Doc OutputAnnotation -> Doc OutputAnnotation
forall a. Doc a -> Doc a -> Doc a
<> Doc OutputAnnotation
forall a. Doc a
line)
showDeclImp PPOption
o (POpenInterfaces FC
_ [Name]
ns [PDecl' PTerm]
ps) = String -> Doc OutputAnnotation
forall a. String -> Doc a
text String
"open" Doc OutputAnnotation
-> Doc OutputAnnotation -> Doc OutputAnnotation
forall a. Doc a -> Doc a -> Doc a
<+> Doc OutputAnnotation -> Doc OutputAnnotation
forall a. Doc a -> Doc a
braces (String -> Doc OutputAnnotation
forall a. String -> Doc a
text ([Name] -> String
forall a. Show a => a -> String
show [Name]
ns) Doc OutputAnnotation
-> Doc OutputAnnotation -> Doc OutputAnnotation
forall a. Doc a -> Doc a -> Doc a
<> Doc OutputAnnotation
forall a. Doc a
line Doc OutputAnnotation
-> Doc OutputAnnotation -> Doc OutputAnnotation
forall a. Doc a -> Doc a -> Doc a
<> PPOption -> [PDecl' PTerm] -> Doc OutputAnnotation
showDecls PPOption
o [PDecl' PTerm]
ps Doc OutputAnnotation
-> Doc OutputAnnotation -> Doc OutputAnnotation
forall a. Doc a -> Doc a -> Doc a
<> Doc OutputAnnotation
forall a. Doc a
line)
showDeclImp PPOption
o (PNamespace String
n FC
fc [PDecl' PTerm]
ps)  = String -> Doc OutputAnnotation
forall a. String -> Doc a
text String
"namespace" Doc OutputAnnotation
-> Doc OutputAnnotation -> Doc OutputAnnotation
forall a. Doc a -> Doc a -> Doc a
<+> String -> Doc OutputAnnotation
forall a. String -> Doc a
text String
n Doc OutputAnnotation
-> Doc OutputAnnotation -> Doc OutputAnnotation
forall a. Doc a -> Doc a -> Doc a
<> Doc OutputAnnotation -> Doc OutputAnnotation
forall a. Doc a -> Doc a
braces (Doc OutputAnnotation
forall a. Doc a
line Doc OutputAnnotation
-> Doc OutputAnnotation -> Doc OutputAnnotation
forall a. Doc a -> Doc a -> Doc a
<> PPOption -> [PDecl' PTerm] -> Doc OutputAnnotation
showDecls PPOption
o [PDecl' PTerm]
ps Doc OutputAnnotation
-> Doc OutputAnnotation -> Doc OutputAnnotation
forall a. Doc a -> Doc a -> Doc a
<> Doc OutputAnnotation
forall a. Doc a
line)
showDeclImp PPOption
_ (PSyntax FC
_ Syntax
syn) = String -> Doc OutputAnnotation
forall a. String -> Doc a
text String
"syntax" Doc OutputAnnotation
-> Doc OutputAnnotation -> Doc OutputAnnotation
forall a. Doc a -> Doc a -> Doc a
<+> String -> Doc OutputAnnotation
forall a. String -> Doc a
text (Syntax -> String
forall a. Show a => a -> String
show Syntax
syn)
showDeclImp PPOption
o (PInterface Docstring (Either Err PTerm)
_ SyntaxInfo
_ FC
_ [(Name, PTerm)]
cs Name
n FC
_ [(Name, FC, PTerm)]
ps [(Name, Docstring (Either Err PTerm))]
_ [(Name, FC)]
_ [PDecl' PTerm]
ds Maybe (Name, FC)
_ Docstring (Either Err PTerm)
_)
   = String -> Doc OutputAnnotation
forall a. String -> Doc a
text String
"interface" Doc OutputAnnotation
-> Doc OutputAnnotation -> Doc OutputAnnotation
forall a. Doc a -> Doc a -> Doc a
<+> String -> Doc OutputAnnotation
forall a. String -> Doc a
text ([(Name, PTerm)] -> String
forall a. Show a => a -> String
show [(Name, PTerm)]
cs) Doc OutputAnnotation
-> Doc OutputAnnotation -> Doc OutputAnnotation
forall a. Doc a -> Doc a -> Doc a
<+> String -> Doc OutputAnnotation
forall a. String -> Doc a
text (Name -> String
forall a. Show a => a -> String
show Name
n) Doc OutputAnnotation
-> Doc OutputAnnotation -> Doc OutputAnnotation
forall a. Doc a -> Doc a -> Doc a
<+> String -> Doc OutputAnnotation
forall a. String -> Doc a
text ([(Name, FC, PTerm)] -> String
forall a. Show a => a -> String
show [(Name, FC, PTerm)]
ps) Doc OutputAnnotation
-> Doc OutputAnnotation -> Doc OutputAnnotation
forall a. Doc a -> Doc a -> Doc a
<> Doc OutputAnnotation
forall a. Doc a
line Doc OutputAnnotation
-> Doc OutputAnnotation -> Doc OutputAnnotation
forall a. Doc a -> Doc a -> Doc a
<> PPOption -> [PDecl' PTerm] -> Doc OutputAnnotation
showDecls PPOption
o [PDecl' PTerm]
ds
showDeclImp PPOption
o (PImplementation Docstring (Either Err PTerm)
_ [(Name, Docstring (Either Err PTerm))]
_ SyntaxInfo
_ FC
_ [(Name, PTerm)]
cs [Name]
_ Accessibility
acc [FnOpt]
_ Name
n FC
_ [PTerm]
_ [(Name, PTerm)]
_ PTerm
t Maybe Name
_ [PDecl' PTerm]
ds)
   = String -> Doc OutputAnnotation
forall a. String -> Doc a
text String
"implementation" Doc OutputAnnotation
-> Doc OutputAnnotation -> Doc OutputAnnotation
forall a. Doc a -> Doc a -> Doc a
<+> String -> Doc OutputAnnotation
forall a. String -> Doc a
text ([(Name, PTerm)] -> String
forall a. Show a => a -> String
show [(Name, PTerm)]
cs) Doc OutputAnnotation
-> Doc OutputAnnotation -> Doc OutputAnnotation
forall a. Doc a -> Doc a -> Doc a
<+> String -> Doc OutputAnnotation
forall a. String -> Doc a
text (Name -> String
forall a. Show a => a -> String
show Name
n) Doc OutputAnnotation
-> Doc OutputAnnotation -> Doc OutputAnnotation
forall a. Doc a -> Doc a -> Doc a
<+> PPOption -> PTerm -> Doc OutputAnnotation
prettyImp PPOption
o PTerm
t Doc OutputAnnotation
-> Doc OutputAnnotation -> Doc OutputAnnotation
forall a. Doc a -> Doc a -> Doc a
<> Doc OutputAnnotation
forall a. Doc a
line Doc OutputAnnotation
-> Doc OutputAnnotation -> Doc OutputAnnotation
forall a. Doc a -> Doc a -> Doc a
<> PPOption -> [PDecl' PTerm] -> Doc OutputAnnotation
showDecls PPOption
o [PDecl' PTerm]
ds
showDeclImp PPOption
_ PDecl' PTerm
_ = String -> Doc OutputAnnotation
forall a. String -> Doc a
text String
"..."
-- showDeclImp (PImport o) = "import " ++ o

getImps :: [PArg] -> [(Name, PTerm)]
getImps :: [PArg] -> [(Name, PTerm)]
getImps [] = []
getImps (PImp Int
_ Bool
_ [ArgOpt]
_ Name
n PTerm
tm : [PArg]
xs)  = (Name
n, PTerm
tm) (Name, PTerm) -> [(Name, PTerm)] -> [(Name, PTerm)]
forall a. a -> [a] -> [a]
: [PArg] -> [(Name, PTerm)]
getImps [PArg]
xs
getImps (PArg
_ : [PArg]
xs)                = [PArg] -> [(Name, PTerm)]
getImps [PArg]
xs

getExps :: [PArg] -> [PTerm]
getExps :: [PArg] -> [PTerm]
getExps [] = []
getExps (PExp Int
_ [ArgOpt]
_ Name
_ PTerm
tm : [PArg]
xs)  = PTerm
tm PTerm -> [PTerm] -> [PTerm]
forall a. a -> [a] -> [a]
: [PArg] -> [PTerm]
getExps [PArg]
xs
getExps (PArg
_ : [PArg]
xs)              = [PArg] -> [PTerm]
getExps [PArg]
xs

getShowArgs :: [PArg] -> [PArg]
getShowArgs :: [PArg] -> [PArg]
getShowArgs [] = []
getShowArgs (e :: PArg
e@(PExp Int
_ [ArgOpt]
_ Name
_ PTerm
_) : [PArg]
xs) = PArg
e PArg -> [PArg] -> [PArg]
forall a. a -> [a] -> [a]
: [PArg] -> [PArg]
getShowArgs [PArg]
xs
getShowArgs (PArg
e : [PArg]
xs) | ArgOpt
AlwaysShow ArgOpt -> [ArgOpt] -> Bool
forall a. Eq a => a -> [a] -> Bool
forall (t :: * -> *) a. (Foldable t, Eq a) => a -> t a -> Bool
`elem` PArg -> [ArgOpt]
forall t. PArg' t -> [ArgOpt]
argopts PArg
e = PArg
e PArg -> [PArg] -> [PArg]
forall a. a -> [a] -> [a]
: [PArg] -> [PArg]
getShowArgs [PArg]
xs
                     | PImp Int
_ Bool
_ [ArgOpt]
_ Name
_ PTerm
tm <- PArg
e
                     , PTerm -> Bool
containsHole PTerm
tm = PArg
e PArg -> [PArg] -> [PArg]
forall a. a -> [a] -> [a]
: [PArg] -> [PArg]
getShowArgs [PArg]
xs
getShowArgs (PArg
_ : [PArg]
xs) = [PArg] -> [PArg]
getShowArgs [PArg]
xs

getConsts :: [PArg] -> [PTerm]
getConsts :: [PArg] -> [PTerm]
getConsts []                          = []
getConsts (PConstraint Int
_ [ArgOpt]
_ Name
_ PTerm
tm : [PArg]
xs) = PTerm
tm PTerm -> [PTerm] -> [PTerm]
forall a. a -> [a] -> [a]
: [PArg] -> [PTerm]
getConsts [PArg]
xs
getConsts (PArg
_ : [PArg]
xs)                    = [PArg] -> [PTerm]
getConsts [PArg]
xs

getAll :: [PArg] -> [PTerm]
getAll :: [PArg] -> [PTerm]
getAll = (PArg -> PTerm) -> [PArg] -> [PTerm]
forall a b. (a -> b) -> [a] -> [b]
map PArg -> PTerm
forall t. PArg' t -> t
getTm


-- | Show Idris name
showName :: Maybe IState   -- ^ the Idris state, for information about names and colours
         -> [(Name, Bool)] -- ^ the bound variables and whether they're implicit
         -> PPOption       -- ^ pretty printing options
         -> Bool           -- ^ whether to colourise
         -> Name           -- ^ the term to show
         -> String
showName :: Maybe IState
-> [(Name, Bool)] -> PPOption -> Bool -> Name -> String
showName Maybe IState
ist [(Name, Bool)]
bnd PPOption
ppo Bool
colour Name
n = case Maybe IState
ist of
                                   Just IState
i   -> if Bool
colour then Name -> ColourTheme -> String
colourise Name
n (IState -> ColourTheme
idris_colourTheme IState
i) else Name -> String
showbasic Name
n
                                   Maybe IState
Nothing  -> Name -> String
showbasic Name
n
    where name :: String
name = if PPOption -> Bool
ppopt_impl PPOption
ppo then Name -> String
forall a. Show a => a -> String
show Name
n else Name -> String
showbasic Name
n
          showbasic :: Name -> String
showbasic n :: Name
n@(UN Text
_)  = Name -> String
showCG Name
n
          showbasic (MN Int
i Text
s)  = Text -> String
str Text
s
          showbasic (NS Name
n [Text]
s)  = String -> [String] -> String
showSep String
"." ((Text -> String) -> [Text] -> [String]
forall a b. (a -> b) -> [a] -> [b]
map Text -> String
str ([Text] -> [Text]
forall a. [a] -> [a]
reverse [Text]
s)) String -> ShowS
forall a. [a] -> [a] -> [a]
++ String
"." String -> ShowS
forall a. [a] -> [a] -> [a]
++ Name -> String
showbasic Name
n
          showbasic (SN SpecialName
s)    = SpecialName -> String
forall a. Show a => a -> String
show SpecialName
s
          colourise :: Name -> ColourTheme -> String
colourise Name
n ColourTheme
t = let ctxt' :: Maybe Context
ctxt' = (IState -> Context) -> Maybe IState -> Maybe Context
forall a b. (a -> b) -> Maybe a -> Maybe b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap IState -> Context
tt_ctxt Maybe IState
ist in
                          case Maybe Context
ctxt' of
                            Maybe Context
Nothing -> String
name
                            Just Context
ctxt | Just Bool
impl <- Name -> [(Name, Bool)] -> Maybe Bool
forall a b. Eq a => a -> [(a, b)] -> Maybe b
lookup Name
n [(Name, Bool)]
bnd -> if Bool
impl then ColourTheme -> ShowS
colouriseImplicit ColourTheme
t String
name
                                                                             else ColourTheme -> ShowS
colouriseBound ColourTheme
t String
name
                                      | Name -> Context -> Bool
isDConName Name
n Context
ctxt -> ColourTheme -> ShowS
colouriseData ColourTheme
t String
name
                                      | Name -> Context -> Bool
isFnName Name
n Context
ctxt   -> ColourTheme -> ShowS
colouriseFun ColourTheme
t String
name
                                      | Name -> Context -> Bool
isTConName Name
n Context
ctxt -> ColourTheme -> ShowS
colouriseType ColourTheme
t String
name
                                      -- The assumption is that if a name is not bound and does not exist in the
                                      -- global context, then we're somewhere in which implicit info has been lost
                                      -- (like error messages). Thus, unknown vars are colourised as implicits.
                                      | Bool
otherwise         -> ColourTheme -> ShowS
colouriseImplicit ColourTheme
t String
name

showTm :: IState -- ^ the Idris state, for information about identifiers and colours
       -> PTerm  -- ^ the term to show
       -> String
showTm :: IState -> PTerm -> String
showTm IState
ist = (OutputAnnotation -> ShowS) -> SimpleDoc OutputAnnotation -> String
forall a. (a -> ShowS) -> SimpleDoc a -> String
displayDecorated (IState -> OutputAnnotation -> ShowS
consoleDecorate IState
ist) (SimpleDoc OutputAnnotation -> String)
-> (PTerm -> SimpleDoc OutputAnnotation) -> PTerm -> String
forall b c a. (b -> c) -> (a -> b) -> a -> c
.
             Float -> Int -> Doc OutputAnnotation -> SimpleDoc OutputAnnotation
forall a. Float -> Int -> Doc a -> SimpleDoc a
renderPretty Float
0.8 Int
100000 (Doc OutputAnnotation -> SimpleDoc OutputAnnotation)
-> (PTerm -> Doc OutputAnnotation)
-> PTerm
-> SimpleDoc OutputAnnotation
forall b c a. (b -> c) -> (a -> b) -> a -> c
.
             PPOption -> PTerm -> Doc OutputAnnotation
prettyImp (IState -> PPOption
ppOptionIst IState
ist)

-- | Show a term with implicits, no colours
showTmImpls :: PTerm -> String
showTmImpls :: PTerm -> String
showTmImpls = (PTerm -> ShowS) -> String -> PTerm -> String
forall a b c. (a -> b -> c) -> b -> a -> c
flip (SimpleDoc OutputAnnotation -> ShowS
forall a. SimpleDoc a -> ShowS
displayS (SimpleDoc OutputAnnotation -> ShowS)
-> (PTerm -> SimpleDoc OutputAnnotation) -> PTerm -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Doc OutputAnnotation -> SimpleDoc OutputAnnotation
forall a. Doc a -> SimpleDoc a
renderCompact (Doc OutputAnnotation -> SimpleDoc OutputAnnotation)
-> (PTerm -> Doc OutputAnnotation)
-> PTerm
-> SimpleDoc OutputAnnotation
forall b c a. (b -> c) -> (a -> b) -> a -> c
. PPOption -> PTerm -> Doc OutputAnnotation
prettyImp PPOption
verbosePPOption) String
""

-- | Show a term with specific options
showTmOpts :: PPOption -> PTerm -> String
showTmOpts :: PPOption -> PTerm -> String
showTmOpts PPOption
opt = (PTerm -> ShowS) -> String -> PTerm -> String
forall a b c. (a -> b -> c) -> b -> a -> c
flip (SimpleDoc OutputAnnotation -> ShowS
forall a. SimpleDoc a -> ShowS
displayS (SimpleDoc OutputAnnotation -> ShowS)
-> (PTerm -> SimpleDoc OutputAnnotation) -> PTerm -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Float -> Int -> Doc OutputAnnotation -> SimpleDoc OutputAnnotation
forall a. Float -> Int -> Doc a -> SimpleDoc a
renderPretty Float
1.0 Int
10000000 (Doc OutputAnnotation -> SimpleDoc OutputAnnotation)
-> (PTerm -> Doc OutputAnnotation)
-> PTerm
-> SimpleDoc OutputAnnotation
forall b c a. (b -> c) -> (a -> b) -> a -> c
. PPOption -> PTerm -> Doc OutputAnnotation
prettyImp PPOption
opt) String
""


instance Sized PTerm where
  size :: PTerm -> Int
size (PQuote Raw
rawTerm)               = Raw -> Int
forall a. Sized a => a -> Int
size Raw
rawTerm
  size (PRef FC
fc [FC]
_ Name
name)               = Name -> Int
forall a. Sized a => a -> Int
size Name
name
  size (PLam FC
fc Name
name FC
_ PTerm
ty PTerm
bdy)        = Int
1 Int -> Int -> Int
forall a. Num a => a -> a -> a
+ PTerm -> Int
forall a. Sized a => a -> Int
size PTerm
ty Int -> Int -> Int
forall a. Num a => a -> a -> a
+ PTerm -> Int
forall a. Sized a => a -> Int
size PTerm
bdy
  size (PPi Plicity
plicity Name
name FC
fc PTerm
ty PTerm
bdy)   = Int
1 Int -> Int -> Int
forall a. Num a => a -> a -> a
+ PTerm -> Int
forall a. Sized a => a -> Int
size PTerm
ty Int -> Int -> Int
forall a. Num a => a -> a -> a
+ FC -> Int
forall a. Sized a => a -> Int
size FC
fc Int -> Int -> Int
forall a. Num a => a -> a -> a
+ PTerm -> Int
forall a. Sized a => a -> Int
size PTerm
bdy
  size (PLet FC
fc RigCount
_ Name
name FC
nfc PTerm
ty PTerm
def PTerm
bdy) = Int
1 Int -> Int -> Int
forall a. Num a => a -> a -> a
+ PTerm -> Int
forall a. Sized a => a -> Int
size PTerm
ty Int -> Int -> Int
forall a. Num a => a -> a -> a
+ PTerm -> Int
forall a. Sized a => a -> Int
size PTerm
def Int -> Int -> Int
forall a. Num a => a -> a -> a
+ PTerm -> Int
forall a. Sized a => a -> Int
size PTerm
bdy
  size (PTyped PTerm
trm PTerm
ty)                = Int
1 Int -> Int -> Int
forall a. Num a => a -> a -> a
+ PTerm -> Int
forall a. Sized a => a -> Int
size PTerm
trm Int -> Int -> Int
forall a. Num a => a -> a -> a
+ PTerm -> Int
forall a. Sized a => a -> Int
size PTerm
ty
  size (PApp FC
fc PTerm
name [PArg]
args)            = Int
1 Int -> Int -> Int
forall a. Num a => a -> a -> a
+ [PArg] -> Int
forall a. Sized a => a -> Int
size [PArg]
args
  size (PAppBind FC
fc PTerm
name [PArg]
args)        = Int
1 Int -> Int -> Int
forall a. Num a => a -> a -> a
+ [PArg] -> Int
forall a. Sized a => a -> Int
size [PArg]
args
  size (PCase FC
fc PTerm
trm [(PTerm, PTerm)]
bdy)             = Int
1 Int -> Int -> Int
forall a. Num a => a -> a -> a
+ PTerm -> Int
forall a. Sized a => a -> Int
size PTerm
trm Int -> Int -> Int
forall a. Num a => a -> a -> a
+ [(PTerm, PTerm)] -> Int
forall a. Sized a => a -> Int
size [(PTerm, PTerm)]
bdy
  size (PIfThenElse FC
fc PTerm
c PTerm
t PTerm
f)         = Int
1 Int -> Int -> Int
forall a. Num a => a -> a -> a
+ [Int] -> Int
forall a. Num a => [a] -> a
forall (t :: * -> *) a. (Foldable t, Num a) => t a -> a
sum ((PTerm -> Int) -> [PTerm] -> [Int]
forall a b. (a -> b) -> [a] -> [b]
map PTerm -> Int
forall a. Sized a => a -> Int
size [PTerm
c, PTerm
t, PTerm
f])
  size (PTrue FC
fc PunInfo
_)                   = Int
1
  size (PResolveTC FC
fc)                = Int
1
  size (PRewrite FC
fc Maybe Name
by PTerm
left PTerm
right Maybe PTerm
_)  = Int
1 Int -> Int -> Int
forall a. Num a => a -> a -> a
+ PTerm -> Int
forall a. Sized a => a -> Int
size PTerm
left Int -> Int -> Int
forall a. Num a => a -> a -> a
+ PTerm -> Int
forall a. Sized a => a -> Int
size PTerm
right
  size (PPair FC
fc [FC]
_ PunInfo
_ PTerm
left PTerm
right)      = Int
1 Int -> Int -> Int
forall a. Num a => a -> a -> a
+ PTerm -> Int
forall a. Sized a => a -> Int
size PTerm
left Int -> Int -> Int
forall a. Num a => a -> a -> a
+ PTerm -> Int
forall a. Sized a => a -> Int
size PTerm
right
  size (PDPair FC
fs [FC]
_ PunInfo
_ PTerm
left PTerm
ty PTerm
right)  = Int
1 Int -> Int -> Int
forall a. Num a => a -> a -> a
+ PTerm -> Int
forall a. Sized a => a -> Int
size PTerm
left Int -> Int -> Int
forall a. Num a => a -> a -> a
+ PTerm -> Int
forall a. Sized a => a -> Int
size PTerm
ty Int -> Int -> Int
forall a. Num a => a -> a -> a
+ PTerm -> Int
forall a. Sized a => a -> Int
size PTerm
right
  size (PAlternative [(Name, Name)]
_ PAltType
a [PTerm]
alts)        = Int
1 Int -> Int -> Int
forall a. Num a => a -> a -> a
+ [PTerm] -> Int
forall a. Sized a => a -> Int
size [PTerm]
alts
  size (PHidden PTerm
hidden)               = PTerm -> Int
forall a. Sized a => a -> Int
size PTerm
hidden
  size (PUnifyLog PTerm
tm)                 = PTerm -> Int
forall a. Sized a => a -> Int
size PTerm
tm
  size (PDisamb [[Text]]
_ PTerm
tm)                 = PTerm -> Int
forall a. Sized a => a -> Int
size PTerm
tm
  size (PNoImplicits PTerm
tm)              = PTerm -> Int
forall a. Sized a => a -> Int
size PTerm
tm
  size (PType FC
_)                      = Int
1
  size (PUniverse FC
_ Universe
_)                = Int
1
  size (PConstant FC
fc Const
const)           = Int
1 Int -> Int -> Int
forall a. Num a => a -> a -> a
+ FC -> Int
forall a. Sized a => a -> Int
size FC
fc Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Const -> Int
forall a. Sized a => a -> Int
size Const
const
  size PTerm
Placeholder                    = Int
1
  size (PDoBlock [PDo]
dos)                 = Int
1 Int -> Int -> Int
forall a. Num a => a -> a -> a
+ [PDo] -> Int
forall a. Sized a => a -> Int
size [PDo]
dos
  size (PIdiom FC
fc PTerm
term)               = Int
1 Int -> Int -> Int
forall a. Num a => a -> a -> a
+ PTerm -> Int
forall a. Sized a => a -> Int
size PTerm
term
  size (PMetavar FC
_ Name
name)              = Int
1
  size (PProof [PTactic]
tactics)               = [PTactic] -> Int
forall a. Sized a => a -> Int
size [PTactic]
tactics
  size (PElabError Err
err)               = Err -> Int
forall a. Sized a => a -> Int
size Err
err
  size PTerm
PImpossible                    = Int
1
  size PTerm
_                              = Int
0

getPArity :: PTerm -> Int
getPArity :: PTerm -> Int
getPArity (PPi Plicity
_ Name
_ FC
_ PTerm
_ PTerm
sc)  = Int
1 Int -> Int -> Int
forall a. Num a => a -> a -> a
+ PTerm -> Int
getPArity PTerm
sc
getPArity PTerm
_                 = Int
0

-- Return all names, free or globally bound, in the given term.

allNamesIn :: PTerm -> [Name]
allNamesIn :: PTerm -> [Name]
allNamesIn PTerm
tm = [Name] -> [Name]
forall a. Eq a => [a] -> [a]
nub ([Name] -> [Name]) -> [Name] -> [Name]
forall a b. (a -> b) -> a -> b
$ Integer -> [Name] -> PTerm -> [Name]
forall {t}. (Eq t, Num t) => t -> [Name] -> PTerm -> [Name]
ni Integer
0 [] PTerm
tm
  where -- TODO THINK added niTacImp, but is it right?
    ni :: t -> [Name] -> PTerm -> [Name]
ni t
0 [Name]
env (PRef FC
_ [FC]
_ Name
n)
        | Bool -> Bool
not (Name
n Name -> [Name] -> Bool
forall a. Eq a => a -> [a] -> Bool
forall (t :: * -> *) a. (Foldable t, Eq a) => a -> t a -> Bool
`elem` [Name]
env)          = [Name
n]
    ni t
0 [Name]
env (PPatvar FC
_ Name
n)            = [Name
n]
    ni t
0 [Name]
env (PApp FC
_ PTerm
f [PArg]
as)            = t -> [Name] -> PTerm -> [Name]
ni t
0 [Name]
env PTerm
f [Name] -> [Name] -> [Name]
forall a. [a] -> [a] -> [a]
++ (PArg -> [Name]) -> [PArg] -> [Name]
forall (t :: * -> *) a b. Foldable t => (a -> [b]) -> t a -> [b]
concatMap (t -> [Name] -> PTerm -> [Name]
ni t
0 [Name]
env (PTerm -> [Name]) -> (PArg -> PTerm) -> PArg -> [Name]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. PArg -> PTerm
forall t. PArg' t -> t
getTm) [PArg]
as
    ni t
0 [Name]
env (PAppBind FC
_ PTerm
f [PArg]
as)        = t -> [Name] -> PTerm -> [Name]
ni t
0 [Name]
env PTerm
f [Name] -> [Name] -> [Name]
forall a. [a] -> [a] -> [a]
++ (PArg -> [Name]) -> [PArg] -> [Name]
forall (t :: * -> *) a b. Foldable t => (a -> [b]) -> t a -> [b]
concatMap (t -> [Name] -> PTerm -> [Name]
ni t
0 [Name]
env (PTerm -> [Name]) -> (PArg -> PTerm) -> PArg -> [Name]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. PArg -> PTerm
forall t. PArg' t -> t
getTm) [PArg]
as
    ni t
0 [Name]
env (PWithApp FC
_ PTerm
f PTerm
a)         = t -> [Name] -> PTerm -> [Name]
ni t
0 [Name]
env PTerm
f [Name] -> [Name] -> [Name]
forall a. [a] -> [a] -> [a]
++ t -> [Name] -> PTerm -> [Name]
ni t
0 [Name]
env PTerm
a
    ni t
0 [Name]
env (PAppImpl PTerm
t [ImplicitInfo]
_)           = t -> [Name] -> PTerm -> [Name]
ni t
0 [Name]
env PTerm
t
    ni t
0 [Name]
env (PCase FC
_ PTerm
c [(PTerm, PTerm)]
os)           = t -> [Name] -> PTerm -> [Name]
ni t
0 [Name]
env PTerm
c [Name] -> [Name] -> [Name]
forall a. [a] -> [a] -> [a]
++ ((PTerm, PTerm) -> [Name]) -> [(PTerm, PTerm)] -> [Name]
forall (t :: * -> *) a b. Foldable t => (a -> [b]) -> t a -> [b]
concatMap (t -> [Name] -> PTerm -> [Name]
ni t
0 [Name]
env (PTerm -> [Name])
-> ((PTerm, PTerm) -> PTerm) -> (PTerm, PTerm) -> [Name]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (PTerm, PTerm) -> PTerm
forall a b. (a, b) -> b
snd) [(PTerm, PTerm)]
os
    ni t
0 [Name]
env (PIfThenElse FC
_ PTerm
c PTerm
t PTerm
f)    = t -> [Name] -> PTerm -> [Name]
ni t
0 [Name]
env PTerm
c [Name] -> [Name] -> [Name]
forall a. [a] -> [a] -> [a]
++ t -> [Name] -> PTerm -> [Name]
ni t
0 [Name]
env PTerm
t [Name] -> [Name] -> [Name]
forall a. [a] -> [a] -> [a]
++ t -> [Name] -> PTerm -> [Name]
ni t
0 [Name]
env PTerm
f
    ni t
0 [Name]
env (PLam FC
fc Name
n FC
_ PTerm
ty PTerm
sc)      = t -> [Name] -> PTerm -> [Name]
ni t
0 [Name]
env PTerm
ty [Name] -> [Name] -> [Name]
forall a. [a] -> [a] -> [a]
++ t -> [Name] -> PTerm -> [Name]
ni t
0 (Name
nName -> [Name] -> [Name]
forall a. a -> [a] -> [a]
:[Name]
env) PTerm
sc
    ni t
0 [Name]
env (PPi Plicity
p Name
n FC
_ PTerm
ty PTerm
sc)        = t -> [Name] -> Plicity -> [Name]
niTacImp t
0 [Name]
env Plicity
p [Name] -> [Name] -> [Name]
forall a. [a] -> [a] -> [a]
++ t -> [Name] -> PTerm -> [Name]
ni t
0 [Name]
env PTerm
ty [Name] -> [Name] -> [Name]
forall a. [a] -> [a] -> [a]
++ t -> [Name] -> PTerm -> [Name]
ni t
0 (Name
nName -> [Name] -> [Name]
forall a. a -> [a] -> [a]
:[Name]
env) PTerm
sc
    ni t
0 [Name]
env (PLet FC
_ RigCount
_ Name
n FC
_ PTerm
ty PTerm
val PTerm
sc) = t -> [Name] -> PTerm -> [Name]
ni t
0 [Name]
env PTerm
ty [Name] -> [Name] -> [Name]
forall a. [a] -> [a] -> [a]
++ t -> [Name] -> PTerm -> [Name]
ni t
0 [Name]
env PTerm
val [Name] -> [Name] -> [Name]
forall a. [a] -> [a] -> [a]
++ t -> [Name] -> PTerm -> [Name]
ni t
0 (Name
nName -> [Name] -> [Name]
forall a. a -> [a] -> [a]
:[Name]
env) PTerm
sc
    ni t
0 [Name]
env (PHidden PTerm
tm)             = t -> [Name] -> PTerm -> [Name]
ni t
0 [Name]
env PTerm
tm
    ni t
0 [Name]
env (PGoal FC
_ PTerm
t Name
_ PTerm
sc)         = t -> [Name] -> PTerm -> [Name]
ni t
0 [Name]
env PTerm
t [Name] -> [Name] -> [Name]
forall a. [a] -> [a] -> [a]
++ t -> [Name] -> PTerm -> [Name]
ni t
0 [Name]
env PTerm
sc
    ni t
0 [Name]
env (PIdiom FC
_ PTerm
tm)            = t -> [Name] -> PTerm -> [Name]
ni t
0 [Name]
env PTerm
tm
    ni t
0 [Name]
env (PRewrite FC
_ Maybe Name
_ PTerm
l PTerm
r Maybe PTerm
_)     = t -> [Name] -> PTerm -> [Name]
ni t
0 [Name]
env PTerm
l [Name] -> [Name] -> [Name]
forall a. [a] -> [a] -> [a]
++ t -> [Name] -> PTerm -> [Name]
ni t
0 [Name]
env PTerm
r
    ni t
0 [Name]
env (PTyped PTerm
l PTerm
r)             = t -> [Name] -> PTerm -> [Name]
ni t
0 [Name]
env PTerm
l [Name] -> [Name] -> [Name]
forall a. [a] -> [a] -> [a]
++ t -> [Name] -> PTerm -> [Name]
ni t
0 [Name]
env PTerm
r
    ni t
0 [Name]
env (PPair FC
_ [FC]
_ PunInfo
_ PTerm
l PTerm
r)        = t -> [Name] -> PTerm -> [Name]
ni t
0 [Name]
env PTerm
l [Name] -> [Name] -> [Name]
forall a. [a] -> [a] -> [a]
++ t -> [Name] -> PTerm -> [Name]
ni t
0 [Name]
env PTerm
r
    ni t
0 [Name]
env (PDPair FC
_ [FC]
_ PunInfo
_ (PRef FC
_ [FC]
_ Name
n) PTerm
Placeholder PTerm
r) = Name
n Name -> [Name] -> [Name]
forall a. a -> [a] -> [a]
: t -> [Name] -> PTerm -> [Name]
ni t
0 [Name]
env PTerm
r
    ni t
0 [Name]
env (PDPair FC
_ [FC]
_ PunInfo
_ (PRef FC
_ [FC]
_ Name
n) PTerm
t PTerm
r) = t -> [Name] -> PTerm -> [Name]
ni t
0 [Name]
env PTerm
t [Name] -> [Name] -> [Name]
forall a. [a] -> [a] -> [a]
++ t -> [Name] -> PTerm -> [Name]
ni t
0 (Name
nName -> [Name] -> [Name]
forall a. a -> [a] -> [a]
:[Name]
env) PTerm
r
    ni t
0 [Name]
env (PDPair FC
_ [FC]
_ PunInfo
_ PTerm
l PTerm
t PTerm
r)     = t -> [Name] -> PTerm -> [Name]
ni t
0 [Name]
env PTerm
l [Name] -> [Name] -> [Name]
forall a. [a] -> [a] -> [a]
++ t -> [Name] -> PTerm -> [Name]
ni t
0 [Name]
env PTerm
t [Name] -> [Name] -> [Name]
forall a. [a] -> [a] -> [a]
++ t -> [Name] -> PTerm -> [Name]
ni t
0 [Name]
env PTerm
r
    ni t
0 [Name]
env (PAs FC
_ Name
_ PTerm
tm)             = t -> [Name] -> PTerm -> [Name]
ni t
0 [Name]
env PTerm
tm
    -- Just take the first, when disambiguating, since the shape will be
    -- the same and we'll get the name root
    ni t
0 [Name]
env (PAlternative [(Name, Name)]
ns (ExactlyOne Bool
_) (PTerm
a : [PTerm]
as))
            = ((Name, Name) -> Name) -> [(Name, Name)] -> [Name]
forall a b. (a -> b) -> [a] -> [b]
map (Name, Name) -> Name
forall a b. (a, b) -> b
snd [(Name, Name)]
ns [Name] -> [Name] -> [Name]
forall a. [a] -> [a] -> [a]
++ t -> [Name] -> PTerm -> [Name]
ni t
0 [Name]
env PTerm
a
    ni t
0 [Name]
env (PAlternative [(Name, Name)]
ns PAltType
a [PTerm]
ls)   = ((Name, Name) -> Name) -> [(Name, Name)] -> [Name]
forall a b. (a -> b) -> [a] -> [b]
map (Name, Name) -> Name
forall a b. (a, b) -> b
snd [(Name, Name)]
ns [Name] -> [Name] -> [Name]
forall a. [a] -> [a] -> [a]
++ (PTerm -> [Name]) -> [PTerm] -> [Name]
forall (t :: * -> *) a b. Foldable t => (a -> [b]) -> t a -> [b]
concatMap (t -> [Name] -> PTerm -> [Name]
ni t
0 [Name]
env) [PTerm]
ls
    ni t
0 [Name]
env (PUnifyLog PTerm
tm)           = t -> [Name] -> PTerm -> [Name]
ni t
0 [Name]
env PTerm
tm
    ni t
0 [Name]
env (PDisamb [[Text]]
_ PTerm
tm)           = t -> [Name] -> PTerm -> [Name]
ni t
0 [Name]
env PTerm
tm
    ni t
0 [Name]
env (PNoImplicits PTerm
tm)        = t -> [Name] -> PTerm -> [Name]
ni t
0 [Name]
env PTerm
tm
    ni t
0 [Name]
env (PCoerced PTerm
tm)            = t -> [Name] -> PTerm -> [Name]
ni t
0 [Name]
env PTerm
tm
    ni t
0 [Name]
env (PRunElab FC
_ PTerm
tm [String]
_)        = t -> [Name] -> PTerm -> [Name]
ni t
0 [Name]
env PTerm
tm
    ni t
0 [Name]
env (PConstSugar FC
_ PTerm
tm)       = t -> [Name] -> PTerm -> [Name]
ni t
0 [Name]
env PTerm
tm
    ni t
0 [Name]
env tm :: PTerm
tm@(PDoBlock [PDo]
_)      = (PTerm -> [Name]) -> [PTerm] -> [Name]
forall (t :: * -> *) a b. Foldable t => (a -> [b]) -> t a -> [b]
concatMap (t -> [Name] -> PTerm -> [Name]
ni t
0 [Name]
env) (PTerm -> [PTerm]
forall on. Uniplate on => on -> [on]
children PTerm
tm)
    ni t
0 [Name]
env tm :: PTerm
tm@(PProof [PTactic]
_)        = (PTerm -> [Name]) -> [PTerm] -> [Name]
forall (t :: * -> *) a b. Foldable t => (a -> [b]) -> t a -> [b]
concatMap (t -> [Name] -> PTerm -> [Name]
ni t
0 [Name]
env) (PTerm -> [PTerm]
forall on. Uniplate on => on -> [on]
children PTerm
tm)
    ni t
0 [Name]
env tm :: PTerm
tm@(PTactics [PTactic]
_)      = (PTerm -> [Name]) -> [PTerm] -> [Name]
forall (t :: * -> *) a b. Foldable t => (a -> [b]) -> t a -> [b]
concatMap (t -> [Name] -> PTerm -> [Name]
ni t
0 [Name]
env) (PTerm -> [PTerm]
forall on. Uniplate on => on -> [on]
children PTerm
tm)

    ni t
i [Name]
env (PQuasiquote PTerm
tm Maybe PTerm
ty)  = t -> [Name] -> PTerm -> [Name]
ni (t
it -> t -> t
forall a. Num a => a -> a -> a
+t
1) [Name]
env PTerm
tm [Name] -> [Name] -> [Name]
forall a. [a] -> [a] -> [a]
++ [Name] -> (PTerm -> [Name]) -> Maybe PTerm -> [Name]
forall b a. b -> (a -> b) -> Maybe a -> b
maybe [] (t -> [Name] -> PTerm -> [Name]
ni t
i [Name]
env) Maybe PTerm
ty
    ni t
i [Name]
env (PUnquote PTerm
tm)        = t -> [Name] -> PTerm -> [Name]
ni (t
i t -> t -> t
forall a. Num a => a -> a -> a
- t
1) [Name]
env PTerm
tm
    ni t
0 [Name]
env PTerm
tm                   = []
    ni t
i [Name]
env PTerm
tm                   = (PTerm -> [Name]) -> [PTerm] -> [Name]
forall (t :: * -> *) a b. Foldable t => (a -> [b]) -> t a -> [b]
concatMap (t -> [Name] -> PTerm -> [Name]
ni t
i [Name]
env) (PTerm -> [PTerm]
forall on. Uniplate on => on -> [on]
children PTerm
tm)

    niTacImp :: t -> [Name] -> Plicity -> [Name]
niTacImp t
i [Name]
env (TacImp [ArgOpt]
_ Static
_ PTerm
scr RigCount
_) = t -> [Name] -> PTerm -> [Name]
ni t
i [Name]
env PTerm
scr
    niTacImp t
_ [Name]
_ Plicity
_                  = []


-- Return all names defined in binders in the given term
boundNamesIn :: PTerm -> [Name]
boundNamesIn :: PTerm -> [Name]
boundNamesIn PTerm
tm = Set Name -> [Name]
forall a. Set a -> [a]
S.toList (Int -> Set Name -> PTerm -> Set Name
ni Int
0 Set Name
forall a. Set a
S.empty PTerm
tm)
  where -- TODO THINK Added niTacImp, but is it right?
    ni :: Int -> S.Set Name -> PTerm -> S.Set Name
    ni :: Int -> Set Name -> PTerm -> Set Name
ni Int
0 Set Name
set (PApp FC
_ PTerm
f [PArg]
as)              = Int -> Set Name -> [PTerm] -> Set Name
niTms Int
0 (Int -> Set Name -> PTerm -> Set Name
ni Int
0 Set Name
set PTerm
f) ((PArg -> PTerm) -> [PArg] -> [PTerm]
forall a b. (a -> b) -> [a] -> [b]
map PArg -> PTerm
forall t. PArg' t -> t
getTm [PArg]
as)
    ni Int
0 Set Name
set (PAppBind FC
_ PTerm
f [PArg]
as)          = Int -> Set Name -> [PTerm] -> Set Name
niTms Int
0 (Int -> Set Name -> PTerm -> Set Name
ni Int
0 Set Name
set PTerm
f) ((PArg -> PTerm) -> [PArg] -> [PTerm]
forall a b. (a -> b) -> [a] -> [b]
map PArg -> PTerm
forall t. PArg' t -> t
getTm [PArg]
as)
    ni Int
0 Set Name
set (PCase FC
_ PTerm
c [(PTerm, PTerm)]
os)             = Int -> Set Name -> [PTerm] -> Set Name
niTms Int
0 (Int -> Set Name -> PTerm -> Set Name
ni Int
0 Set Name
set PTerm
c) (((PTerm, PTerm) -> PTerm) -> [(PTerm, PTerm)] -> [PTerm]
forall a b. (a -> b) -> [a] -> [b]
map (PTerm, PTerm) -> PTerm
forall a b. (a, b) -> b
snd [(PTerm, PTerm)]
os)
    ni Int
0 Set Name
set (PIfThenElse FC
_ PTerm
c PTerm
t PTerm
f)      = Int -> Set Name -> [PTerm] -> Set Name
niTms Int
0 Set Name
set [PTerm
c, PTerm
t, PTerm
f]
    ni Int
0 Set Name
set (PLam FC
fc Name
n FC
_ PTerm
ty PTerm
sc)        = Name -> Set Name -> Set Name
forall a. Ord a => a -> Set a -> Set a
S.insert Name
n (Set Name -> Set Name) -> Set Name -> Set Name
forall a b. (a -> b) -> a -> b
$ Int -> Set Name -> PTerm -> Set Name
ni Int
0 (Int -> Set Name -> PTerm -> Set Name
ni Int
0 Set Name
set PTerm
ty) PTerm
sc
    ni Int
0 Set Name
set (PLet FC
fc RigCount
rc Name
n FC
nfc PTerm
ty PTerm
val PTerm
sc) = Name -> Set Name -> Set Name
forall a. Ord a => a -> Set a -> Set a
S.insert Name
n (Set Name -> Set Name) -> Set Name -> Set Name
forall a b. (a -> b) -> a -> b
$ Int -> Set Name -> PTerm -> Set Name
ni Int
0 (Int -> Set Name -> PTerm -> Set Name
ni Int
0 (Int -> Set Name -> PTerm -> Set Name
ni Int
0 Set Name
set PTerm
ty) PTerm
val) PTerm
sc
    ni Int
0 Set Name
set (PPi Plicity
p Name
n FC
_ PTerm
ty PTerm
sc)          = Int -> Set Name -> Plicity -> Set Name
niTacImp Int
0 (Name -> Set Name -> Set Name
forall a. Ord a => a -> Set a -> Set a
S.insert Name
n (Set Name -> Set Name) -> Set Name -> Set Name
forall a b. (a -> b) -> a -> b
$ Int -> Set Name -> PTerm -> Set Name
ni Int
0 (Int -> Set Name -> PTerm -> Set Name
ni Int
0 Set Name
set PTerm
ty) PTerm
sc) Plicity
p
    ni Int
0 Set Name
set (PRewrite FC
_ Maybe Name
_ PTerm
l PTerm
r Maybe PTerm
_)       = Int -> Set Name -> PTerm -> Set Name
ni Int
0 (Int -> Set Name -> PTerm -> Set Name
ni Int
0 Set Name
set PTerm
l) PTerm
r
    ni Int
0 Set Name
set (PTyped PTerm
l PTerm
r)               = Int -> Set Name -> PTerm -> Set Name
ni Int
0 (Int -> Set Name -> PTerm -> Set Name
ni Int
0 Set Name
set PTerm
l) PTerm
r
    ni Int
0 Set Name
set (PPair FC
_ [FC]
_ PunInfo
_ PTerm
l PTerm
r)          = Int -> Set Name -> PTerm -> Set Name
ni Int
0 (Int -> Set Name -> PTerm -> Set Name
ni Int
0 Set Name
set PTerm
l) PTerm
r
    ni Int
0 Set Name
set (PDPair FC
_ [FC]
_ PunInfo
_ (PRef FC
_ [FC]
_ Name
n) PTerm
t PTerm
r) = Int -> Set Name -> PTerm -> Set Name
ni Int
0 (Int -> Set Name -> PTerm -> Set Name
ni Int
0 Set Name
set PTerm
t) PTerm
r
    ni Int
0 Set Name
set (PDPair FC
_ [FC]
_ PunInfo
_ PTerm
l PTerm
t PTerm
r)       = Int -> Set Name -> PTerm -> Set Name
ni Int
0 (Int -> Set Name -> PTerm -> Set Name
ni Int
0 (Int -> Set Name -> PTerm -> Set Name
ni Int
0 Set Name
set PTerm
l) PTerm
t) PTerm
r
    ni Int
0 Set Name
set (PAlternative [(Name, Name)]
ns PAltType
a [PTerm]
as)     = Int -> Set Name -> [PTerm] -> Set Name
niTms Int
0 Set Name
set [PTerm]
as
    ni Int
0 Set Name
set (PHidden PTerm
tm)               = Int -> Set Name -> PTerm -> Set Name
ni Int
0 Set Name
set PTerm
tm
    ni Int
0 Set Name
set (PUnifyLog PTerm
tm)             = Int -> Set Name -> PTerm -> Set Name
ni Int
0 Set Name
set PTerm
tm
    ni Int
0 Set Name
set (PDisamb [[Text]]
_ PTerm
tm)             = Int -> Set Name -> PTerm -> Set Name
ni Int
0 Set Name
set PTerm
tm
    ni Int
0 Set Name
set (PNoImplicits PTerm
tm)          = Int -> Set Name -> PTerm -> Set Name
ni Int
0 Set Name
set PTerm
tm

    ni Int
i Set Name
set (PQuasiquote PTerm
tm Maybe PTerm
ty)        = Int -> Set Name -> PTerm -> Set Name
ni (Int
i Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
1) Set Name
set PTerm
tm Set Name -> Set Name -> Set Name
forall a. Ord a => Set a -> Set a -> Set a
`S.union` Set Name -> (PTerm -> Set Name) -> Maybe PTerm -> Set Name
forall b a. b -> (a -> b) -> Maybe a -> b
maybe Set Name
forall a. Set a
S.empty (Int -> Set Name -> PTerm -> Set Name
ni Int
i Set Name
set) Maybe PTerm
ty
    ni Int
i Set Name
set (PUnquote PTerm
tm)              = Int -> Set Name -> PTerm -> Set Name
ni (Int
i Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
1) Set Name
set PTerm
tm

    ni Int
i Set Name
set PTerm
tm                         = (PTerm -> Set Name -> Set Name) -> Set Name -> [PTerm] -> Set Name
forall a b. (a -> b -> b) -> b -> [a] -> b
forall (t :: * -> *) a b.
Foldable t =>
(a -> b -> b) -> b -> t a -> b
foldr (Set Name -> Set Name -> Set Name
forall a. Ord a => Set a -> Set a -> Set a
S.union (Set Name -> Set Name -> Set Name)
-> (PTerm -> Set Name) -> PTerm -> Set Name -> Set Name
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int -> Set Name -> PTerm -> Set Name
ni Int
i Set Name
set) Set Name
set (PTerm -> [PTerm]
forall on. Uniplate on => on -> [on]
children PTerm
tm)

    niTms :: Int -> S.Set Name -> [PTerm] -> S.Set Name
    niTms :: Int -> Set Name -> [PTerm] -> Set Name
niTms Int
i Set Name
set []        = Set Name
set
    niTms Int
i Set Name
set (PTerm
x : [PTerm]
xs)  = Int -> Set Name -> [PTerm] -> Set Name
niTms Int
i (Int -> Set Name -> PTerm -> Set Name
ni Int
i Set Name
set PTerm
x) [PTerm]
xs

    niTacImp :: Int -> Set Name -> Plicity -> Set Name
niTacImp Int
i Set Name
set (TacImp [ArgOpt]
_ Static
_ PTerm
scr RigCount
_) = Int -> Set Name -> PTerm -> Set Name
ni Int
i Set Name
set PTerm
scr
    niTacImp Int
i Set Name
set Plicity
_                = Set Name
set

-- Return names which are valid implicits in the given term (type).
implicitNamesIn :: [Name] -> IState -> PTerm -> [Name]
implicitNamesIn :: [Name] -> IState -> PTerm -> [Name]
implicitNamesIn [Name]
uvars IState
ist PTerm
tm
      = let ([Name]
imps, [Name]
fns) = State ([Name], [Name]) () -> ([Name], [Name]) -> ([Name], [Name])
forall s a. State s a -> s -> s
execState (Integer -> [Name] -> PTerm -> State ([Name], [Name]) ()
forall {t} {m :: * -> *}.
(Eq t, Num t, Monad m) =>
t -> [Name] -> PTerm -> StateT ([Name], [Name]) m ()
ni Integer
0 [] PTerm
tm) ([], []) in
            [Name] -> [Name]
forall a. Eq a => [a] -> [a]
nub [Name]
imps [Name] -> [Name] -> [Name]
forall a. Eq a => [a] -> [a] -> [a]
\\ [Name] -> [Name]
forall a. Eq a => [a] -> [a]
nub [Name]
fns
  where
    addImp :: a -> StateT ([a], b) m ()
addImp a
n = do ([a]
imps, b
fns) <- StateT ([a], b) m ([a], b)
forall (m :: * -> *) s. Monad m => StateT s m s
get
                  ([a], b) -> StateT ([a], b) m ()
forall (m :: * -> *) s. Monad m => s -> StateT s m ()
put (a
n a -> [a] -> [a]
forall a. a -> [a] -> [a]
: [a]
imps, b
fns)
    addFn :: a -> StateT (a, [a]) m ()
addFn a
n = do (a
imps, [a]
fns) <- StateT (a, [a]) m (a, [a])
forall (m :: * -> *) s. Monad m => StateT s m s
get
                 (a, [a]) -> StateT (a, [a]) m ()
forall (m :: * -> *) s. Monad m => s -> StateT s m ()
put (a
imps, a
na -> [a] -> [a]
forall a. a -> [a] -> [a]
: [a]
fns)

    ni :: t -> [Name] -> PTerm -> StateT ([Name], [Name]) m ()
ni t
0 [Name]
env (PRef FC
_ [FC]
_ n :: Name
n@(NS Name
_ [Text]
_))
        | Bool -> Bool
not (Name
n Name -> [Name] -> Bool
forall a. Eq a => a -> [a] -> Bool
forall (t :: * -> *) a. (Foldable t, Eq a) => a -> t a -> Bool
`elem` [Name]
env)
          -- Never implicitly bind if there's a namespace
            = Name -> StateT ([Name], [Name]) m ()
forall {m :: * -> *} {a} {a}. Monad m => a -> StateT (a, [a]) m ()
addFn Name
n
    ni t
0 [Name]
env (PRef FC
_ [FC]
_ Name
n)
        | Bool -> Bool
not (Name
n Name -> [Name] -> Bool
forall a. Eq a => a -> [a] -> Bool
forall (t :: * -> *) a. (Foldable t, Eq a) => a -> t a -> Bool
`elem` [Name]
env) Bool -> Bool -> Bool
&& Name -> Bool
implicitable Name
n Bool -> Bool -> Bool
|| Name
n Name -> [Name] -> Bool
forall a. Eq a => a -> [a] -> Bool
forall (t :: * -> *) a. (Foldable t, Eq a) => a -> t a -> Bool
`elem` [Name]
uvars = Name -> StateT ([Name], [Name]) m ()
forall {m :: * -> *} {a} {b}. Monad m => a -> StateT ([a], b) m ()
addImp Name
n
    ni t
0 [Name]
env (PApp FC
_ f :: PTerm
f@(PRef FC
_ [FC]
_ Name
n) [PArg]
as)
        | Name
n Name -> [Name] -> Bool
forall a. Eq a => a -> [a] -> Bool
forall (t :: * -> *) a. (Foldable t, Eq a) => a -> t a -> Bool
`elem` [Name]
uvars = do t -> [Name] -> PTerm -> StateT ([Name], [Name]) m ()
ni t
0 [Name]
env PTerm
f
                              (PArg -> StateT ([Name], [Name]) m ())
-> [PArg] -> StateT ([Name], [Name]) m ()
forall (t :: * -> *) (m :: * -> *) a b.
(Foldable t, Monad m) =>
(a -> m b) -> t a -> m ()
mapM_ (t -> [Name] -> PTerm -> StateT ([Name], [Name]) m ()
ni t
0 [Name]
env (PTerm -> StateT ([Name], [Name]) m ())
-> (PArg -> PTerm) -> PArg -> StateT ([Name], [Name]) m ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. PArg -> PTerm
forall t. PArg' t -> t
getTm) [PArg]
as
        | Bool
otherwise = do case Name -> Context -> [Term]
lookupTy Name
n (IState -> Context
tt_ctxt IState
ist) of
                              []  -> () -> StateT ([Name], [Name]) m ()
forall a. a -> StateT ([Name], [Name]) m a
forall (m :: * -> *) a. Monad m => a -> m a
return ()
                              [Term]
_   -> Name -> StateT ([Name], [Name]) m ()
forall {m :: * -> *} {a} {a}. Monad m => a -> StateT (a, [a]) m ()
addFn Name
n
                         (PArg -> StateT ([Name], [Name]) m ())
-> [PArg] -> StateT ([Name], [Name]) m ()
forall (t :: * -> *) (m :: * -> *) a b.
(Foldable t, Monad m) =>
(a -> m b) -> t a -> m ()
mapM_ (t -> [Name] -> PTerm -> StateT ([Name], [Name]) m ()
ni t
0 [Name]
env (PTerm -> StateT ([Name], [Name]) m ())
-> (PArg -> PTerm) -> PArg -> StateT ([Name], [Name]) m ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. PArg -> PTerm
forall t. PArg' t -> t
getTm) [PArg]
as
    ni t
0 [Name]
env (PApp FC
_ PTerm
f [PArg]
as) = do t -> [Name] -> PTerm -> StateT ([Name], [Name]) m ()
ni t
0 [Name]
env PTerm
f
                                (PArg -> StateT ([Name], [Name]) m ())
-> [PArg] -> StateT ([Name], [Name]) m ()
forall (t :: * -> *) (m :: * -> *) a b.
(Foldable t, Monad m) =>
(a -> m b) -> t a -> m ()
mapM_ (t -> [Name] -> PTerm -> StateT ([Name], [Name]) m ()
ni t
0 [Name]
env (PTerm -> StateT ([Name], [Name]) m ())
-> (PArg -> PTerm) -> PArg -> StateT ([Name], [Name]) m ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. PArg -> PTerm
forall t. PArg' t -> t
getTm) [PArg]
as
    ni t
0 [Name]
env (PAppBind FC
_ PTerm
f [PArg]
as) = do t -> [Name] -> PTerm -> StateT ([Name], [Name]) m ()
ni t
0 [Name]
env PTerm
f
                                    (PArg -> StateT ([Name], [Name]) m ())
-> [PArg] -> StateT ([Name], [Name]) m ()
forall (t :: * -> *) (m :: * -> *) a b.
(Foldable t, Monad m) =>
(a -> m b) -> t a -> m ()
mapM_ (t -> [Name] -> PTerm -> StateT ([Name], [Name]) m ()
ni t
0 [Name]
env (PTerm -> StateT ([Name], [Name]) m ())
-> (PArg -> PTerm) -> PArg -> StateT ([Name], [Name]) m ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. PArg -> PTerm
forall t. PArg' t -> t
getTm) [PArg]
as
    ni t
0 [Name]
env (PCase FC
_ PTerm
c [(PTerm, PTerm)]
os)  = do t -> [Name] -> PTerm -> StateT ([Name], [Name]) m ()
ni t
0 [Name]
env PTerm
c
    -- names in 'os', not counting the names bound in the cases
                                  ((PTerm, PTerm) -> StateT ([Name], [Name]) m ())
-> [(PTerm, PTerm)] -> StateT ([Name], [Name]) m ()
forall (t :: * -> *) (m :: * -> *) a b.
(Foldable t, Monad m) =>
(a -> m b) -> t a -> m ()
mapM_ (t -> [Name] -> PTerm -> StateT ([Name], [Name]) m ()
ni t
0 [Name]
env (PTerm -> StateT ([Name], [Name]) m ())
-> ((PTerm, PTerm) -> PTerm)
-> (PTerm, PTerm)
-> StateT ([Name], [Name]) m ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (PTerm, PTerm) -> PTerm
forall a b. (a, b) -> b
snd) [(PTerm, PTerm)]
os
                                  ([Name]
imps, [Name]
fns) <- StateT ([Name], [Name]) m ([Name], [Name])
forall (m :: * -> *) s. Monad m => StateT s m s
get
                                  ([Name], [Name]) -> StateT ([Name], [Name]) m ()
forall (m :: * -> *) s. Monad m => s -> StateT s m ()
put ([] ,[])
                                  ((PTerm, PTerm) -> StateT ([Name], [Name]) m ())
-> [(PTerm, PTerm)] -> StateT ([Name], [Name]) m ()
forall (t :: * -> *) (m :: * -> *) a b.
(Foldable t, Monad m) =>
(a -> m b) -> t a -> m ()
mapM_ (t -> [Name] -> PTerm -> StateT ([Name], [Name]) m ()
ni t
0 [Name]
env (PTerm -> StateT ([Name], [Name]) m ())
-> ((PTerm, PTerm) -> PTerm)
-> (PTerm, PTerm)
-> StateT ([Name], [Name]) m ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (PTerm, PTerm) -> PTerm
forall a b. (a, b) -> a
fst) [(PTerm, PTerm)]
os
                                  ([Name]
impsfst, [Name]
_) <- StateT ([Name], [Name]) m ([Name], [Name])
forall (m :: * -> *) s. Monad m => StateT s m s
get
                                  ([Name], [Name]) -> StateT ([Name], [Name]) m ()
forall (m :: * -> *) s. Monad m => s -> StateT s m ()
put ([Name] -> [Name]
forall a. Eq a => [a] -> [a]
nub [Name]
imps [Name] -> [Name] -> [Name]
forall a. Eq a => [a] -> [a] -> [a]
\\ [Name] -> [Name]
forall a. Eq a => [a] -> [a]
nub [Name]
impsfst, [Name]
fns)
    ni t
0 [Name]
env (PIfThenElse FC
_ PTerm
c PTerm
t PTerm
f)            = (PTerm -> StateT ([Name], [Name]) m ())
-> [PTerm] -> StateT ([Name], [Name]) m ()
forall (t :: * -> *) (m :: * -> *) a b.
(Foldable t, Monad m) =>
(a -> m b) -> t a -> m ()
mapM_ (t -> [Name] -> PTerm -> StateT ([Name], [Name]) m ()
ni t
0 [Name]
env) [PTerm
c, PTerm
t, PTerm
f]
    ni t
0 [Name]
env (PLam FC
fc Name
n FC
_ PTerm
ty PTerm
sc)              = do t -> [Name] -> PTerm -> StateT ([Name], [Name]) m ()
ni t
0 [Name]
env PTerm
ty; t -> [Name] -> PTerm -> StateT ([Name], [Name]) m ()
ni t
0 (Name
nName -> [Name] -> [Name]
forall a. a -> [a] -> [a]
:[Name]
env) PTerm
sc
    ni t
0 [Name]
env (PPi Plicity
p Name
n FC
_ PTerm
ty PTerm
sc)                = do t -> [Name] -> PTerm -> StateT ([Name], [Name]) m ()
ni t
0 [Name]
env PTerm
ty; t -> [Name] -> PTerm -> StateT ([Name], [Name]) m ()
ni t
0 (Name
nName -> [Name] -> [Name]
forall a. a -> [a] -> [a]
:[Name]
env) PTerm
sc
    ni t
0 [Name]
env (PLet FC
fc RigCount
rc Name
n FC
_ PTerm
ty PTerm
val PTerm
sc)       = do t -> [Name] -> PTerm -> StateT ([Name], [Name]) m ()
ni t
0 [Name]
env PTerm
ty;
                                                   t -> [Name] -> PTerm -> StateT ([Name], [Name]) m ()
ni t
0 [Name]
env PTerm
val; t -> [Name] -> PTerm -> StateT ([Name], [Name]) m ()
ni t
0 (Name
nName -> [Name] -> [Name]
forall a. a -> [a] -> [a]
:[Name]
env) PTerm
sc
    ni t
0 [Name]
env (PRewrite FC
_ Maybe Name
_ PTerm
l PTerm
r Maybe PTerm
_)             = do t -> [Name] -> PTerm -> StateT ([Name], [Name]) m ()
ni t
0 [Name]
env PTerm
l; t -> [Name] -> PTerm -> StateT ([Name], [Name]) m ()
ni t
0 [Name]
env PTerm
r
    ni t
0 [Name]
env (PTyped PTerm
l PTerm
r)                     = do t -> [Name] -> PTerm -> StateT ([Name], [Name]) m ()
ni t
0 [Name]
env PTerm
l; t -> [Name] -> PTerm -> StateT ([Name], [Name]) m ()
ni t
0 [Name]
env PTerm
r
    ni t
0 [Name]
env (PPair FC
_ [FC]
_ PunInfo
_ PTerm
l PTerm
r)                = do t -> [Name] -> PTerm -> StateT ([Name], [Name]) m ()
ni t
0 [Name]
env PTerm
l; t -> [Name] -> PTerm -> StateT ([Name], [Name]) m ()
ni t
0 [Name]
env PTerm
r
    ni t
0 [Name]
env (PDPair FC
_ [FC]
_ PunInfo
_ (PRef FC
_ [FC]
_ Name
n) PTerm
t PTerm
r)  = do t -> [Name] -> PTerm -> StateT ([Name], [Name]) m ()
ni t
0 [Name]
env PTerm
t; t -> [Name] -> PTerm -> StateT ([Name], [Name]) m ()
ni t
0 (Name
nName -> [Name] -> [Name]
forall a. a -> [a] -> [a]
:[Name]
env) PTerm
r
    ni t
0 [Name]
env (PDPair FC
_ [FC]
_ PunInfo
_ PTerm
l PTerm
t PTerm
r)             = do t -> [Name] -> PTerm -> StateT ([Name], [Name]) m ()
ni t
0 [Name]
env PTerm
l
                                                   t -> [Name] -> PTerm -> StateT ([Name], [Name]) m ()
ni t
0 [Name]
env PTerm
t
                                                   t -> [Name] -> PTerm -> StateT ([Name], [Name]) m ()
ni t
0 [Name]
env PTerm
r
    ni t
0 [Name]
env (PAlternative [(Name, Name)]
ns PAltType
a [PTerm]
as)           = (PTerm -> StateT ([Name], [Name]) m ())
-> [PTerm] -> StateT ([Name], [Name]) m ()
forall (t :: * -> *) (m :: * -> *) a b.
(Foldable t, Monad m) =>
(a -> m b) -> t a -> m ()
mapM_ (t -> [Name] -> PTerm -> StateT ([Name], [Name]) m ()
ni t
0 [Name]
env) [PTerm]
as
    ni t
0 [Name]
env (PHidden PTerm
tm)                     = t -> [Name] -> PTerm -> StateT ([Name], [Name]) m ()
ni t
0 [Name]
env PTerm
tm
    ni t
0 [Name]
env (PUnifyLog PTerm
tm)                   = t -> [Name] -> PTerm -> StateT ([Name], [Name]) m ()
ni t
0 [Name]
env PTerm
tm
    ni t
0 [Name]
env (PDisamb [[Text]]
_ PTerm
tm)                   = t -> [Name] -> PTerm -> StateT ([Name], [Name]) m ()
ni t
0 [Name]
env PTerm
tm
    ni t
0 [Name]
env (PNoImplicits PTerm
tm)                = t -> [Name] -> PTerm -> StateT ([Name], [Name]) m ()
ni t
0 [Name]
env PTerm
tm

    ni t
i [Name]
env (PQuasiquote PTerm
tm Maybe PTerm
ty) = do t -> [Name] -> PTerm -> StateT ([Name], [Name]) m ()
ni (t
i t -> t -> t
forall a. Num a => a -> a -> a
+ t
1) [Name]
env PTerm
tm
                                      StateT ([Name], [Name]) m ()
-> (PTerm -> StateT ([Name], [Name]) m ())
-> Maybe PTerm
-> StateT ([Name], [Name]) m ()
forall b a. b -> (a -> b) -> Maybe a -> b
maybe (() -> StateT ([Name], [Name]) m ()
forall a. a -> StateT ([Name], [Name]) m a
forall (m :: * -> *) a. Monad m => a -> m a
return ()) (t -> [Name] -> PTerm -> StateT ([Name], [Name]) m ()
ni t
i [Name]
env) Maybe PTerm
ty
    ni t
i [Name]
env (PUnquote PTerm
tm) = t -> [Name] -> PTerm -> StateT ([Name], [Name]) m ()
ni (t
i t -> t -> t
forall a. Num a => a -> a -> a
- t
1) [Name]
env PTerm
tm

    ni t
i [Name]
env PTerm
tm = (PTerm -> StateT ([Name], [Name]) m ())
-> [PTerm] -> StateT ([Name], [Name]) m ()
forall (t :: * -> *) (m :: * -> *) a b.
(Foldable t, Monad m) =>
(a -> m b) -> t a -> m ()
mapM_ (t -> [Name] -> PTerm -> StateT ([Name], [Name]) m ()
ni t
i [Name]
env) (PTerm -> [PTerm]
forall on. Uniplate on => on -> [on]
children PTerm
tm)

-- Return names which are free in the given term.
namesIn :: [(Name, PTerm)] -> IState -> PTerm -> [Name]
namesIn :: [(Name, PTerm)] -> IState -> PTerm -> [Name]
namesIn [(Name, PTerm)]
uvars IState
ist PTerm
tm = [Name] -> [Name]
forall a. Eq a => [a] -> [a]
nub ([Name] -> [Name]) -> [Name] -> [Name]
forall a b. (a -> b) -> a -> b
$ Integer -> [Name] -> PTerm -> [Name]
forall {t}. (Eq t, Num t) => t -> [Name] -> PTerm -> [Name]
ni Integer
0 [] PTerm
tm
  where
    ni :: t -> [Name] -> PTerm -> [Name]
ni t
0 [Name]
env (PRef FC
_ [FC]
_ Name
n)
        | Bool -> Bool
not (Name
n Name -> [Name] -> Bool
forall a. Eq a => a -> [a] -> Bool
forall (t :: * -> *) a. (Foldable t, Eq a) => a -> t a -> Bool
`elem` [Name]
env)
            = case Name -> Context -> [Term]
lookupTy Name
n (IState -> Context
tt_ctxt IState
ist) of
                []  -> [Name
n]
                [Term]
_   -> [Name
n | Name
n Name -> [Name] -> Bool
forall a. Eq a => a -> [a] -> Bool
forall (t :: * -> *) a. (Foldable t, Eq a) => a -> t a -> Bool
`elem` (((Name, PTerm) -> Name) -> [(Name, PTerm)] -> [Name]
forall a b. (a -> b) -> [a] -> [b]
map (Name, PTerm) -> Name
forall a b. (a, b) -> a
fst [(Name, PTerm)]
uvars)]
    ni t
0 [Name]
env (PApp FC
_ PTerm
f [PArg]
as)      = t -> [Name] -> PTerm -> [Name]
ni t
0 [Name]
env PTerm
f [Name] -> [Name] -> [Name]
forall a. [a] -> [a] -> [a]
++ (PArg -> [Name]) -> [PArg] -> [Name]
forall (t :: * -> *) a b. Foldable t => (a -> [b]) -> t a -> [b]
concatMap (t -> [Name] -> PTerm -> [Name]
ni t
0 [Name]
env (PTerm -> [Name]) -> (PArg -> PTerm) -> PArg -> [Name]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. PArg -> PTerm
forall t. PArg' t -> t
getTm) [PArg]
as
    ni t
0 [Name]
env (PAppBind FC
_ PTerm
f [PArg]
as)  = t -> [Name] -> PTerm -> [Name]
ni t
0 [Name]
env PTerm
f [Name] -> [Name] -> [Name]
forall a. [a] -> [a] -> [a]
++ (PArg -> [Name]) -> [PArg] -> [Name]
forall (t :: * -> *) a b. Foldable t => (a -> [b]) -> t a -> [b]
concatMap (t -> [Name] -> PTerm -> [Name]
ni t
0 [Name]
env (PTerm -> [Name]) -> (PArg -> PTerm) -> PArg -> [Name]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. PArg -> PTerm
forall t. PArg' t -> t
getTm) [PArg]
as
    ni t
0 [Name]
env (PCase FC
_ PTerm
c [(PTerm, PTerm)]
os)     = t -> [Name] -> PTerm -> [Name]
ni t
0 [Name]
env PTerm
c [Name] -> [Name] -> [Name]
forall a. [a] -> [a] -> [a]
++
    -- names in 'os', not counting the names bound in the cases
                                ([Name] -> [Name]
forall a. Eq a => [a] -> [a]
nub (((PTerm, PTerm) -> [Name]) -> [(PTerm, PTerm)] -> [Name]
forall (t :: * -> *) a b. Foldable t => (a -> [b]) -> t a -> [b]
concatMap (t -> [Name] -> PTerm -> [Name]
ni t
0 [Name]
env (PTerm -> [Name])
-> ((PTerm, PTerm) -> PTerm) -> (PTerm, PTerm) -> [Name]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (PTerm, PTerm) -> PTerm
forall a b. (a, b) -> b
snd) [(PTerm, PTerm)]
os)
                                     [Name] -> [Name] -> [Name]
forall a. Eq a => [a] -> [a] -> [a]
\\ [Name] -> [Name]
forall a. Eq a => [a] -> [a]
nub (((PTerm, PTerm) -> [Name]) -> [(PTerm, PTerm)] -> [Name]
forall (t :: * -> *) a b. Foldable t => (a -> [b]) -> t a -> [b]
concatMap (t -> [Name] -> PTerm -> [Name]
ni t
0 [Name]
env (PTerm -> [Name])
-> ((PTerm, PTerm) -> PTerm) -> (PTerm, PTerm) -> [Name]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (PTerm, PTerm) -> PTerm
forall a b. (a, b) -> a
fst) [(PTerm, PTerm)]
os))
    ni t
0 [Name]
env (PIfThenElse FC
_ PTerm
c PTerm
t PTerm
f)  = (PTerm -> [Name]) -> [PTerm] -> [Name]
forall (t :: * -> *) a b. Foldable t => (a -> [b]) -> t a -> [b]
concatMap (t -> [Name] -> PTerm -> [Name]
ni t
0 [Name]
env) [PTerm
c, PTerm
t, PTerm
f]
    ni t
0 [Name]
env (PLam FC
fc Name
n FC
nfc PTerm
ty PTerm
sc)  = t -> [Name] -> PTerm -> [Name]
ni t
0 [Name]
env PTerm
ty [Name] -> [Name] -> [Name]
forall a. [a] -> [a] -> [a]
++ t -> [Name] -> PTerm -> [Name]
ni t
0 (Name
nName -> [Name] -> [Name]
forall a. a -> [a] -> [a]
:[Name]
env) PTerm
sc
    ni t
0 [Name]
env (PPi Plicity
p Name
n FC
_ PTerm
ty PTerm
sc)      = t -> [Name] -> Plicity -> [Name]
niTacImp t
0 [Name]
env Plicity
p [Name] -> [Name] -> [Name]
forall a. [a] -> [a] -> [a]
++ t -> [Name] -> PTerm -> [Name]
ni t
0 [Name]
env PTerm
ty [Name] -> [Name] -> [Name]
forall a. [a] -> [a] -> [a]
++ t -> [Name] -> PTerm -> [Name]
ni t
0 (Name
nName -> [Name] -> [Name]
forall a. a -> [a] -> [a]
:[Name]
env) PTerm
sc
    ni t
0 [Name]
env (PRewrite FC
_ Maybe Name
_ PTerm
l PTerm
r Maybe PTerm
_)   = t -> [Name] -> PTerm -> [Name]
ni t
0 [Name]
env PTerm
l [Name] -> [Name] -> [Name]
forall a. [a] -> [a] -> [a]
++ t -> [Name] -> PTerm -> [Name]
ni t
0 [Name]
env PTerm
r
    ni t
0 [Name]
env (PTyped PTerm
l PTerm
r)           = t -> [Name] -> PTerm -> [Name]
ni t
0 [Name]
env PTerm
l [Name] -> [Name] -> [Name]
forall a. [a] -> [a] -> [a]
++ t -> [Name] -> PTerm -> [Name]
ni t
0 [Name]
env PTerm
r
    ni t
0 [Name]
env (PPair FC
_ [FC]
_ PunInfo
_ PTerm
l PTerm
r)      = t -> [Name] -> PTerm -> [Name]
ni t
0 [Name]
env PTerm
l [Name] -> [Name] -> [Name]
forall a. [a] -> [a] -> [a]
++ t -> [Name] -> PTerm -> [Name]
ni t
0 [Name]
env PTerm
r
    ni t
0 [Name]
env (PDPair FC
_ [FC]
_ PunInfo
_ (PRef FC
_ [FC]
_ Name
n) PTerm
t PTerm
r) = t -> [Name] -> PTerm -> [Name]
ni t
0 [Name]
env PTerm
t [Name] -> [Name] -> [Name]
forall a. [a] -> [a] -> [a]
++ t -> [Name] -> PTerm -> [Name]
ni t
0 (Name
nName -> [Name] -> [Name]
forall a. a -> [a] -> [a]
:[Name]
env) PTerm
r
    ni t
0 [Name]
env (PDPair FC
_ [FC]
_ PunInfo
_ PTerm
l PTerm
t PTerm
r)   = t -> [Name] -> PTerm -> [Name]
ni t
0 [Name]
env PTerm
l [Name] -> [Name] -> [Name]
forall a. [a] -> [a] -> [a]
++ t -> [Name] -> PTerm -> [Name]
ni t
0 [Name]
env PTerm
t [Name] -> [Name] -> [Name]
forall a. [a] -> [a] -> [a]
++ t -> [Name] -> PTerm -> [Name]
ni t
0 [Name]
env PTerm
r
    ni t
0 [Name]
env (PAlternative [(Name, Name)]
ns PAltType
a [PTerm]
as) = (PTerm -> [Name]) -> [PTerm] -> [Name]
forall (t :: * -> *) a b. Foldable t => (a -> [b]) -> t a -> [b]
concatMap (t -> [Name] -> PTerm -> [Name]
ni t
0 [Name]
env) [PTerm]
as
    ni t
0 [Name]
env (PHidden PTerm
tm)           = t -> [Name] -> PTerm -> [Name]
ni t
0 [Name]
env PTerm
tm
    ni t
0 [Name]
env (PUnifyLog PTerm
tm)         = t -> [Name] -> PTerm -> [Name]
ni t
0 [Name]
env PTerm
tm
    ni t
0 [Name]
env (PDisamb [[Text]]
_ PTerm
tm)         = t -> [Name] -> PTerm -> [Name]
ni t
0 [Name]
env PTerm
tm
    ni t
0 [Name]
env (PNoImplicits PTerm
tm)      = t -> [Name] -> PTerm -> [Name]
ni t
0 [Name]
env PTerm
tm

    ni t
i [Name]
env (PQuasiquote PTerm
tm Maybe PTerm
ty)    = t -> [Name] -> PTerm -> [Name]
ni (t
i t -> t -> t
forall a. Num a => a -> a -> a
+ t
1) [Name]
env PTerm
tm [Name] -> [Name] -> [Name]
forall a. [a] -> [a] -> [a]
++ [Name] -> (PTerm -> [Name]) -> Maybe PTerm -> [Name]
forall b a. b -> (a -> b) -> Maybe a -> b
maybe [] (t -> [Name] -> PTerm -> [Name]
ni t
i [Name]
env) Maybe PTerm
ty
    ni t
i [Name]
env (PUnquote PTerm
tm)          = t -> [Name] -> PTerm -> [Name]
ni (t
i t -> t -> t
forall a. Num a => a -> a -> a
- t
1) [Name]
env PTerm
tm

    ni t
i [Name]
env PTerm
tm                     = (PTerm -> [Name]) -> [PTerm] -> [Name]
forall (t :: * -> *) a b. Foldable t => (a -> [b]) -> t a -> [b]
concatMap (t -> [Name] -> PTerm -> [Name]
ni t
i [Name]
env) (PTerm -> [PTerm]
forall on. Uniplate on => on -> [on]
children PTerm
tm)

    niTacImp :: t -> [Name] -> Plicity -> [Name]
niTacImp t
i [Name]
env (TacImp [ArgOpt]
_ Static
_ PTerm
scr RigCount
_) = t -> [Name] -> PTerm -> [Name]
ni t
i [Name]
env PTerm
scr
    niTacImp t
_ [Name]
_ Plicity
_                  = []

-- Return which of the given names are used in the given term.

usedNamesIn :: [Name] -> IState -> PTerm -> [Name]
usedNamesIn :: [Name] -> IState -> PTerm -> [Name]
usedNamesIn [Name]
vars IState
ist PTerm
tm = [Name] -> [Name]
forall a. Eq a => [a] -> [a]
nub ([Name] -> [Name]) -> [Name] -> [Name]
forall a b. (a -> b) -> a -> b
$ Integer -> [Name] -> PTerm -> [Name]
forall {t}. (Eq t, Num t) => t -> [Name] -> PTerm -> [Name]
ni Integer
0 [] PTerm
tm
  where -- TODO THINK added niTacImp, but is it right?
    ni :: t -> [Name] -> PTerm -> [Name]
ni t
0 [Name]
env (PRef FC
_ [FC]
_ Name
n)
        | Name
n Name -> [Name] -> Bool
forall a. Eq a => a -> [a] -> Bool
forall (t :: * -> *) a. (Foldable t, Eq a) => a -> t a -> Bool
`elem` [Name]
vars Bool -> Bool -> Bool
&& Bool -> Bool
not (Name
n Name -> [Name] -> Bool
forall a. Eq a => a -> [a] -> Bool
forall (t :: * -> *) a. (Foldable t, Eq a) => a -> t a -> Bool
`elem` [Name]
env)
            = case Name -> Context -> Maybe Def
lookupDefExact Name
n (IState -> Context
tt_ctxt IState
ist) of
                Maybe Def
Nothing -> [Name
n]
                Maybe Def
_ -> []
    ni t
0 [Name]
env (PApp FC
_ PTerm
f [PArg]
as)          = t -> [Name] -> PTerm -> [Name]
ni t
0 [Name]
env PTerm
f [Name] -> [Name] -> [Name]
forall a. [a] -> [a] -> [a]
++ (PArg -> [Name]) -> [PArg] -> [Name]
forall (t :: * -> *) a b. Foldable t => (a -> [b]) -> t a -> [b]
concatMap (t -> [Name] -> PTerm -> [Name]
ni t
0 [Name]
env (PTerm -> [Name]) -> (PArg -> PTerm) -> PArg -> [Name]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. PArg -> PTerm
forall t. PArg' t -> t
getTm) [PArg]
as
    ni t
0 [Name]
env (PAppBind FC
_ PTerm
f [PArg]
as)      = t -> [Name] -> PTerm -> [Name]
ni t
0 [Name]
env PTerm
f [Name] -> [Name] -> [Name]
forall a. [a] -> [a] -> [a]
++ (PArg -> [Name]) -> [PArg] -> [Name]
forall (t :: * -> *) a b. Foldable t => (a -> [b]) -> t a -> [b]
concatMap (t -> [Name] -> PTerm -> [Name]
ni t
0 [Name]
env (PTerm -> [Name]) -> (PArg -> PTerm) -> PArg -> [Name]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. PArg -> PTerm
forall t. PArg' t -> t
getTm) [PArg]
as
    ni t
0 [Name]
env (PCase FC
_ PTerm
c [(PTerm, PTerm)]
os)         = t -> [Name] -> PTerm -> [Name]
ni t
0 [Name]
env PTerm
c [Name] -> [Name] -> [Name]
forall a. [a] -> [a] -> [a]
++ ((PTerm, PTerm) -> [Name]) -> [(PTerm, PTerm)] -> [Name]
forall (t :: * -> *) a b. Foldable t => (a -> [b]) -> t a -> [b]
concatMap (t -> [Name] -> PTerm -> [Name]
ni t
0 [Name]
env (PTerm -> [Name])
-> ((PTerm, PTerm) -> PTerm) -> (PTerm, PTerm) -> [Name]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (PTerm, PTerm) -> PTerm
forall a b. (a, b) -> b
snd) [(PTerm, PTerm)]
os
    ni t
0 [Name]
env (PIfThenElse FC
_ PTerm
c PTerm
t PTerm
f)  = (PTerm -> [Name]) -> [PTerm] -> [Name]
forall (t :: * -> *) a b. Foldable t => (a -> [b]) -> t a -> [b]
concatMap (t -> [Name] -> PTerm -> [Name]
ni t
0 [Name]
env) [PTerm
c, PTerm
t, PTerm
f]
    ni t
0 [Name]
env (PLam FC
fc Name
n FC
_ PTerm
ty PTerm
sc)    = t -> [Name] -> PTerm -> [Name]
ni t
0 [Name]
env PTerm
ty [Name] -> [Name] -> [Name]
forall a. [a] -> [a] -> [a]
++ t -> [Name] -> PTerm -> [Name]
ni t
0 (Name
nName -> [Name] -> [Name]
forall a. a -> [a] -> [a]
:[Name]
env) PTerm
sc
    ni t
0 [Name]
env (PPi Plicity
p Name
n FC
_ PTerm
ty PTerm
sc)      = t -> [Name] -> Plicity -> [Name]
niTacImp t
0 [Name]
env Plicity
p [Name] -> [Name] -> [Name]
forall a. [a] -> [a] -> [a]
++ t -> [Name] -> PTerm -> [Name]
ni t
0 [Name]
env PTerm
ty [Name] -> [Name] -> [Name]
forall a. [a] -> [a] -> [a]
++ t -> [Name] -> PTerm -> [Name]
ni t
0 (Name
nName -> [Name] -> [Name]
forall a. a -> [a] -> [a]
:[Name]
env) PTerm
sc
    ni t
0 [Name]
env (PRewrite FC
_ Maybe Name
_ PTerm
l PTerm
r Maybe PTerm
_)   = t -> [Name] -> PTerm -> [Name]
ni t
0 [Name]
env PTerm
l [Name] -> [Name] -> [Name]
forall a. [a] -> [a] -> [a]
++ t -> [Name] -> PTerm -> [Name]
ni t
0 [Name]
env PTerm
r
    ni t
0 [Name]
env (PTyped PTerm
l PTerm
r)           = t -> [Name] -> PTerm -> [Name]
ni t
0 [Name]
env PTerm
l [Name] -> [Name] -> [Name]
forall a. [a] -> [a] -> [a]
++ t -> [Name] -> PTerm -> [Name]
ni t
0 [Name]
env PTerm
r
    ni t
0 [Name]
env (PPair FC
_ [FC]
_ PunInfo
_ PTerm
l PTerm
r)      = t -> [Name] -> PTerm -> [Name]
ni t
0 [Name]
env PTerm
l [Name] -> [Name] -> [Name]
forall a. [a] -> [a] -> [a]
++ t -> [Name] -> PTerm -> [Name]
ni t
0 [Name]
env PTerm
r
    ni t
0 [Name]
env (PDPair FC
_ [FC]
_ PunInfo
_ (PRef FC
_ [FC]
_ Name
n) PTerm
t PTerm
r) = t -> [Name] -> PTerm -> [Name]
ni t
0 [Name]
env PTerm
t [Name] -> [Name] -> [Name]
forall a. [a] -> [a] -> [a]
++ t -> [Name] -> PTerm -> [Name]
ni t
0 (Name
nName -> [Name] -> [Name]
forall a. a -> [a] -> [a]
:[Name]
env) PTerm
r
    ni t
0 [Name]
env (PDPair FC
_ [FC]
_ PunInfo
_ PTerm
l PTerm
t PTerm
r)   = t -> [Name] -> PTerm -> [Name]
ni t
0 [Name]
env PTerm
l [Name] -> [Name] -> [Name]
forall a. [a] -> [a] -> [a]
++ t -> [Name] -> PTerm -> [Name]
ni t
0 [Name]
env PTerm
t [Name] -> [Name] -> [Name]
forall a. [a] -> [a] -> [a]
++ t -> [Name] -> PTerm -> [Name]
ni t
0 [Name]
env PTerm
r
    ni t
0 [Name]
env (PAlternative [(Name, Name)]
ns PAltType
a [PTerm]
as) = (PTerm -> [Name]) -> [PTerm] -> [Name]
forall (t :: * -> *) a b. Foldable t => (a -> [b]) -> t a -> [b]
concatMap (t -> [Name] -> PTerm -> [Name]
ni t
0 [Name]
env) [PTerm]
as
    ni t
0 [Name]
env (PHidden PTerm
tm)           = t -> [Name] -> PTerm -> [Name]
ni t
0 [Name]
env PTerm
tm
    ni t
0 [Name]
env (PUnifyLog PTerm
tm)         = t -> [Name] -> PTerm -> [Name]
ni t
0 [Name]
env PTerm
tm
    ni t
0 [Name]
env (PDisamb [[Text]]
_ PTerm
tm)         = t -> [Name] -> PTerm -> [Name]
ni t
0 [Name]
env PTerm
tm
    ni t
0 [Name]
env (PNoImplicits PTerm
tm)      = t -> [Name] -> PTerm -> [Name]
ni t
0 [Name]
env PTerm
tm

    ni t
i [Name]
env (PQuasiquote PTerm
tm Maybe PTerm
ty)    = t -> [Name] -> PTerm -> [Name]
ni (t
i t -> t -> t
forall a. Num a => a -> a -> a
+ t
1) [Name]
env PTerm
tm [Name] -> [Name] -> [Name]
forall a. [a] -> [a] -> [a]
++ [Name] -> (PTerm -> [Name]) -> Maybe PTerm -> [Name]
forall b a. b -> (a -> b) -> Maybe a -> b
maybe [] (t -> [Name] -> PTerm -> [Name]
ni t
i [Name]
env) Maybe PTerm
ty
    ni t
i [Name]
env (PUnquote PTerm
tm)          = t -> [Name] -> PTerm -> [Name]
ni (t
i t -> t -> t
forall a. Num a => a -> a -> a
- t
1) [Name]
env PTerm
tm

    ni t
i [Name]
env PTerm
tm                     = (PTerm -> [Name]) -> [PTerm] -> [Name]
forall (t :: * -> *) a b. Foldable t => (a -> [b]) -> t a -> [b]
concatMap (t -> [Name] -> PTerm -> [Name]
ni t
i [Name]
env) (PTerm -> [PTerm]
forall on. Uniplate on => on -> [on]
children PTerm
tm)

    niTacImp :: t -> [Name] -> Plicity -> [Name]
niTacImp t
i [Name]
env (TacImp [ArgOpt]
_ Static
_ PTerm
scr RigCount
_) = t -> [Name] -> PTerm -> [Name]
ni t
i [Name]
env PTerm
scr
    niTacImp t
_ [Name]
_ Plicity
_                = []

-- Return the list of inaccessible (= dotted) positions for a name.
getErasureInfo :: IState -> Name -> [Int]
getErasureInfo :: IState -> Name -> [Int]
getErasureInfo IState
ist Name
n =
    case Name -> Ctxt OptInfo -> Maybe OptInfo
forall a. Name -> Ctxt a -> Maybe a
lookupCtxtExact Name
n (IState -> Ctxt OptInfo
idris_optimisation IState
ist) of
        Just (Optimise [(Int, Name)]
inacc Bool
_ [Int]
_) -> ((Int, Name) -> Int) -> [(Int, Name)] -> [Int]
forall a b. (a -> b) -> [a] -> [b]
map (Int, Name) -> Int
forall a b. (a, b) -> a
fst [(Int, Name)]
inacc
        Maybe OptInfo
Nothing -> []