{-|
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
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [ElabWhat] -> ShowS
$cshowList :: [ElabWhat] -> ShowS
show :: ElabWhat -> String
$cshow :: ElabWhat -> String
showsPrec :: Int -> ElabWhat -> ShowS
$cshowsPrec :: Int -> ElabWhat -> ShowS
Show, ElabWhat -> ElabWhat -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: ElabWhat -> ElabWhat -> Bool
$c/= :: ElabWhat -> ElabWhat -> Bool
== :: ElabWhat -> ElabWhat -> Bool
$c== :: 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 -> 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 -> Idris ())
-> ElabInfo
EInfo [] forall {k} {a}. Map k a
emptyContext forall a. a -> a
id [] forall a. Maybe a
Nothing String
"(toplevel)" Int
0 [] forall a. a -> a
id (\ElabWhat
_ ElabInfo
_ PDecl
_ -> 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 -> Idris ())
-> ElabInfo
EInfo [] forall {k} {a}. Map k a
emptyContext forall a. a -> a
id [] forall a. Maybe a
Nothing String
ns Int
0 [] forall a. a -> a
id (\ElabWhat
_ ElabInfo
_ PDecl
_ -> forall (m :: * -> *) a. MonadFail m => String -> m a
fail String
"Not implemented")

eInfoNames :: ElabInfo -> [Name]
eInfoNames :: ElabInfo -> [Name]
eInfoNames ElabInfo
info = forall a b. (a -> b) -> [a] -> [b]
map forall a b. (a, b) -> a
fst (ElabInfo -> [(Name, PTerm)]
params ElabInfo
info) forall a. [a] -> [a] -> [a]
++ 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
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [IOption] -> ShowS
$cshowList :: [IOption] -> ShowS
show :: IOption -> String
$cshow :: IOption -> String
showsPrec :: Int -> IOption -> ShowS
$cshowsPrec :: Int -> IOption -> ShowS
Show, IOption -> IOption -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: IOption -> IOption -> Bool
$c/= :: IOption -> IOption -> Bool
== :: IOption -> IOption -> Bool
$c== :: IOption -> IOption -> Bool
Eq, 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
$cto :: forall x. Rep IOption x -> IOption
$cfrom :: forall x. IOption -> Rep IOption x
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 = 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
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [PPOption] -> ShowS
$cshowList :: [PPOption] -> ShowS
show :: PPOption -> String
$cshow :: PPOption -> String
showsPrec :: Int -> PPOption -> ShowS
$cshowsPrec :: Int -> 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 = 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 = 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 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
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [OutputMode] -> ShowS
$cshowList :: [OutputMode] -> ShowS
show :: OutputMode -> String
$cshow :: OutputMode -> String
showsPrec :: Int -> OutputMode -> ShowS
$cshowsPrec :: Int -> 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
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [DefaultTotality] -> ShowS
$cshowList :: [DefaultTotality] -> ShowS
show :: DefaultTotality -> String
$cshow :: DefaultTotality -> String
showsPrec :: Int -> DefaultTotality -> ShowS
$cshowsPrec :: Int -> DefaultTotality -> ShowS
Show, DefaultTotality -> DefaultTotality -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: DefaultTotality -> DefaultTotality -> Bool
$c/= :: DefaultTotality -> DefaultTotality -> Bool
== :: DefaultTotality -> DefaultTotality -> Bool
$c== :: DefaultTotality -> DefaultTotality -> Bool
Eq, 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
$cto :: forall x. Rep DefaultTotality x -> DefaultTotality
$cfrom :: forall x. DefaultTotality -> Rep DefaultTotality x
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
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [InteractiveOpts] -> ShowS
$cshowList :: [InteractiveOpts] -> ShowS
show :: InteractiveOpts -> String
$cshow :: InteractiveOpts -> String
showsPrec :: Int -> InteractiveOpts -> ShowS
$cshowsPrec :: Int -> InteractiveOpts -> ShowS
Show, 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
$cto :: forall x. Rep InteractiveOpts x -> InteractiveOpts
$cfrom :: forall x. InteractiveOpts -> Rep InteractiveOpts x
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. 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
$cto :: forall x. Rep IState x -> IState
$cfrom :: forall x. IState -> Rep IState x
Generic

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

data SizeChange = Smaller | Same | Bigger | Unknown
    deriving (Int -> SizeChange -> ShowS
[SizeChange] -> ShowS
SizeChange -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [SizeChange] -> ShowS
$cshowList :: [SizeChange] -> ShowS
show :: SizeChange -> String
$cshow :: SizeChange -> String
showsPrec :: Int -> SizeChange -> ShowS
$cshowsPrec :: Int -> SizeChange -> ShowS
Show, SizeChange -> SizeChange -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: SizeChange -> SizeChange -> Bool
$c/= :: SizeChange -> SizeChange -> Bool
== :: SizeChange -> SizeChange -> Bool
$c== :: SizeChange -> SizeChange -> Bool
Eq, 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
$cto :: forall x. Rep SizeChange x -> SizeChange
$cfrom :: forall x. SizeChange -> Rep SizeChange x
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
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [CGInfo] -> ShowS
$cshowList :: [CGInfo] -> ShowS
show :: CGInfo -> String
$cshow :: CGInfo -> String
showsPrec :: Int -> CGInfo -> ShowS
$cshowsPrec :: Int -> CGInfo -> ShowS
Show, 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
$cto :: forall x. Rep CGInfo x -> CGInfo
$cfrom :: forall x. CGInfo -> Rep CGInfo x
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
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [IBCWrite] -> ShowS
$cshowList :: [IBCWrite] -> ShowS
show :: IBCWrite -> String
$cshow :: IBCWrite -> String
showsPrec :: Int -> IBCWrite -> ShowS
$cshowsPrec :: Int -> IBCWrite -> ShowS
Show, 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
$cto :: forall x. Rep IBCWrite x -> IBCWrite
$cfrom :: forall x. IBCWrite -> Rep IBCWrite x
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 forall a. Set a
S.empty []
                   forall {k} {a}. Map k a
emptyContext forall {k} {a}. Map k a
emptyContext forall {k} {a}. Map k a
emptyContext [] forall {k} {a}. Map k a
emptyContext
                   forall {k} {a}. Map k a
emptyContext forall {k} {a}. Map k a
emptyContext forall {k} {a}. Map k a
emptyContext forall {k} {a}. Map k a
emptyContext
                   forall {k} {a}. Map k a
emptyContext forall {k} {a}. Map k a
emptyContext forall {k} {a}. Map k a
emptyContext forall {k} {a}. Map k a
emptyContext
                   forall {k} {a}. Map k a
emptyContext forall {k} {a}. Map k a
emptyContext forall {k} {a}. Map k a
emptyContext forall {k} {a}. Map k a
emptyContext
                   forall {k} {a}. Map k a
emptyContext
                   [] [] [] IOption
defaultOpts Int
6 [] [] [] [] [] SyntaxRules
emptySyntaxRules [] [] [] [] [] [] []
                   [] [] forall a. Maybe a
Nothing [] forall a. Maybe a
Nothing [] [] forall a. Maybe a
Nothing forall {k} {a}. Map k a
emptyContext Accessibility
Private DefaultTotality
DefaultCheckingPartial [] forall a. Maybe a
Nothing [] []
                   (Handle -> OutputMode
RawOutput Handle
stdout) Bool
True ColourTheme
defaultTheme [] (Int
0, forall {k} {a}. Map k a
emptyContext) forall {k} {a}. Map k a
emptyContext forall {k} {a}. Map k a
M.empty
                   ConsoleWidth
AutomaticWidth forall a. Set a
S.empty forall a. Set a
S.empty [] [] [] forall {k} {a}. Map k a
M.empty [] forall a. Set a
S.empty forall a. Set a
S.empty
                   forall {k} {a}. Map k a
emptyContext forall a. Set a
S.empty forall {k} {a}. Map k a
M.empty 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 = forall e (m :: * -> *) a s.
Catch e m (a, s) -> Catch e (StateT s m) a
liftCatch 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 = forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
Trans.lift forall b c a. (b -> c) -> (a -> b) -> a -> c
. 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
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [ElabShellCmd] -> ShowS
$cshowList :: [ElabShellCmd] -> ShowS
show :: ElabShellCmd -> String
$cshow :: ElabShellCmd -> String
showsPrec :: Int -> ElabShellCmd -> ShowS
$cshowsPrec :: Int -> ElabShellCmd -> ShowS
Show, ElabShellCmd -> ElabShellCmd -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: ElabShellCmd -> ElabShellCmd -> Bool
$c/= :: ElabShellCmd -> ElabShellCmd -> Bool
== :: ElabShellCmd -> ElabShellCmd -> Bool
$c== :: 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
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Fixity -> Fixity -> Bool
$c/= :: Fixity -> Fixity -> Bool
== :: Fixity -> Fixity -> Bool
$c== :: Fixity -> Fixity -> Bool
Eq, 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
$cto :: forall x. Rep Fixity x -> Fixity
$cfrom :: forall x. Fixity -> Rep Fixity x
Generic)
{-!
deriving instance Binary Fixity
!-}

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

data FixDecl = Fix Fixity String
    deriving (FixDecl -> FixDecl -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: FixDecl -> FixDecl -> Bool
$c/= :: FixDecl -> FixDecl -> Bool
== :: FixDecl -> FixDecl -> Bool
$c== :: FixDecl -> FixDecl -> Bool
Eq, 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
$cto :: forall x. Rep FixDecl x -> FixDecl
$cfrom :: forall x. FixDecl -> Rep FixDecl x
Generic)

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

type FnOpts = [FnOpt]

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

dictionary :: FnOpts -> Bool
dictionary :: [FnOpt] -> Bool
dictionary = 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
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
showList :: [ProvideWhat' t] -> ShowS
$cshowList :: forall t. Show t => [ProvideWhat' t] -> ShowS
show :: ProvideWhat' t -> String
$cshow :: forall t. Show t => ProvideWhat' t -> String
showsPrec :: Int -> ProvideWhat' t -> ShowS
$cshowsPrec :: forall t. Show t => Int -> ProvideWhat' t -> ShowS
Show, ProvideWhat' t -> ProvideWhat' t -> Bool
forall t. Eq t => ProvideWhat' t -> ProvideWhat' t -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: ProvideWhat' t -> ProvideWhat' t -> Bool
$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
Eq, 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
<$ :: forall a b. a -> ProvideWhat' b -> ProvideWhat' a
$c<$ :: forall a b. a -> ProvideWhat' b -> ProvideWhat' a
fmap :: forall a b. (a -> b) -> ProvideWhat' a -> ProvideWhat' b
$cfmap :: forall a b. (a -> b) -> ProvideWhat' a -> ProvideWhat' b
Functor, 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
$cto :: forall t x. Rep (ProvideWhat' t) x -> ProvideWhat' t
$cfrom :: forall t x. ProvideWhat' t -> Rep (ProvideWhat' t) x
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 -> 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
<$ :: forall a b. a -> PDecl' b -> PDecl' a
$c<$ :: forall a b. a -> PDecl' b -> PDecl' a
fmap :: forall a b. (a -> b) -> PDecl' a -> PDecl' b
$cfmap :: forall a b. (a -> b) -> PDecl' a -> PDecl' b
Functor, 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
$cto :: forall t x. Rep (PDecl' t) x -> PDecl' t
$cfrom :: forall t x. PDecl' t -> Rep (PDecl' t) x
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. 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
$cto :: forall x. Rep Directive x -> Directive
$cfrom :: forall x. Directive -> Rep Directive x
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)]
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)]
-> [(Int, Elab' EState ())]
-> [RDeclInstructions]
-> Set (FC', OutputAnnotation)
-> [Name]
-> [(FC, Name)]
-> EState
EState [] [] [] 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 =
  forall aux. (aux -> aux) -> Elab' aux ()
updateAux (\EState
aux -> EState
aux { highlighting :: Set (FC', OutputAnnotation)
highlighting = forall a. Ord a => a -> Set a -> Set a
S.insert (FC -> FC'
FC' FC
fc, OutputAnnotation
annot) (EState -> Set (FC', OutputAnnotation)
highlighting EState
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 -> 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
<$ :: forall a b. a -> PClause' b -> PClause' a
$c<$ :: forall a b. a -> PClause' b -> PClause' a
fmap :: forall a b. (a -> b) -> PClause' a -> PClause' b
$cfmap :: forall a b. (a -> b) -> PClause' a -> PClause' b
Functor, 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
$cto :: forall t x. Rep (PClause' t) x -> PClause' t
$cfrom :: forall t x. PClause' t -> Rep (PClause' t) x
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 -> 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
<$ :: forall a b. a -> PData' b -> PData' a
$c<$ :: forall a b. a -> PData' b -> PData' a
fmap :: forall a b. (a -> b) -> PData' a -> PData' b
$cfmap :: forall a b. (a -> b) -> PData' a -> PData' b
Functor, 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
$cto :: forall t x. Rep (PData' t) x -> PData' t
$cfrom :: forall t x. PData' t -> Rep (PData' t) x
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) =
  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) (forall a b. (a -> b) -> [a] -> [b]
map 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) =
  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 -> PDecl
mapPDeclFC FC -> FC
f FC -> FC
g (PFix FC
fc Fixity
fixity [String]
ops) =
    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) =
    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) =
    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]
clauses) =
    forall t. FC -> [FnOpt] -> Name -> [PClause' t] -> PDecl' t
PClauses (FC -> FC
f FC
fc) [FnOpt]
opts Name
n (forall a b. (a -> b) -> [a] -> [b]
map (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]
clauses)
mapPDeclFC FC -> FC
f FC -> FC
g (PCAF FC
fc Name
n PTerm
tm) = 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) =
    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]
decls) =
    forall t. FC -> [(Name, t)] -> [PDecl' t] -> PDecl' t
PParams (FC -> FC
f FC
fc)
            (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)
            (forall a b. (a -> b) -> [a] -> [b]
map ((FC -> FC) -> (FC -> FC) -> PDecl -> PDecl
mapPDeclFC FC -> FC
f FC -> FC
g) [PDecl]
decls)
mapPDeclFC FC -> FC
f FC -> FC
g (POpenInterfaces FC
fc [Name]
ifs [PDecl]
decls) =
    forall t. FC -> [Name] -> [PDecl' t] -> PDecl' t
POpenInterfaces (FC -> FC
f FC
fc) [Name]
ifs (forall a b. (a -> b) -> [a] -> [b]
map ((FC -> FC) -> (FC -> FC) -> PDecl -> PDecl
mapPDeclFC FC -> FC
f FC -> FC
g) [PDecl]
decls)
mapPDeclFC FC -> FC
f FC -> FC
g (PNamespace String
ns FC
fc [PDecl]
decls) =
    forall t. String -> FC -> [PDecl' t] -> PDecl' t
PNamespace String
ns (FC -> FC
f FC
fc) (forall a b. (a -> b) -> [a] -> [b]
map ((FC -> FC) -> (FC -> FC) -> PDecl -> PDecl
mapPDeclFC FC -> FC
f FC -> FC
g) [PDecl]
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') =
    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)
            (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
            (forall a b. (a -> b) -> [a] -> [b]
map (\(Maybe (Name, FC)
fn, Plicity
plic, PTerm
ty, Maybe (Docstring (Either Err PTerm))
fdoc) -> (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)
            (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]
body Maybe (Name, FC)
ctor Docstring (Either Err PTerm)
ctorDoc) =
    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)
           (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) (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 (forall a b. (a -> b) -> [a] -> [b]
map (\(Name
dn, FC
dnfc) -> (Name
dn, FC -> FC
g FC
dnfc)) [(Name, FC)]
det)
           (forall a b. (a -> b) -> [a] -> [b]
map ((FC -> FC) -> (FC -> FC) -> PDecl -> PDecl
mapPDeclFC FC -> FC
f FC -> FC
g) [PDecl]
body)
           (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]
body) =
    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)
                    (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) (forall a b. (a -> b) -> [a] -> [b]
map ((FC -> FC) -> (FC -> FC) -> PTerm -> PTerm
mapPTermFC FC -> FC
f FC -> FC
g) [PTerm]
params)
                    (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
                    (forall a b. (a -> b) -> [a] -> [b]
map ((FC -> FC) -> (FC -> FC) -> PDecl -> PDecl
mapPDeclFC FC -> FC
f FC -> FC
g) [PDecl]
body)
mapPDeclFC FC -> FC
f FC -> FC
g (PDSL Name
n DSL
dsl) = forall t. Name -> DSL' t -> PDecl' t
PDSL Name
n (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) = forall t. FC -> Syntax -> PDecl' t
PSyntax (FC -> FC
f FC
fc) 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]
decls -> [SSymbol] -> [PDecl] -> Syntax
DeclRule [SSymbol]
syms (forall a b. (a -> b) -> [a] -> [b]
map ((FC -> FC) -> (FC -> FC) -> PDecl -> PDecl
mapPDeclFC FC -> FC
f FC -> FC
g) [PDecl]
decls)
mapPDeclFC FC -> FC
f FC -> FC
g (PMutual FC
fc [PDecl]
decls) =
    forall t. FC -> [PDecl' t] -> PDecl' t
PMutual (FC -> FC
f FC
fc) (forall a b. (a -> b) -> [a] -> [b]
map ((FC -> FC) -> (FC -> FC) -> PDecl -> PDecl
mapPDeclFC FC -> FC
f FC -> FC
g) [PDecl]
decls)
mapPDeclFC FC -> FC
f FC -> FC
g (PDirective Directive
d) =
    forall t. Directive -> PDecl' t
PDirective 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) (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') forall a b. (a -> b) -> a -> b
$
                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) =
    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) (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) =
    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) =
    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 -> [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]
_) = [] -- 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 forall a. a -> [a] -> [a]
: forall a b. (a -> b) -> [a] -> [b]
map 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]
ds) = forall (t :: * -> *) a b. Foldable t => (a -> [b]) -> t a -> [b]
concatMap PDecl -> [Name]
declared [PDecl]
ds
declared (POpenInterfaces FC
_ [Name]
_ [PDecl]
ds) = forall (t :: * -> *) a b. Foldable t => (a -> [b]) -> t a -> [b]
concatMap PDecl -> [Name]
declared [PDecl]
ds
declared (PNamespace String
_ FC
_ [PDecl]
ds) = forall (t :: * -> *) a b. Foldable t => (a -> [b]) -> t a -> [b]
concatMap PDecl -> [Name]
declared [PDecl]
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 forall a. a -> [a] -> [a]
: forall a b. (a -> b) -> [a] -> [b]
map forall a b. (a, b) -> a
fst (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]
ms Maybe (Name, FC)
cn Docstring (Either Err PTerm)
cd) = Name
n forall a. a -> [a] -> [a]
: (forall a b. (a -> b) -> [a] -> [b]
map forall a b. (a, b) -> a
fst (forall a. Maybe a -> [a]
maybeToList Maybe (Name, FC)
cn) forall a. [a] -> [a] -> [a]
++ forall (t :: * -> *) a b. Foldable t => (a -> [b]) -> t a -> [b]
concatMap PDecl -> [Name]
declared [PDecl]
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]
_)
    = 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]
ds) = forall (t :: * -> *) a b. Foldable t => (a -> [b]) -> t a -> [b]
concatMap PDecl -> [Name]
declared [PDecl]
ds
declared (PDirective Directive
_) = []
declared PDecl
_ = []

-- get the names declared, not counting nested parameter blocks
tldeclared :: PDecl -> [Name]
tldeclared :: PDecl -> [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]
_)                     = [] -- 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 forall a. a -> [a] -> [a]
: forall a b. (a -> b) -> [a] -> [b]
map forall a b. (a, b) -> a
fst (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 forall a. a -> [a] -> [a]
: forall a b. (a -> b) -> [a] -> [b]
map 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]
ds)                       = []
tldeclared (POpenInterfaces FC
_ [Name]
_ [PDecl]
ds)               = forall (t :: * -> *) a b. Foldable t => (a -> [b]) -> t a -> [b]
concatMap PDecl -> [Name]
tldeclared [PDecl]
ds
tldeclared (PMutual FC
_ [PDecl]
ds)                         = forall (t :: * -> *) a b. Foldable t => (a -> [b]) -> t a -> [b]
concatMap PDecl -> [Name]
tldeclared [PDecl]
ds
tldeclared (PNamespace String
_ FC
_ [PDecl]
ds)                    = forall (t :: * -> *) a b. Foldable t => (a -> [b]) -> t a -> [b]
concatMap PDecl -> [Name]
tldeclared [PDecl]
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]
ms Maybe (Name, FC)
cn Docstring (Either Err PTerm)
_)     = Name
n forall a. a -> [a] -> [a]
: (forall a b. (a -> b) -> [a] -> [b]
map forall a b. (a, b) -> a
fst (forall a. Maybe a -> [a]
maybeToList Maybe (Name, FC)
cn) forall a. [a] -> [a] -> [a]
++ forall (t :: * -> *) a b. Foldable t => (a -> [b]) -> t a -> [b]
concatMap PDecl -> [Name]
tldeclared [PDecl]
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]
_)
    = case Maybe Name
mn of
           Maybe Name
Nothing -> []
           Just Name
n -> [Name
n]
tldeclared PDecl
_                                      = []

defined :: PDecl -> [Name]
defined :: PDecl -> [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]
_)                        = [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 forall a. a -> [a] -> [a]
: forall a b. (a -> b) -> [a] -> [b]
map 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]
ds)                          = forall (t :: * -> *) a b. Foldable t => (a -> [b]) -> t a -> [b]
concatMap PDecl -> [Name]
defined [PDecl]
ds
defined (POpenInterfaces FC
_ [Name]
_ [PDecl]
ds)                  = forall (t :: * -> *) a b. Foldable t => (a -> [b]) -> t a -> [b]
concatMap PDecl -> [Name]
defined [PDecl]
ds
defined (PNamespace String
_ FC
_ [PDecl]
ds)                       = forall (t :: * -> *) a b. Foldable t => (a -> [b]) -> t a -> [b]
concatMap PDecl -> [Name]
defined [PDecl]
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 forall a. a -> [a] -> [a]
: forall a b. (a -> b) -> [a] -> [b]
map forall a b. (a, b) -> a
fst (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]
ms Maybe (Name, FC)
cn Docstring (Either Err PTerm)
_)        = Name
n forall a. a -> [a] -> [a]
: (forall a b. (a -> b) -> [a] -> [b]
map forall a b. (a, b) -> a
fst (forall a. Maybe a -> [a]
maybeToList Maybe (Name, FC)
cn) forall a. [a] -> [a] -> [a]
++ forall (t :: * -> *) a b. Foldable t => (a -> [b]) -> t a -> [b]
concatMap PDecl -> [Name]
defined [PDecl]
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]
_)
    = 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]
ds)                            = forall (t :: * -> *) a b. Foldable t => (a -> [b]) -> t a -> [b]
concatMap PDecl -> [Name]
defined [PDecl]
ds
defined (PDirective Directive
_)                            = []
defined PDecl
_                                         = []

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

data PAltType = ExactlyOne Bool -- ^ flag sets whether delay is allowed
              | FirstSuccess
              | TryImplicit
       deriving (PAltType -> PAltType -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: PAltType -> PAltType -> Bool
$c/= :: PAltType -> PAltType -> Bool
== :: PAltType -> PAltType -> Bool
$c== :: PAltType -> PAltType -> Bool
Eq, Eq 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
min :: PAltType -> PAltType -> PAltType
$cmin :: PAltType -> PAltType -> PAltType
max :: PAltType -> PAltType -> PAltType
$cmax :: PAltType -> PAltType -> PAltType
>= :: PAltType -> PAltType -> Bool
$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
compare :: PAltType -> PAltType -> Ordering
$ccompare :: PAltType -> PAltType -> Ordering
Ord, Typeable 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)
gmapMo :: 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
gmapMp :: forall (m :: * -> *).
MonadPlus 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
gmapM :: forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> PAltType -> m PAltType
$cgmapM :: forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> PAltType -> m PAltType
gmapQi :: forall u. Int -> (forall d. Data d => d -> u) -> PAltType -> u
$cgmapQi :: forall u. Int -> (forall d. Data d => d -> u) -> PAltType -> u
gmapQ :: forall u. (forall d. Data d => d -> u) -> PAltType -> [u]
$cgmapQ :: forall u. (forall d. Data d => d -> u) -> PAltType -> [u]
gmapQr :: 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
gmapQl :: forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> PAltType -> r
$cgmapQl :: forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> PAltType -> r
gmapT :: (forall b. Data b => b -> b) -> PAltType -> PAltType
$cgmapT :: (forall b. Data b => b -> b) -> PAltType -> PAltType
dataCast2 :: forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c PAltType)
$cdataCast2 :: forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c PAltType)
dataCast1 :: forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c PAltType)
$cdataCast1 :: forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c PAltType)
dataTypeOf :: PAltType -> DataType
$cdataTypeOf :: PAltType -> DataType
toConstr :: PAltType -> Constr
$ctoConstr :: PAltType -> Constr
gunfold :: forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c PAltType
$cgunfold :: forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c PAltType
gfoldl :: forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> PAltType -> c PAltType
$cgfoldl :: forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> PAltType -> c PAltType
Data, 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
$cto :: forall x. Rep PAltType x -> PAltType
$cfrom :: forall x. PAltType -> Rep PAltType x
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) (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) (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) (forall a b. (a -> b) -> [a] -> [b]
map (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) (forall a b. (a -> b) -> [a] -> [b]
map (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) (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) (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) (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) (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 (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 (forall a b. (a -> b) -> [a] -> [b]
map PDo -> PDo
mapPDoFC [PDo]
dos)
  where mapPDoFC :: PDo -> PDo
mapPDoFC (DoExp  FC
fc PTerm
t) = 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) = 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) =
          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) (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) = 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) =
          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) (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) = 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 (forall a b. (a -> b) -> [a] -> [b]
map (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 (forall a b. (a -> b) -> [a] -> [b]
map (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) (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) (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) (forall a b. (a -> b) -> [a] -> [b]
map (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) (forall a b. (a -> b) -> [a] -> [b]
map (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) (forall a b. (a -> b) -> [a] -> [b]
map (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 (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 (forall a b. (a -> b) -> [a] -> [b]
map (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 (forall a b. (a -> b) -> [a] -> [b]
map (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 (forall a b. (a -> b) -> [a] -> [b]
map (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
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
showList :: [PTactic' t] -> ShowS
$cshowList :: forall t. Show t => [PTactic' t] -> ShowS
show :: PTactic' t -> String
$cshow :: forall t. Show t => PTactic' t -> String
showsPrec :: Int -> PTactic' t -> ShowS
$cshowsPrec :: forall t. Show t => Int -> PTactic' t -> ShowS
Show, PTactic' t -> PTactic' t -> Bool
forall t. Eq t => PTactic' t -> PTactic' t -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: PTactic' t -> PTactic' t -> Bool
$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
Eq, PTactic' t -> PTactic' t -> Ordering
forall a.
Eq a
-> (a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
forall {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
min :: PTactic' t -> PTactic' t -> PTactic' t
$cmin :: forall t. Ord t => PTactic' t -> PTactic' t -> PTactic' t
max :: PTactic' t -> PTactic' t -> PTactic' t
$cmax :: forall t. Ord t => PTactic' t -> PTactic' t -> PTactic' t
>= :: 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
$c< :: forall t. Ord t => PTactic' t -> PTactic' t -> Bool
compare :: PTactic' t -> PTactic' t -> Ordering
$ccompare :: forall t. Ord t => PTactic' t -> PTactic' t -> Ordering
Ord, 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
<$ :: forall a b. a -> PTactic' b -> PTactic' a
$c<$ :: forall a b. a -> PTactic' b -> PTactic' a
fmap :: forall a b. (a -> b) -> PTactic' a -> PTactic' b
$cfmap :: forall a b. (a -> b) -> PTactic' a -> PTactic' b
Functor, 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
product :: forall a. Num a => PTactic' a -> a
$cproduct :: forall a. Num a => PTactic' a -> a
sum :: forall a. Num a => PTactic' a -> a
$csum :: forall a. Num a => PTactic' a -> a
minimum :: forall a. Ord a => PTactic' a -> a
$cminimum :: forall a. Ord a => PTactic' a -> a
maximum :: forall a. Ord a => PTactic' a -> a
$cmaximum :: forall a. Ord a => PTactic' a -> a
elem :: forall a. Eq a => a -> PTactic' a -> Bool
$celem :: forall a. Eq a => a -> PTactic' a -> Bool
length :: forall a. PTactic' a -> Int
$clength :: forall a. PTactic' a -> Int
null :: forall a. PTactic' a -> Bool
$cnull :: forall a. PTactic' a -> Bool
toList :: forall a. PTactic' a -> [a]
$ctoList :: forall a. PTactic' a -> [a]
foldl1 :: forall a. (a -> a -> a) -> PTactic' a -> a
$cfoldl1 :: forall a. (a -> a -> a) -> PTactic' a -> a
foldr1 :: forall a. (a -> a -> a) -> PTactic' a -> a
$cfoldr1 :: forall a. (a -> a -> a) -> PTactic' a -> a
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
$cfoldl :: forall b a. (b -> a -> 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
$cfoldr :: forall a b. (a -> b -> b) -> b -> PTactic' a -> b
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
$cfoldMap :: forall m a. Monoid m => (a -> m) -> PTactic' a -> m
fold :: forall m. Monoid m => PTactic' m -> m
$cfold :: forall m. Monoid m => PTactic' m -> m
Foldable, Functor PTactic'
Foldable 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)
sequence :: forall (m :: * -> *) a. Monad m => PTactic' (m a) -> m (PTactic' a)
$csequence :: forall (m :: * -> *) a. Monad m => PTactic' (m a) -> m (PTactic' a)
mapM :: forall (m :: * -> *) a b.
Monad m =>
(a -> m b) -> PTactic' a -> m (PTactic' b)
$cmapM :: forall (m :: * -> *) a b.
Monad m =>
(a -> m b) -> PTactic' a -> m (PTactic' b)
sequenceA :: forall (f :: * -> *) a.
Applicative f =>
PTactic' (f a) -> f (PTactic' a)
$csequenceA :: forall (f :: * -> *) a.
Applicative f =>
PTactic' (f a) -> f (PTactic' a)
traverse :: 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)
Traversable, PTactic' t -> Constr
PTactic' t -> DataType
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 (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))
gmapMo :: 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)
gmapMp :: forall (m :: * -> *).
MonadPlus 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)
gmapM :: forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> PTactic' t -> m (PTactic' t)
$cgmapM :: forall t (m :: * -> *).
(Data t, Monad m) =>
(forall d. Data d => d -> m d) -> PTactic' t -> m (PTactic' t)
gmapQi :: forall u. Int -> (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
gmapQ :: forall u. (forall d. Data d => d -> u) -> PTactic' t -> [u]
$cgmapQ :: forall t u.
Data t =>
(forall d. Data d => d -> u) -> PTactic' t -> [u]
gmapQr :: 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
gmapQl :: forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> PTactic' t -> r
$cgmapQl :: forall t r r'.
Data t =>
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> PTactic' t -> r
gmapT :: (forall b. Data b => b -> b) -> PTactic' t -> PTactic' t
$cgmapT :: forall t.
Data t =>
(forall b. Data b => b -> b) -> PTactic' t -> PTactic' t
dataCast2 :: forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e))
-> 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))
dataCast1 :: forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c (PTactic' t))
$cdataCast1 :: forall t (t :: * -> *) (c :: * -> *).
(Data t, Typeable t) =>
(forall d. Data d => c (t d)) -> Maybe (c (PTactic' t))
dataTypeOf :: PTactic' t -> DataType
$cdataTypeOf :: forall t. Data t => PTactic' t -> DataType
toConstr :: PTactic' t -> Constr
$ctoConstr :: forall t. Data t => PTactic' t -> Constr
gunfold :: forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> 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)
gfoldl :: forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> PTactic' t -> 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)
Data, 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
$cto :: forall t x. Rep (PTactic' t) x -> PTactic' t
$cfrom :: forall t x. PTactic' t -> Rep (PTactic' t) x
Generic, Typeable)
{-!
deriving instance Binary PTactic'
!-}
instance Sized a => Sized (PTactic' a) where
  size :: PTactic' a -> Int
size (Intro [Name]
nms)      = Int
1 forall a. Num a => a -> a -> a
+ forall a. Sized a => a -> Int
size [Name]
nms
  size PTactic' a
Intros           = Int
1
  size (Focus Name
nm)       = Int
1 forall a. Num a => a -> a -> a
+ forall a. Sized a => a -> Int
size Name
nm
  size (Refine Name
nm [Bool]
bs)   = Int
1 forall a. Num a => a -> a -> a
+ forall a. Sized a => a -> Int
size Name
nm forall a. Num a => a -> a -> a
+ forall (t :: * -> *) a. Foldable t => t a -> Int
length [Bool]
bs
  size (Rewrite a
t)      = Int
1 forall a. Num a => a -> a -> a
+ forall a. Sized a => a -> Int
size a
t
  size (LetTac Name
nm a
t)    = Int
1 forall a. Num a => a -> a -> a
+ forall a. Sized a => a -> Int
size Name
nm forall a. Num a => a -> a -> a
+ forall a. Sized a => a -> Int
size a
t
  size (Exact a
t)        = Int
1 forall a. Num a => a -> a -> a
+ 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 forall a. Num a => a -> a -> a
+ forall a. Sized a => a -> Int
size PTactic' a
l forall a. Num a => a -> a -> a
+ forall a. Sized a => a -> Int
size PTactic' a
r
  size (TSeq PTactic' a
l PTactic' a
r)       = Int
1 forall a. Num a => a -> a -> a
+ forall a. Sized a => a -> Int
size PTactic' a
l forall a. Num a => a -> a -> a
+ forall a. Sized a => a -> Int
size PTactic' a
r
  size (ApplyTactic a
t)  = Int
1 forall a. Num a => a -> a -> a
+ forall a. Sized a => a -> Int
size a
t
  size (Reflect a
t)      = Int
1 forall a. Num a => a -> a -> a
+ forall a. Sized a => a -> Int
size a
t
  size (Fill a
t)         = Int
1 forall a. Num a => a -> a -> a
+ 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 forall a. Num a => a -> a -> a
+ 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 forall a. Num a => a -> a -> a
+ forall a. Sized a => a -> Int
size a
t
  size (Claim Name
x a
y)      = Int
1 forall a. Num a => a -> a -> a
+ forall a. Sized a => a -> Int
size Name
x forall a. Num a => a -> a -> a
+ forall a. Sized a => a -> Int
size a
y
  size PTactic' a
Unfocus          = Int
1
  size (MatchRefine Name
x)  = Int
1 forall a. Num a => a -> a -> a
+ forall a. Sized a => a -> Int
size Name
x
  size (LetTacTy Name
x a
y a
z) = Int
1 forall a. Num a => a -> a -> a
+ forall a. Sized a => a -> Int
size Name
x forall a. Num a => a -> a -> a
+ forall a. Sized a => a -> Int
size a
y forall a. Num a => a -> a -> a
+ 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
forall t. Eq t => PDo' t -> PDo' t -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: PDo' t -> PDo' t -> Bool
$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
Eq, PDo' t -> PDo' t -> Ordering
forall a.
Eq a
-> (a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
forall {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
min :: PDo' t -> PDo' t -> PDo' t
$cmin :: forall t. Ord t => PDo' t -> PDo' t -> PDo' t
max :: PDo' t -> PDo' t -> PDo' t
$cmax :: forall t. Ord t => PDo' t -> PDo' t -> PDo' t
>= :: 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
$c< :: forall t. Ord t => PDo' t -> PDo' t -> Bool
compare :: PDo' t -> PDo' t -> Ordering
$ccompare :: forall t. Ord t => PDo' t -> PDo' t -> Ordering
Ord, 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
<$ :: forall a b. a -> PDo' b -> PDo' a
$c<$ :: forall a b. a -> PDo' b -> PDo' a
fmap :: forall a b. (a -> b) -> PDo' a -> PDo' b
$cfmap :: forall a b. (a -> b) -> PDo' a -> PDo' b
Functor, PDo' t -> Constr
PDo' t -> DataType
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 (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))
gmapMo :: 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)
gmapMp :: forall (m :: * -> *).
MonadPlus 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)
gmapM :: forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> PDo' t -> m (PDo' t)
$cgmapM :: forall t (m :: * -> *).
(Data t, Monad m) =>
(forall d. Data d => d -> m d) -> PDo' t -> m (PDo' t)
gmapQi :: forall u. Int -> (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
gmapQ :: forall u. (forall d. Data d => d -> u) -> PDo' t -> [u]
$cgmapQ :: forall t u. Data t => (forall d. Data d => d -> u) -> PDo' t -> [u]
gmapQr :: 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
gmapQl :: forall r r'.
(r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> PDo' t -> r
$cgmapQl :: forall t r r'.
Data t =>
(r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> PDo' t -> r
gmapT :: (forall b. Data b => b -> b) -> PDo' t -> PDo' t
$cgmapT :: forall t.
Data t =>
(forall b. Data b => b -> b) -> PDo' t -> PDo' t
dataCast2 :: forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e)) -> 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))
dataCast1 :: forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c (PDo' t))
$cdataCast1 :: forall t (t :: * -> *) (c :: * -> *).
(Data t, Typeable t) =>
(forall d. Data d => c (t d)) -> Maybe (c (PDo' t))
dataTypeOf :: PDo' t -> DataType
$cdataTypeOf :: forall t. Data t => PDo' t -> DataType
toConstr :: PDo' t -> Constr
$ctoConstr :: forall t. Data t => PDo' t -> Constr
gunfold :: forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> 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)
gfoldl :: forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> PDo' t -> 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)
Data, 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
$cto :: forall t x. Rep (PDo' t) x -> PDo' t
$cfrom :: forall t x. PDo' t -> Rep (PDo' t) x
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 forall a. Num a => a -> a -> a
+ forall a. Sized a => a -> Int
size FC
fc forall a. Num a => a -> a -> a
+ forall a. Sized a => a -> Int
size a
t
  size (DoBind FC
fc Name
nm FC
nfc a
t)   = Int
1 forall a. Num a => a -> a -> a
+ forall a. Sized a => a -> Int
size FC
fc forall a. Num a => a -> a -> a
+ forall a. Sized a => a -> Int
size Name
nm forall a. Num a => a -> a -> a
+ forall a. Sized a => a -> Int
size FC
nfc forall a. Num a => a -> a -> a
+ forall a. Sized a => a -> Int
size a
t
  size (DoBindP FC
fc a
l a
r [(a, a)]
alts)  = Int
1 forall a. Num a => a -> a -> a
+ forall a. Sized a => a -> Int
size FC
fc forall a. Num a => a -> a -> a
+ forall a. Sized a => a -> Int
size a
l  forall a. Num a => a -> a -> a
+ forall a. Sized a => a -> Int
size a
r   forall a. Num a => a -> a -> a
+ 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 forall a. Num a => a -> a -> a
+ forall a. Sized a => a -> Int
size FC
fc forall a. Num a => a -> a -> a
+ forall a. Sized a => a -> Int
size Name
nm forall a. Num a => a -> a -> a
+ forall a. Sized a => a -> Int
size a
l   forall a. Num a => a -> a -> a
+ forall a. Sized a => a -> Int
size a
r
  size (DoLetP FC
fc a
l a
r [(a, a)]
alts)   = Int
1 forall a. Num a => a -> a -> a
+ forall a. Sized a => a -> Int
size FC
fc forall a. Num a => a -> a -> a
+ forall a. Sized a => a -> Int
size a
l  forall a. Num a => a -> a -> a
+ forall a. Sized a => a -> Int
size a
r forall a. Num a => a -> a -> a
+ forall a. Sized a => a -> Int
size [(a, a)]
alts
  size (DoRewrite FC
fc a
h)       = Int
1 forall a. Num a => a -> a -> a
+ forall a. Sized a => a -> Int
size FC
fc forall a. Num a => a -> a -> a
+ 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
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
showList :: [PArg' t] -> ShowS
$cshowList :: forall t. Show t => [PArg' t] -> ShowS
show :: PArg' t -> String
$cshow :: forall t. Show t => PArg' t -> String
showsPrec :: Int -> PArg' t -> ShowS
$cshowsPrec :: forall t. Show t => Int -> PArg' t -> ShowS
Show, PArg' t -> PArg' t -> Bool
forall t. Eq t => PArg' t -> PArg' t -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: PArg' t -> PArg' t -> Bool
$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
Eq, PArg' t -> PArg' t -> Ordering
forall a.
Eq a
-> (a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
forall {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
min :: PArg' t -> PArg' t -> PArg' t
$cmin :: forall t. Ord t => PArg' t -> PArg' t -> PArg' t
max :: PArg' t -> PArg' t -> PArg' t
$cmax :: forall t. Ord t => PArg' t -> PArg' t -> PArg' t
>= :: 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
$c< :: forall t. Ord t => PArg' t -> PArg' t -> Bool
compare :: PArg' t -> PArg' t -> Ordering
$ccompare :: forall t. Ord t => PArg' t -> PArg' t -> Ordering
Ord, 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
<$ :: forall a b. a -> PArg' b -> PArg' a
$c<$ :: forall a b. a -> PArg' b -> PArg' a
fmap :: forall a b. (a -> b) -> PArg' a -> PArg' b
$cfmap :: forall a b. (a -> b) -> PArg' a -> PArg' b
Functor, PArg' t -> Constr
PArg' t -> DataType
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 (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))
gmapMo :: 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)
gmapMp :: forall (m :: * -> *).
MonadPlus 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)
gmapM :: forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> PArg' t -> m (PArg' t)
$cgmapM :: forall t (m :: * -> *).
(Data t, Monad m) =>
(forall d. Data d => d -> m d) -> PArg' t -> m (PArg' t)
gmapQi :: forall u. Int -> (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
gmapQ :: forall u. (forall d. Data d => d -> u) -> PArg' t -> [u]
$cgmapQ :: forall t u.
Data t =>
(forall d. Data d => d -> u) -> PArg' t -> [u]
gmapQr :: 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
gmapQl :: forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> PArg' t -> r
$cgmapQl :: forall t r r'.
Data t =>
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> PArg' t -> r
gmapT :: (forall b. Data b => b -> b) -> PArg' t -> PArg' t
$cgmapT :: forall t.
Data t =>
(forall b. Data b => b -> b) -> PArg' t -> PArg' t
dataCast2 :: forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e)) -> 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))
dataCast1 :: forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c (PArg' t))
$cdataCast1 :: forall t (t :: * -> *) (c :: * -> *).
(Data t, Typeable t) =>
(forall d. Data d => c (t d)) -> Maybe (c (PArg' t))
dataTypeOf :: PArg' t -> DataType
$cdataTypeOf :: forall t. Data t => PArg' t -> DataType
toConstr :: PArg' t -> Constr
$ctoConstr :: forall t. Data t => PArg' t -> Constr
gunfold :: forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> 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)
gfoldl :: forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> PArg' t -> 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)
Data, 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
$cto :: forall t x. Rep (PArg' t) x -> PArg' t
$cfrom :: forall t x. PArg' t -> Rep (PArg' t) x
Generic, Typeable)

data ArgOpt = AlwaysShow
            | HideDisplay
            | InaccessibleArg
            | UnknownImp
            deriving (Int -> ArgOpt -> ShowS
[ArgOpt] -> ShowS
ArgOpt -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [ArgOpt] -> ShowS
$cshowList :: [ArgOpt] -> ShowS
show :: ArgOpt -> String
$cshow :: ArgOpt -> String
showsPrec :: Int -> ArgOpt -> ShowS
$cshowsPrec :: Int -> ArgOpt -> ShowS
Show, ArgOpt -> ArgOpt -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: ArgOpt -> ArgOpt -> Bool
$c/= :: ArgOpt -> ArgOpt -> Bool
== :: ArgOpt -> ArgOpt -> Bool
$c== :: ArgOpt -> ArgOpt -> Bool
Eq, Eq 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
min :: ArgOpt -> ArgOpt -> ArgOpt
$cmin :: ArgOpt -> ArgOpt -> ArgOpt
max :: ArgOpt -> ArgOpt -> ArgOpt
$cmax :: ArgOpt -> ArgOpt -> ArgOpt
>= :: ArgOpt -> ArgOpt -> Bool
$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
compare :: ArgOpt -> ArgOpt -> Ordering
$ccompare :: ArgOpt -> ArgOpt -> Ordering
Ord, Typeable 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)
gmapMo :: 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
gmapMp :: forall (m :: * -> *).
MonadPlus 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
gmapM :: forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> ArgOpt -> m ArgOpt
$cgmapM :: forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> ArgOpt -> m ArgOpt
gmapQi :: forall u. Int -> (forall d. Data d => d -> u) -> ArgOpt -> u
$cgmapQi :: forall u. Int -> (forall d. Data d => d -> u) -> ArgOpt -> u
gmapQ :: forall u. (forall d. Data d => d -> u) -> ArgOpt -> [u]
$cgmapQ :: forall u. (forall d. Data d => d -> u) -> ArgOpt -> [u]
gmapQr :: 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
gmapQl :: forall r r'.
(r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> ArgOpt -> r
$cgmapQl :: forall r r'.
(r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> ArgOpt -> r
gmapT :: (forall b. Data b => b -> b) -> ArgOpt -> ArgOpt
$cgmapT :: (forall b. Data b => b -> b) -> ArgOpt -> ArgOpt
dataCast2 :: forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c ArgOpt)
$cdataCast2 :: forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c ArgOpt)
dataCast1 :: forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c ArgOpt)
$cdataCast1 :: forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c ArgOpt)
dataTypeOf :: ArgOpt -> DataType
$cdataTypeOf :: ArgOpt -> DataType
toConstr :: ArgOpt -> Constr
$ctoConstr :: ArgOpt -> Constr
gunfold :: forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c ArgOpt
$cgunfold :: forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c ArgOpt
gfoldl :: forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> ArgOpt -> c ArgOpt
$cgfoldl :: forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> ArgOpt -> c ArgOpt
Data, 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
$cto :: forall x. Rep ArgOpt x -> ArgOpt
$cfrom :: forall x. ArgOpt -> Rep ArgOpt x
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 forall a. Num a => a -> a -> a
+ forall a. Sized a => a -> Int
size Name
nm forall a. Num a => a -> a -> a
+ forall a. Sized a => a -> Int
size a
trm
  size (PExp Int
p [ArgOpt]
l Name
nm a
trm)              = Int
1 forall a. Num a => a -> a -> a
+ forall a. Sized a => a -> Int
size Name
nm forall a. Num a => a -> a -> a
+ forall a. Sized a => a -> Int
size a
trm
  size (PConstraint Int
p [ArgOpt]
l Name
nm a
trm)       = Int
1 forall a. Num a => a -> a -> a
+ forall a. Sized a => a -> Int
size Name
nm forall a. Num a => a -> a -> a
+ forall a. Sized a => a -> Int
size Name
nm  forall a. Num a => a -> a -> a
+  forall a. Sized a => a -> Int
size a
trm
  size (PTacImplicit Int
p [ArgOpt]
l Name
nm a
scr a
trm)  = Int
1 forall a. Num a => a -> a -> a
+ forall a. Sized a => a -> Int
size Name
nm forall a. Num a => a -> a -> a
+ forall a. Sized a => a -> Int
size a
scr forall a. Num a => a -> a -> a
+ 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 = 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        = 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      = 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 = 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
_)              = forall a. Maybe a
Nothing
highestFC (PRef FC
fc [FC]
_ Name
_)           = forall a. a -> Maybe a
Just FC
fc
highestFC (PInferRef FC
fc [FC]
_ Name
_)      = forall a. a -> Maybe a
Just FC
fc
highestFC (PPatvar FC
fc Name
_)          = forall a. a -> Maybe a
Just FC
fc
highestFC (PLam FC
fc Name
_ FC
_ PTerm
_ PTerm
_)       = forall a. a -> Maybe a
Just FC
fc
highestFC (PPi Plicity
_ Name
_ FC
_ PTerm
_ PTerm
_)         = forall a. Maybe a
Nothing
highestFC (PLet FC
fc RigCount
_ Name
_ FC
_ PTerm
_ PTerm
_ PTerm
_)   = forall a. a -> Maybe a
Just FC
fc
highestFC (PTyped PTerm
tm PTerm
ty)          = PTerm -> Maybe FC
highestFC PTerm
tm forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> PTerm -> Maybe FC
highestFC PTerm
ty
highestFC (PApp FC
fc PTerm
_ [PArg]
_)           = forall a. a -> Maybe a
Just FC
fc
highestFC (PAppBind FC
fc PTerm
_ [PArg]
_)       = forall a. a -> Maybe a
Just FC
fc
highestFC (PMatchApp FC
fc Name
_)        = forall a. a -> Maybe a
Just FC
fc
highestFC (PCase FC
fc PTerm
_ [(PTerm, PTerm)]
_)          = forall a. a -> Maybe a
Just FC
fc
highestFC (PIfThenElse FC
fc PTerm
_ PTerm
_ PTerm
_)  = forall a. a -> Maybe a
Just FC
fc
highestFC (PTrue FC
fc PunInfo
_)            = forall a. a -> Maybe a
Just FC
fc
highestFC (PResolveTC FC
fc)         = forall a. a -> Maybe a
Just FC
fc
highestFC (PRewrite FC
fc Maybe Name
_ PTerm
_ PTerm
_ Maybe PTerm
_)   = forall a. a -> Maybe a
Just FC
fc
highestFC (PPair FC
fc [FC]
_ PunInfo
_ PTerm
_ PTerm
_)      = forall a. a -> Maybe a
Just FC
fc
highestFC (PDPair FC
fc [FC]
_ PunInfo
_ PTerm
_ PTerm
_ PTerm
_)   = forall a. a -> Maybe a
Just FC
fc
highestFC (PAs FC
fc Name
_ PTerm
_)            = forall a. a -> Maybe a
Just FC
fc
highestFC (PAlternative [(Name, Name)]
_ PAltType
_ [PTerm]
args) =
  case forall a b. (a -> Maybe b) -> [a] -> [b]
mapMaybe PTerm -> Maybe FC
highestFC [PTerm]
args of
    [] -> forall a. Maybe a
Nothing
    (FC
fc:[FC]
_) -> forall a. a -> Maybe a
Just FC
fc
highestFC (PHidden PTerm
_)             = forall a. Maybe a
Nothing
highestFC (PType FC
fc)              = forall a. a -> Maybe a
Just FC
fc
highestFC (PUniverse FC
_ Universe
_)         = forall a. Maybe a
Nothing
highestFC (PGoal FC
fc PTerm
_ Name
_ PTerm
_)        = forall a. a -> Maybe a
Just FC
fc
highestFC (PConstant FC
fc Const
_)        = forall a. a -> Maybe a
Just FC
fc
highestFC PTerm
Placeholder             = forall a. Maybe a
Nothing
highestFC (PDoBlock [PDo]
lines) =
  case forall a b. (a -> b) -> [a] -> [b]
map forall {t}. PDo' t -> FC
getDoFC [PDo]
lines of
    [] -> forall a. Maybe a
Nothing
    (FC
fc:[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
_)           = forall a. a -> Maybe a
Just FC
fc
highestFC (PMetavar FC
fc Name
_)         = forall a. a -> Maybe a
Just FC
fc
highestFC (PProof [PTactic]
_)              = forall a. Maybe a
Nothing
highestFC (PTactics [PTactic]
_)            = forall a. Maybe a
Nothing
highestFC (PElabError Err
_)          = forall a. Maybe a
Nothing
highestFC PTerm
PImpossible             = 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
_)       = forall a. Maybe a
Nothing
highestFC (PUnquote PTerm
tm)           = PTerm -> Maybe FC
highestFC PTerm
tm
highestFC (PQuoteName Name
_ Bool
_ FC
fc)     = forall a. a -> Maybe a
Just FC
fc
highestFC (PRunElab FC
fc PTerm
_ [String]
_)       = forall a. a -> Maybe a
Just FC
fc
highestFC (PConstSugar FC
fc PTerm
_)      = 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))]
interface_defaults                 :: [(Name, (Name, PDecl))]         -- ^ method name -> default impl
  , InterfaceInfo -> [PDecl]
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
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [InterfaceInfo] -> ShowS
$cshowList :: [InterfaceInfo] -> ShowS
show :: InterfaceInfo -> String
$cshow :: InterfaceInfo -> String
showsPrec :: Int -> InterfaceInfo -> ShowS
$cshowsPrec :: Int -> InterfaceInfo -> ShowS
Show, 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
$cto :: forall x. Rep InterfaceInfo x -> InterfaceInfo
$cfrom :: forall x. InterfaceInfo -> Rep InterfaceInfo x
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
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [RecordInfo] -> ShowS
$cshowList :: [RecordInfo] -> ShowS
show :: RecordInfo -> String
$cshow :: RecordInfo -> String
showsPrec :: Int -> RecordInfo -> ShowS
$cshowsPrec :: Int -> RecordInfo -> ShowS
Show, 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
$cto :: forall x. Rep RecordInfo x -> RecordInfo
$cfrom :: forall x. RecordInfo -> Rep RecordInfo x
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
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [TIData] -> ShowS
$cshowList :: [TIData] -> ShowS
show :: TIData -> String
$cshow :: TIData -> String
showsPrec :: Int -> TIData -> ShowS
$cshowsPrec :: Int -> TIData -> ShowS
Show, 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
$cto :: forall x. Rep TIData x -> TIData
$cfrom :: forall x. TIData -> Rep TIData x
Generic)

-- | Miscellaneous information about functions
data FnInfo = FnInfo { FnInfo -> [Int]
fn_params :: [Int] }
    deriving (Int -> FnInfo -> ShowS
[FnInfo] -> ShowS
FnInfo -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [FnInfo] -> ShowS
$cshowList :: [FnInfo] -> ShowS
show :: FnInfo -> String
$cshow :: FnInfo -> String
showsPrec :: Int -> FnInfo -> ShowS
$cshowsPrec :: Int -> FnInfo -> ShowS
Show, 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
$cto :: forall x. Rep FnInfo x -> FnInfo
$cfrom :: forall x. FnInfo -> Rep FnInfo x
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
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [OptInfo] -> ShowS
$cshowList :: [OptInfo] -> ShowS
show :: OptInfo -> String
$cshow :: OptInfo -> String
showsPrec :: Int -> OptInfo -> ShowS
$cshowsPrec :: Int -> OptInfo -> ShowS
Show, 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
$cto :: forall x. Rep OptInfo x -> OptInfo
$cfrom :: forall x. OptInfo -> Rep OptInfo x
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
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
showList :: [DSL' t] -> ShowS
$cshowList :: forall t. Show t => [DSL' t] -> ShowS
show :: DSL' t -> String
$cshow :: forall t. Show t => DSL' t -> String
showsPrec :: Int -> DSL' t -> ShowS
$cshowsPrec :: forall t. Show t => Int -> DSL' t -> ShowS
Show, 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
<$ :: forall a b. a -> DSL' b -> DSL' a
$c<$ :: forall a b. a -> DSL' b -> DSL' a
fmap :: forall a b. (a -> b) -> DSL' a -> DSL' b
$cfmap :: forall a b. (a -> b) -> DSL' a -> DSL' b
Functor, 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
$cto :: forall t x. Rep (DSL' t) x -> DSL' t
$cfrom :: forall t x. DSL' t -> Rep (DSL' t) x
Generic)
{-!
deriving instance Binary DSL'
!-}

type DSL = DSL' PTerm

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

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

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

syntaxSymbols :: Syntax -> [SSymbol]
syntaxSymbols :: Syntax -> [SSymbol]
syntaxSymbols (Rule [SSymbol]
ss PTerm
_ SynContext
_) = [SSymbol]
ss
syntaxSymbols (DeclRule [SSymbol]
ss [PDecl]
_) = [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
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [SSymbol] -> ShowS
$cshowList :: [SSymbol] -> ShowS
show :: SSymbol -> String
$cshow :: SSymbol -> String
showsPrec :: Int -> SSymbol -> ShowS
$cshowsPrec :: Int -> SSymbol -> ShowS
Show, SSymbol -> SSymbol -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: SSymbol -> SSymbol -> Bool
$c/= :: SSymbol -> SSymbol -> Bool
== :: SSymbol -> SSymbol -> Bool
$c== :: SSymbol -> SSymbol -> Bool
Eq, 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
$cto :: forall x. Rep SSymbol x -> SSymbol
$cfrom :: forall x. SSymbol -> Rep SSymbol x
Generic)


{-!
deriving instance Binary SSymbol
!-}

newtype SyntaxRules = SyntaxRules { SyntaxRules -> [Syntax]
syntaxRulesList :: [Syntax] }
  deriving 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
$cto :: forall x. Rep SyntaxRules x -> SyntaxRules
$cfrom :: forall x. SyntaxRules -> Rep SyntaxRules x
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 = forall a. (a -> a -> Ordering) -> [a] -> [a]
sortBy ([SSymbol] -> [SSymbol] -> Ordering
ruleSort forall b c a. (b -> b -> c) -> (a -> b) -> a -> a -> c
`on` Syntax -> [SSymbol]
syntaxSymbols) ([Syntax]
rules 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)        = 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)          = 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)        = 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)              = 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)  = forall a. Ord a => a -> a -> Ordering
compare Name
e1 Name
e2

initDSL :: DSL
initDSL = 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"))
              forall a. Maybe a
Nothing
              forall a. Maybe a
Nothing
              forall a. Maybe a
Nothing
              forall a. Maybe a
Nothing
              forall a. Maybe a
Nothing
              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
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Using] -> ShowS
$cshowList :: [Using] -> ShowS
show :: Using -> String
$cshow :: Using -> String
showsPrec :: Int -> Using -> ShowS
$cshowsPrec :: Int -> Using -> ShowS
Show, Using -> Using -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Using -> Using -> Bool
$c/= :: Using -> Using -> Bool
== :: Using -> Using -> Bool
$c== :: Using -> Using -> Bool
Eq, Typeable 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)
gmapMo :: 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
gmapMp :: forall (m :: * -> *).
MonadPlus 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
gmapM :: forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> Using -> m Using
$cgmapM :: forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> Using -> m Using
gmapQi :: forall u. Int -> (forall d. Data d => d -> u) -> Using -> u
$cgmapQi :: forall u. Int -> (forall d. Data d => d -> u) -> Using -> u
gmapQ :: forall u. (forall d. Data d => d -> u) -> Using -> [u]
$cgmapQ :: forall u. (forall d. Data d => d -> u) -> Using -> [u]
gmapQr :: 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
gmapQl :: forall r r'.
(r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> Using -> r
$cgmapQl :: forall r r'.
(r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> Using -> r
gmapT :: (forall b. Data b => b -> b) -> Using -> Using
$cgmapT :: (forall b. Data b => b -> b) -> Using -> Using
dataCast2 :: forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c Using)
$cdataCast2 :: forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c Using)
dataCast1 :: forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c Using)
$cdataCast1 :: forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c Using)
dataTypeOf :: Using -> DataType
$cdataTypeOf :: Using -> DataType
toConstr :: Using -> Constr
$ctoConstr :: Using -> Constr
gunfold :: forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c Using
$cgunfold :: forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c Using
gfoldl :: forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> Using -> c Using
$cgfoldl :: forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> Using -> c Using
Data, 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
$cto :: forall x. Rep Using x -> Using
$cfrom :: forall x. Using -> Rep Using x
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
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [SyntaxInfo] -> ShowS
$cshowList :: [SyntaxInfo] -> ShowS
show :: SyntaxInfo -> String
$cshow :: SyntaxInfo -> String
showsPrec :: Int -> SyntaxInfo -> ShowS
$cshowsPrec :: Int -> SyntaxInfo -> ShowS
Show, 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
$cto :: forall x. Rep SyntaxInfo x -> SyntaxInfo
$cfrom :: forall x. SyntaxInfo -> Rep SyntaxInfo x
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 [] [] [] [] [] forall a. a -> a
id Bool
False Bool
False Bool
False 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 = 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)
                      [(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) [forall {t}. Name -> t -> Bool -> PArg' t
pimp (Int -> String -> Name
sMN Int
0 String
"iType") PTerm
Placeholder Bool
True, forall {t}. t -> PArg' t
pexp PTerm
t]
infP :: Term
infP = forall n. NameType -> n -> TT n -> TT n
P (Int -> Int -> NameType
TCon Int
6 Int
0) Name
inferTy (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) = forall n. n -> Binder (TT n) -> TT n -> TT n
Bind Name
n Binder Term
b 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)  = forall n. n -> Binder (TT n) -> TT n -> TT n
Bind Name
n (forall {n}. Binder (TT n) -> Binder (TT n)
toTy Binder Term
b) 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)      = forall b. RigCount -> Maybe ImplicitInfo -> b -> b -> Binder b
Pi RigCount
r forall a. Maybe a
Nothing TT n
t (forall n. UExp -> TT n
TType (String -> Int -> UExp
UVar [] Int
0))
        toTy (PVar RigCount
_ TT n
t)     = 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 = forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (forall a b. a -> b -> a
const forall a b. (a -> b) -> a -> b
$ forall t. String -> Err' t
Msg String
"") forall b c a. (b -> c) -> (a -> b) -> a -> c
. Text -> Docstring ()
parseDocstring forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> Text
T.pack forall a b. (a -> b) -> a -> b
$
             String
"The empty type, also known as the trivially false proposition." forall a. [a] -> [a] -> [a]
++
             String
"\n\n" forall a. [a] -> [a] -> [a]
++
             String
"Use `void` or `absurd` to prove anything if you have a variable " 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 = forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (forall a b. a -> b -> a
const (forall a b. a -> Either a b
Left forall a b. (a -> b) -> a -> b
$ forall t. String -> Err' t
Msg String
"")) forall b c a. (b -> c) -> (a -> b) -> a -> c
. Text -> Docstring ()
parseDocstring forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> Text
T.pack forall a b. (a -> b) -> a -> b
$
          String
"The propositional equality type. A proof that `x` = `y`." forall a. [a] -> [a] -> [a]
++
          String
"\n\n" forall a. [a] -> [a] -> [a]
++
          String
"To use such a proof, pattern-match on it, and the two equal things will " forall a. [a] -> [a] -> [a]
++
          String
"then need to be the _same_ pattern." forall a. [a] -> [a] -> [a]
++
          String
"\n\n" forall a. [a] -> [a] -> [a]
++
          String
"**Note**: Idris's equality type is potentially _heterogeneous_, which means that it " forall a. [a] -> [a] -> [a]
++
          String
"is possible to state equalities between values of potentially different " forall a. [a] -> [a] -> [a]
++
          String
"types. However, Idris will attempt the homogeneous case unless it fails to typecheck." forall a. [a] -> [a] -> [a]
++
          String
"\n\n" forall a. [a] -> [a] -> [a]
++
          String
"You may need to use `(~=~)` to explicitly request heterogeneous equality."

eqDecl :: PData
eqDecl = 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)))
                [(forall {t} {b}. Docstring (Either (Err' t) b)
reflDoc, 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) [forall {t}. Name -> t -> Bool -> PArg' t
pimp (String -> Name
n String
"A") PTerm
Placeholder Bool
False,
                                                                     forall {t}. Name -> t -> Bool -> PArg' t
pimp (String -> Name
n String
"B") PTerm
Placeholder Bool
False,
                                                                     forall {t}. t -> PArg' t
pexp (FC -> [FC] -> Name -> PTerm
PRef FC
bi [] (String -> Name
n String
"x")),
                                                                     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 = forall a b. (String -> b) -> Docstring a -> Docstring b
annotCode (forall a b. a -> b -> a
const (forall a b. a -> Either a b
Left forall a b. (a -> b) -> a -> b
$ forall t. String -> Err' t
Msg String
"")) forall b c a. (b -> c) -> (a -> b) -> a -> c
. Text -> Docstring ()
parseDocstring forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> Text
T.pack forall a b. (a -> b) -> a -> b
$
                      String
"A proof that `x` in fact equals `x`. To construct this, you must have already " 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",  forall a b. (String -> b) -> Docstring a -> Docstring b
annotCode (forall a b. a -> b -> a
const (forall a b. a -> Either a b
Left forall a b. (a -> b) -> a -> b
$ forall t. String -> Err' t
Msg String
"")) forall b c a. (b -> c) -> (a -> b) -> a -> c
. Text -> Docstring ()
parseDocstring forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> Text
T.pack forall a b. (a -> b) -> a -> b
$ String
"the type at which the equality is proven"),
                          (String -> Name
n String
"x",  forall a b. (String -> b) -> Docstring a -> Docstring b
annotCode (forall a b. a -> b -> a
const (forall a b. a -> Either a b
Left forall a b. (a -> b) -> a -> b
$ forall t. String -> Err' t
Msg String
"")) forall b c a. (b -> c) -> (a -> b) -> a -> c
. Text -> Docstring ()
parseDocstring forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> Text
T.pack 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", forall a b. (String -> b) -> Docstring a -> Docstring b
annotCode (forall a b. a -> b -> a
const (forall a b. a -> Either a b
Left forall a b. (a -> b) -> a -> b
$ forall t. String -> Err' t
Msg String
"")) forall b c a. (b -> c) -> (a -> b) -> a -> c
. Text -> Docstring ()
parseDocstring forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> Text
T.pack forall a b. (a -> b) -> a -> b
$ String
"the type of the left side of the equality"),
              (String -> Name
n String
"B", forall a b. (String -> b) -> Docstring a -> Docstring b
annotCode (forall a b. a -> b -> a
const (forall a b. a -> Either a b
Left forall a b. (a -> b) -> a -> b
$ forall t. String -> Err' t
Msg String
"")) forall b c a. (b -> c) -> (a -> b) -> a -> c
. Text -> Docstring ()
parseDocstring forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> Text
T.pack 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 = (forall a. SimpleDoc a -> ShowS
displayS forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. Float -> Int -> Doc a -> SimpleDoc a
renderPretty Float
1.0 Int
10000000 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 -> ShowS
showsPrec Int
_ PDecl
d = (forall a. SimpleDoc a -> ShowS
displayS forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. Float -> Int -> Doc a -> SimpleDoc a
renderPretty Float
1.0 Int
10000000 forall b c a. (b -> c) -> (a -> b) -> a -> c
. PPOption -> PDecl -> Doc OutputAnnotation
showDeclImp PPOption
verbosePPOption) PDecl
d

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

instance Show PData where
  showsPrec :: Int -> PData -> ShowS
showsPrec Int
_ PData
d = (forall a. SimpleDoc a -> ShowS
displayS forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. Float -> Int -> Doc a -> SimpleDoc a
renderPretty Float
1.0 Int
10000000 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) = forall a. Maybe a
Nothing
annotationColour IState
ist (AnnConst Const
c) =
    let theme :: ColourTheme
theme = IState -> ColourTheme
idris_colourTheme IState
ist
    in forall a. a -> Maybe a
Just 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
_)          = forall a. a -> Maybe a
Just forall a b. (a -> b) -> a -> b
$ ColourTheme -> IdrisColour
dataColour (IState -> ColourTheme
idris_colourTheme IState
ist)
annotationColour IState
ist (AnnType String
_ String
_)          = forall a. a -> Maybe a
Just forall a b. (a -> b) -> a -> b
$ ColourTheme -> IdrisColour
typeColour (IState -> ColourTheme
idris_colourTheme IState
ist)
annotationColour IState
ist (AnnBoundName Name
_ Bool
True)  = forall a. a -> Maybe a
Just forall a b. (a -> b) -> a -> b
$ ColourTheme -> IdrisColour
implicitColour (IState -> ColourTheme
idris_colourTheme IState
ist)
annotationColour IState
ist (AnnBoundName Name
_ Bool
False) = forall a. a -> Maybe a
Just forall a b. (a -> b) -> a -> b
$ ColourTheme -> IdrisColour
boundVarColour (IState -> ColourTheme
idris_colourTheme IState
ist)
annotationColour IState
ist OutputAnnotation
AnnKeyword             = forall a. a -> Maybe a
Just 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     -> forall a. a -> Maybe a
Just forall a b. (a -> b) -> a -> b
$ ColourTheme -> IdrisColour
dataColour ColourTheme
theme
       ()
_ | Name -> Context -> Bool
isFnName Name
n Context
ctxt       -> forall a. a -> Maybe a
Just forall a b. (a -> b) -> a -> b
$ ColourTheme -> IdrisColour
functionColour ColourTheme
theme
       ()
_ | Name -> Context -> Bool
isTConName Name
n Context
ctxt     -> forall a. a -> Maybe a
Just forall a b. (a -> b) -> a -> b
$ ColourTheme -> IdrisColour
typeColour ColourTheme
theme
       ()
_ | Name -> IState -> Bool
isPostulateName Name
n IState
ist -> forall a. a -> Maybe a
Just forall a b. (a -> b) -> a -> b
$ ColourTheme -> IdrisColour
postulateColour ColourTheme
theme
       ()
_ | Bool
otherwise             -> forall a. Maybe a
Nothing -- don't colourise unknown names
annotationColour IState
ist (AnnTextFmt TextFormatting
fmt) = 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 forall a. Maybe a
Nothing Bool
True Bool
False Bool
True Bool
False
        colour TextFormatting
UnderlineText = Maybe Color -> Bool -> Bool -> Bool -> Bool -> IdrisColour
IdrisColour forall a. Maybe a
Nothing Bool
True Bool
True Bool
False Bool
False
        colour TextFormatting
ItalicText    = Maybe Color -> Bool -> Bool -> Bool -> Bool -> IdrisColour
IdrisColour forall a. Maybe a
Nothing Bool
True Bool
False Bool
False Bool
True
annotationColour IState
ist OutputAnnotation
_ = 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 = forall b a. b -> (a -> b) -> Maybe a -> b
maybe 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 = 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 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 :: Bool
ppopt_displayrig = Bool
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 = forall a. a -> Doc a -> Doc a
annotate (String -> OutputAnnotation
AnnSyntax String
"{") (forall a. String -> Doc a
text String
"{")
    rbrace :: Doc OutputAnnotation
rbrace = forall a. a -> Doc a -> Doc a
annotate (String -> OutputAnnotation
AnnSyntax String
"}") (forall a. String -> Doc a
text String
"}")
    percent :: Doc OutputAnnotation
percent = forall a. a -> Doc a -> Doc a
annotate (String -> OutputAnnotation
AnnSyntax String
"%") (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) =
        forall a. String -> Doc a
text String
"![" forall a. Doc a -> Doc a -> Doc a
<> forall a ty. Pretty a ty => a -> Doc ty
pretty Raw
r forall a. Doc a -> Doc a -> Doc a
<> forall a. String -> Doc a
text String
"]"
    prettySe Maybe Int
d Int
p [(Name, Bool)]
bnd (PPatvar FC
fc Name
n) = 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 = 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 = forall {a} {a}. (Ord a, Num a) => Maybe a -> Doc a -> Doc a
depth Maybe Int
d forall a b. (a -> b) -> a -> b
$ forall a. a -> Doc a -> Doc a
annotate (String -> String -> OutputAnnotation
AnnData String
"Nat" String
"") (forall a. String -> Doc a
text (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
          forall {a} {a}. (Ord a, Num a) => Maybe a -> Doc a -> Doc a
depth Maybe Int
d forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall {a} {a}. Ord a => a -> a -> Doc a -> Doc a
bracket Int
p Int
startPrec forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. Doc a -> Doc a
group forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. Doc a -> Doc a
align forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. Int -> Doc a -> Doc a
hang Int
2 forall a b. (a -> b) -> a -> b
$
          (forall a. a -> Doc a -> Doc a
annotate (String -> OutputAnnotation
AnnSyntax String
"\\") (forall a. String -> Doc a
text String
"\\"))
          forall a. Doc a -> Doc a -> Doc a
<> [Name] -> Bool -> Doc OutputAnnotation
prettyBindingsOf [Name]
ns Bool
False forall a. Doc a -> Doc a -> Doc a
<+> forall a. String -> Doc a
text String
"=>" 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)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 forall a. a -> [a] -> [a]
: [Name]
acc) PTerm
sc
        getLamNames [Name]
acc PTerm
sc = (forall a. [a] -> [a]
reverse [Name]
acc, PTerm
sc)

        prettyBindingsOf :: [Name] -> Bool -> Doc OutputAnnotation
prettyBindingsOf [] Bool
t = 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 forall a. Doc a -> Doc a -> Doc a
<> forall a. String -> Doc a
text String
"," 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) =
      forall {a} {a}. (Ord a, Num a) => Maybe a -> Doc a -> Doc a
depth Maybe Int
d forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall {a} {a}. Ord a => a -> a -> Doc a -> Doc a
bracket Int
p Int
startPrec forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. Doc a -> Doc a
group forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. Doc a -> Doc a
align forall a b. (a -> b) -> a -> b
$
      String -> Doc OutputAnnotation
kwd String
"let" forall a. Doc a -> Doc a -> Doc a
<+> (forall a. Doc a -> Doc a
group forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. Doc a -> Doc a
align forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. Int -> Doc a -> Doc a
hang Int
2 forall a b. (a -> b) -> a -> b
$ Name -> Bool -> Doc OutputAnnotation
prettyBindingOf Name
n Bool
False forall a. Doc a -> Doc a -> Doc a
<+> forall a. String -> Doc a
text String
"=" 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) forall a. Doc a -> Doc a -> Doc a
</>
      String -> Doc OutputAnnotation
kwd String
"in" forall a. Doc a -> Doc a -> Doc a
<+> (forall a. Doc a -> Doc a
group forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. Doc a -> Doc a
align forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. Int -> Doc a -> Doc a
hang Int
2 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)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 =
          forall {a} {a}. (Ord a, Num a) => Maybe a -> Doc a -> Doc a
depth Maybe Int
d forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall {a} {a}. Ord a => a -> a -> Doc a -> Doc a
bracket Int
p Int
startPrec forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. Doc a -> Doc a
group forall a b. (a -> b) -> a -> b
$
          forall a. Doc a -> Doc a -> Doc a -> Doc a
enclose forall a. Doc a
lparen forall a. Doc a
rparen (forall a. Doc a -> Doc a
group forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. Doc a -> Doc a
align forall a b. (a -> b) -> a -> b
$ forall a. String -> Doc a
text String
"0" forall a. Doc a -> Doc a -> Doc a
<+> Name -> Bool -> Doc OutputAnnotation
prettyBindingOf Name
n Bool
False forall a. Doc a -> Doc a -> Doc a
<+> forall a. Doc a
colon 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) forall a. Doc a -> Doc a -> Doc a
<+>
          Doc OutputAnnotation
st forall a. Doc a -> Doc a -> Doc a
<> forall a. String -> Doc a
text String
"->" 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)forall a. a -> [a] -> [a]
:[(Name, Bool)]
bnd) PTerm
sc
      | RigCount
Rig1 <- RigCount
rig, PPOption -> Bool
ppopt_displayrig PPOption
ppo =
          forall {a} {a}. (Ord a, Num a) => Maybe a -> Doc a -> Doc a
depth Maybe Int
d forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall {a} {a}. Ord a => a -> a -> Doc a -> Doc a
bracket Int
p Int
startPrec forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. Doc a -> Doc a
group forall a b. (a -> b) -> a -> b
$
          forall a. Doc a -> Doc a -> Doc a -> Doc a
enclose forall a. Doc a
lparen forall a. Doc a
rparen (forall a. Doc a -> Doc a
group forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. Doc a -> Doc a
align forall a b. (a -> b) -> a -> b
$ forall a. String -> Doc a
text String
"1" forall a. Doc a -> Doc a -> Doc a
<+> Name -> Bool -> Doc OutputAnnotation
prettyBindingOf Name
n Bool
False forall a. Doc a -> Doc a -> Doc a
<+> forall a. Doc a
colon 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) forall a. Doc a -> Doc a -> Doc a
<+>
          Doc OutputAnnotation
st forall a. Doc a -> Doc a -> Doc a
<> forall a. String -> Doc a
text String
"->" 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)forall a. a -> [a] -> [a]
:[(Name, Bool)]
bnd) PTerm
sc
      | Name
n 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 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 =
          forall {a} {a}. (Ord a, Num a) => Maybe a -> Doc a -> Doc a
depth Maybe Int
d forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall {a} {a}. Ord a => a -> a -> Doc a -> Doc a
bracket Int
p Int
startPrec forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. Doc a -> Doc a
group forall a b. (a -> b) -> a -> b
$
          forall a. Doc a -> Doc a -> Doc a -> Doc a
enclose forall a. Doc a
lparen forall a. Doc a
rparen (forall a. Doc a -> Doc a
group forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. Doc a -> Doc a
align forall a b. (a -> b) -> a -> b
$ Name -> Bool -> Doc OutputAnnotation
prettyBindingOf Name
n Bool
False forall a. Doc a -> Doc a -> Doc a
<+> forall a. Doc a
colon 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) forall a. Doc a -> Doc a -> Doc a
<+>
          Doc OutputAnnotation
st forall a. Doc a -> Doc a -> Doc a
<> forall a. String -> Doc a
text String
"->" 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)forall a. a -> [a] -> [a]
:[(Name, Bool)]
bnd) PTerm
sc
      | Bool
otherwise                      =
          forall {a} {a}. (Ord a, Num a) => Maybe a -> Doc a -> Doc a
depth Maybe Int
d forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall {a} {a}. Ord a => a -> a -> Doc a -> Doc a
bracket Int
p Int
startPrec forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. Doc a -> Doc a
group forall a b. (a -> b) -> a -> b
$
          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 forall a. Num a => a -> a -> a
+ Int
1) [(Name, Bool)]
bnd PTerm
ty forall a. Doc a -> Doc a -> Doc a
<+> Doc OutputAnnotation
st) forall a. Doc a -> Doc a -> Doc a
<> forall a. String -> Doc a
text String
"->" forall a. Doc a -> Doc a -> Doc a
<$>
          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)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 forall a. Doc a -> Doc a -> Doc a
<> forall a. String -> Doc a
text String
"static" forall a. Doc a -> Doc a -> Doc a
<> forall a. Doc a
space
            Static
_      -> 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 =
          forall {a} {a}. (Ord a, Num a) => Maybe a -> Doc a -> Doc a
depth Maybe Int
d forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall {a} {a}. Ord a => a -> a -> Doc a -> Doc a
bracket Int
p Int
startPrec forall a b. (a -> b) -> a -> b
$
          Doc OutputAnnotation
lbrace forall a. Doc a -> Doc a -> Doc a
<> RigCount -> Name -> Doc OutputAnnotation
showRig RigCount
rig Name
n forall a. Doc a -> Doc a -> Doc a
<+> forall a. Doc a
colon 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 forall a. Doc a -> Doc a -> Doc a
<> Doc OutputAnnotation
rbrace forall a. Doc a -> Doc a -> Doc a
<+>
          Doc OutputAnnotation
st forall a. Doc a -> Doc a -> Doc a
<> forall a. String -> Doc a
text String
"->" 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)forall a. a -> [a] -> [a]
:[(Name, Bool)]
bnd) PTerm
sc
      | PTerm -> Bool
isPi PTerm
sc = forall {a} {a}. (Ord a, Num a) => Maybe a -> Doc a -> Doc a
depth Maybe Int
d forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall {a} {a}. Ord a => a -> a -> Doc a -> Doc a
bracket Int
p Int
startPrec 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)forall a. a -> [a] -> [a]
:[(Name, Bool)]
bnd) PTerm
sc
      | Bool
otherwise = forall {a} {a}. (Ord a, Num a) => Maybe a -> Doc a -> Doc a
depth Maybe Int
d 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)forall a. a -> [a] -> [a]
:[(Name, Bool)]
bnd) PTerm
sc
      where
        showRig :: RigCount -> Name -> Doc OutputAnnotation
showRig RigCount
Rig0 Name
n = forall a. String -> Doc a
text String
"0" forall a. Doc a -> Doc a -> Doc a
<+> Name -> Bool -> Doc OutputAnnotation
prettyBindingOf Name
n Bool
True
        showRig RigCount
Rig1 Name
n = forall a. String -> Doc a
text String
"1" 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 forall a. Doc a -> Doc a -> Doc a
<> forall a. String -> Doc a
text String
"static" forall a. Doc a -> Doc a -> Doc a
<> forall a. Doc a
space
            Static
_      -> 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) =
      forall {a} {a}. (Ord a, Num a) => Maybe a -> Doc a -> Doc a
depth Maybe Int
d forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall {a} {a}. Ord a => a -> a -> Doc a -> Doc a
bracket Int
p Int
startPrec 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 forall a. Num a => a -> a -> a
+ Int
1) [(Name, Bool)]
bnd PTerm
ty forall a. Doc a -> Doc a -> Doc a
<+> forall a. String -> Doc a
text String
"=>" 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)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 forall a. Doc a -> Doc a -> Doc a
<> String -> Doc OutputAnnotation
kwd String
"auto" forall a. Doc a -> Doc a -> Doc a
<+> forall a ty. Pretty a ty => a -> Doc ty
pretty Name
n forall a. Doc a -> Doc a -> Doc a
<+> forall a. Doc a
colon 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 forall a. Doc a -> Doc a -> Doc a
<>
      Doc OutputAnnotation
rbrace forall a. Doc a -> Doc a -> Doc a
<+> forall a. String -> Doc a
text String
"->" 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)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) =
      forall {a} {a}. (Ord a, Num a) => Maybe a -> Doc a -> Doc a
depth Maybe Int
d forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall {a} {a}. Ord a => a -> a -> Doc a -> Doc a
bracket Int
p Int
startPrec forall a b. (a -> b) -> a -> b
$
      Doc OutputAnnotation
lbrace forall a. Doc a -> Doc a -> Doc a
<> String -> Doc OutputAnnotation
kwd String
"default" 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 forall a. Num a => a -> a -> a
+ Int
1) [(Name, Bool)]
bnd PTerm
s forall a. Doc a -> Doc a -> Doc a
<+> forall a ty. Pretty a ty => a -> Doc ty
pretty Name
n forall a. Doc a -> Doc a -> Doc a
<+> forall a. Doc a
colon 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 forall a. Doc a -> Doc a -> Doc a
<>
      Doc OutputAnnotation
rbrace forall a. Doc a -> Doc a -> Doc a
<+> forall a. String -> Doc a
text String
"->" 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)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 forall a. Eq a => a -> a -> Bool
== String -> Name
sUN String
"negate" =
         forall a. Doc a
lparen forall a. Doc a -> Doc a -> Doc a
<> forall a. String -> Doc a
text String
"-" 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 (forall t. PArg' t -> t
getTm PArg
val) forall a. Doc a -> Doc a -> Doc a
<> 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 forall a. Eq a => a -> a -> Bool
== Name
eqTy, PPOption -> Bool
ppopt_impl PPOption
ppo =
          forall {a} {a}. (Ord a, Num a) => Maybe a -> Doc a -> Doc a
depth Maybe Int
d forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall {a} {a}. Ord a => a -> a -> Doc a -> Doc a
bracket Int
p Int
eqPrec forall a b. (a -> b) -> a -> b
$
            forall a. Doc a -> Doc a -> Doc a -> Doc a
enclose forall a. Doc a
lparen forall a. Doc a
rparen Doc OutputAnnotation
eq forall a. Doc a -> Doc a -> Doc a
<+>
            forall a. Doc a -> Doc a
align (forall a. Doc a -> Doc a
group (forall a. [Doc a] -> Doc a
vsep (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 forall a. Eq a => a -> a -> Bool
== Name
eqTy =
          forall {a} {a}. (Ord a, Num a) => Maybe a -> Doc a -> Doc a
depth Maybe Int
d forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall {a} {a}. Ord a => a -> a -> Doc a -> Doc a
bracket Int
p Int
eqPrec forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. Doc a -> Doc a
align forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. Doc a -> Doc a
group forall a b. (a -> b) -> a -> b
$
            PTerm -> Doc OutputAnnotation
prettyTerm (forall t. PArg' t -> t
getTm PArg
l) forall a. Doc a -> Doc a -> Doc a
<+> Doc OutputAnnotation
eq forall a. Doc a -> Doc a -> Doc a
<$> forall a. Doc a -> Doc a
group (PTerm -> Doc OutputAnnotation
prettyTerm (forall t. PArg' t -> t
getTm PArg
r))
      where eq :: Doc OutputAnnotation
eq = Name -> Doc OutputAnnotation -> Doc OutputAnnotation
annName Name
eqTy (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 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
&& 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) = forall a. String -> Doc a
text String
"!" 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 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] -> forall a. Doc a -> Doc a
group (Bool -> Doc OutputAnnotation
opName Bool
True forall a. Doc a -> Doc a -> Doc a
<$> 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 (forall t. PArg' t -> t
getTm PArg
x)))
            [PArg
l,PArg
r] -> let precedence :: Int
precedence = forall b a. b -> (a -> b) -> Maybe a -> b
maybe (Int
startPrec forall a. Num a => a -> a -> a
- Int
1) Fixity -> Int
prec Maybe Fixity
f
                     in forall {a} {a}. (Ord a, Num a) => Maybe a -> Doc a -> Doc a
depth Maybe Int
d forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall {a} {a}. Ord a => a -> a -> Doc a -> Doc a
bracket Int
p Int
precedence forall a b. (a -> b) -> a -> b
$ PTerm -> PTerm -> Doc OutputAnnotation
inFix (forall t. PArg' t -> t
getTm PArg
l) (forall t. PArg' t -> t
getTm PArg
r)
            (l :: PArg
l@(PExp{}) : r :: PArg
r@(PExp{}) : [PArg]
rest) ->
                   forall {a} {a}. (Ord a, Num a) => Maybe a -> Doc a -> Doc a
depth Maybe Int
d forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall {a} {a}. Ord a => a -> a -> Doc a -> Doc a
bracket Int
p Int
funcAppPrec forall a b. (a -> b) -> a -> b
$
                          forall a. Doc a -> Doc a -> Doc a -> Doc a
enclose forall a. Doc a
lparen forall a. Doc a
rparen (PTerm -> PTerm -> Doc OutputAnnotation
inFix (forall t. PArg' t -> t
getTm PArg
l) (forall t. PArg' t -> t
getTm PArg
r)) forall a. Doc a -> Doc a -> Doc a
<+>
                          forall a. Doc a -> Doc a
align (forall a. Doc a -> Doc a
group (forall a. [Doc a] -> Doc a
vsep (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 forall a. Doc a -> Doc a -> Doc a
<+> forall a. Doc a -> Doc a
align (forall a. [Doc a] -> Doc a
vsep (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 forall a. Num a => a -> a -> a
+ Int
1
                           Just (Infixl Int
p') -> Int
p'
                           Just Fixity
f' -> Fixity -> Int
prec Fixity
f' forall a. Num a => a -> a -> a
+ Int
1
                right :: Int
right = case Maybe Fixity
f of
                            Maybe Fixity
Nothing -> Int
funcAppPrec forall a. Num a => a -> a -> a
+ Int
1
                            Just (Infixr Int
p') -> Int
p'
                            Just Fixity
f' -> Fixity -> Int
prec Fixity
f' forall a. Num a => a -> a -> a
+ Int
1
                inFix :: PTerm -> PTerm -> Doc OutputAnnotation
inFix PTerm
l PTerm
r = forall a. Doc a -> Doc a
align forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. Doc a -> Doc a
group 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 forall a. Doc a -> Doc a -> Doc a
<+> Bool -> Doc OutputAnnotation
opName Bool
False) forall a. Doc a -> Doc a -> Doc a
<$>
                    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) <- forall t. PArg' t -> t
getTm PArg
tm,
        Name
f forall a. Eq a => a -> a -> Bool
== String -> Name
sUN String
"Symbol_" = forall a. a -> Doc a -> Doc a
annotate (String -> String -> OutputAnnotation
AnnType (String
"'" forall a. [a] -> [a] -> [a]
++ String
str) (String
"The symbol " forall a. [a] -> [a] -> [a]
++ String
str)) forall a b. (a -> b) -> a -> b
$
                               forall a. Char -> Doc a
char Char
'\'' 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 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
        forall {a} {a}. (Ord a, Num a) => Maybe a -> Doc a -> Doc a
depth Maybe Int
d forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall {a} {a}. Ord a => a -> a -> Doc a -> Doc a
bracket Int
p Int
funcAppPrec forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. Doc a -> Doc a
group forall a b. (a -> b) -> a -> b
$
            if forall (t :: * -> *) a. Foldable t => t a -> Bool
null [PArg]
shownArgs
              then Doc OutputAnnotation
fp
              else Doc OutputAnnotation
fp forall a. Doc a -> Doc a -> Doc a
<+> forall a. Doc a -> Doc a
align (forall a. [Doc a] -> Doc a
vsep (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 forall a. Doc a -> Doc a -> Doc a
<+> forall a. String -> Doc a
text String
"|" 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) =
      forall {a} {a}. Ord a => a -> a -> Doc a -> Doc a
bracket Int
p Int
funcAppPrec forall a b. (a -> b) -> a -> b
$
          forall a. Doc a -> Doc a
align forall a b. (a -> b) -> a -> b
$ String -> Doc OutputAnnotation
kwd String
"case" 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 forall a. Doc a -> Doc a -> Doc a
<+> String -> Doc OutputAnnotation
kwd String
"of" forall a. Doc a -> Doc a -> Doc a
<$>
          forall {a} {a}. (Ord a, Num a) => Maybe a -> Doc a -> Doc a
depth Maybe Int
d (forall a. Int -> Doc a -> Doc a
indent Int
2 (forall a. [Doc a] -> Doc a
vsep (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] forall a. [a] -> [a] -> [a]
++ [(Name, Bool)]
bnd)
                        in forall a. Int -> Doc a -> Doc a
nest Int
nestingSize forall a b. (a -> b) -> a -> b
$
                             PTerm -> Doc OutputAnnotation
prettyCase PTerm
l forall a. Doc a -> Doc a -> Doc a
<+> forall a. String -> Doc a
text String
"=>" 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 = 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) =
      forall {a} {a}. (Ord a, Num a) => Maybe a -> Doc a -> Doc a
depth Maybe Int
d forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall {a} {a}. Ord a => a -> a -> Doc a -> Doc a
bracket Int
p Int
funcAppPrec forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. Doc a -> Doc a
group forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. Doc a -> Doc a
align forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. Int -> Doc a -> Doc a
hang Int
2 forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. [Doc a] -> Doc a
vsep forall a b. (a -> b) -> a -> b
$
        [ String -> Doc OutputAnnotation
kwd String
"if"   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" 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" 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)         = forall a. String -> Doc a
text String
"." 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 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 forall a b. (a -> b) -> a -> b
$ 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 forall a b. (a -> b) -> a -> b
$ forall a. String -> Doc a
text String
"()"
    prettySe Maybe Int
d Int
p [(Name, Bool)]
bnd (PTrue FC
_ PunInfo
TypeOrTerm) = 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
_)   =
      forall {a} {a}. (Ord a, Num a) => Maybe a -> Doc a -> Doc a
depth Maybe Int
d forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall {a} {a}. Ord a => a -> a -> Doc a -> Doc a
bracket Int
p Int
startPrec forall a b. (a -> b) -> a -> b
$
      forall a. String -> Doc a
text String
"rewrite" 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 forall a. Num a => a -> a -> a
+ Int
1) [(Name, Bool)]
bnd PTerm
l
      forall a. Doc a -> Doc a -> Doc a
<+> (case Maybe Name
by of
               Maybe Name
Nothing -> forall a. Doc a
empty
               Just Name
fn -> forall a. String -> Doc a
text String
"using" 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) forall a. Doc a -> Doc a -> Doc a
<+>
          forall a. String -> Doc a
text String
"in" 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) =
      forall a. Doc a
lparen 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 forall a. Doc a -> Doc a -> Doc a
<+> forall a. Doc a
colon 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 forall a. Doc a -> Doc a -> Doc a
<> 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 = forall {a} {a}. (Ord a, Num a) => Maybe a -> Doc a -> Doc a
depth Maybe Int
d forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. Doc a -> Doc a -> Doc a -> Doc a
enclose (Doc OutputAnnotation -> Doc OutputAnnotation
ann forall a. Doc a
lparen) (Doc OutputAnnotation -> Doc OutputAnnotation
ann forall a. Doc a
rparen) forall b c a. (b -> c) -> (a -> b) -> a -> c
.
                                     forall a. Doc a -> Doc a
align forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. Doc a -> Doc a
group forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. [Doc a] -> Doc a
vsep forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. Doc a -> [Doc a] -> [Doc a]
punctuate (Doc OutputAnnotation -> Doc OutputAnnotation
ann forall a. Doc a
comma) forall a b. (a -> b) -> a -> b
$
                                     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 -> 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
      = forall {a} {a}. (Ord a, Num a) => Maybe a -> Doc a -> Doc a
depth Maybe Int
d forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. Doc a -> Doc a -> Doc a -> Doc a
enclose (Doc OutputAnnotation -> Doc OutputAnnotation
annotated forall a. Doc a
lparen) (Doc OutputAnnotation -> Doc OutputAnnotation
annotated forall a. Doc a
rparen) forall b c a. (b -> c) -> (a -> b) -> a -> c
.
        forall a. Doc a -> Doc a
align forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. Doc a -> Doc a
group forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. [Doc a] -> Doc a
vsep forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. Doc a -> [Doc a] -> [Doc a]
punctuate (forall a. Doc a
space forall a. Doc a -> Doc a -> Doc a
<> Doc OutputAnnotation -> Doc OutputAnnotation
annotated (forall a. String -> Doc a
text String
"**")) forall a b. (a -> b) -> a -> b
$
        [(PTerm, PTerm)] -> [(Name, Bool)] -> [Doc OutputAnnotation]
ppElts [(PTerm, PTerm)]
elts [(Name, Bool)]
bnd
      | Bool
otherwise
      = forall {a} {a}. (Ord a, Num a) => Maybe a -> Doc a -> Doc a
depth Maybe Int
d forall a b. (a -> b) -> a -> b
$
        Doc OutputAnnotation -> Doc OutputAnnotation
annotated forall a. Doc a
lparen forall a. Doc a -> Doc a -> Doc a
<>
        Doc OutputAnnotation
left forall a. Doc a -> Doc a -> Doc a
<+>
        Doc OutputAnnotation -> Doc OutputAnnotation
annotated (forall a. String -> Doc a
text String
"**") 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 forall a. Doc a -> Doc a -> Doc a
<>
        Doc OutputAnnotation -> Doc OutputAnnotation
annotated 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 -> 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 forall a. Doc a -> Doc a -> Doc a
<+> forall a. String -> Doc a
text String
":" 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) 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, 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 forall a. Doc a -> Doc a -> Doc a
<+> forall a. Doc a
colon 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) forall a. a -> [a] -> [a]
: [(PTerm, PTerm)] -> [(Name, Bool)] -> [Doc OutputAnnotation]
ppElts [(PTerm, PTerm)]
rs ((Name
n, Bool
False)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) 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) =
      forall a. Doc a
lparen forall a. Doc a -> Doc a -> Doc a
<> forall a. String -> Doc a
text String
"|" forall a. Doc a -> Doc a -> Doc a
<> Doc OutputAnnotation
prettyAs forall a. Doc a -> Doc a -> Doc a
<> forall a. String -> Doc a
text String
"|" forall a. Doc a -> Doc a -> Doc a
<> forall a. Doc a
rparen
        where
          prettyAs :: Doc OutputAnnotation
prettyAs =
            forall (t :: * -> *) a b.
Foldable t =>
(a -> b -> b) -> b -> t a -> b
foldr ((\ Doc OutputAnnotation
l Doc OutputAnnotation
r -> Doc OutputAnnotation
l forall a. Doc a -> Doc a -> Doc a
<+> forall a. String -> Doc a
text String
"," forall a. Doc a -> Doc a -> Doc a
<+> Doc OutputAnnotation
r) forall b c a. (b -> c) -> (a -> b) -> a -> c
.
                    forall {a} {a}. (Ord a, Num a) => Maybe a -> Doc a -> Doc a
depth Maybe Int
d 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)
                  forall a. Doc a
empty [PTerm]
as
    prettySe Maybe Int
d Int
p [(Name, Bool)]
bnd (PType FC
_)        = forall a. a -> Doc a -> Doc a
annotate (String -> String -> OutputAnnotation
AnnType String
"Type" String
"The type of types") forall a b. (a -> b) -> a -> b
$ forall a. String -> Doc a
text String
"Type"
    prettySe Maybe Int
d Int
p [(Name, Bool)]
bnd (PUniverse FC
_ Universe
u)  = forall a. a -> Doc a -> Doc a
annotate (String -> String -> OutputAnnotation
AnnType (forall a. Show a => a -> String
show Universe
u) String
"The type of unique types") forall a b. (a -> b) -> a -> b
$ forall a. String -> Doc a
text (forall a. Show a => a -> String
show Universe
u)
    prettySe Maybe Int
d Int
p [(Name, Bool)]
bnd (PConstant FC
_ Const
c)  = forall a. a -> Doc a -> Doc a
annotate (Const -> OutputAnnotation
AnnConst Const
c) (forall a. String -> Doc a
text (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" forall a. Doc a -> Doc a -> Doc a
<+> Doc OutputAnnotation
lbrace forall a. Doc a -> Doc a -> Doc a
<> forall a. Doc a
ellipsis 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" forall a. Doc a -> Doc a -> Doc a
<+> Doc OutputAnnotation
lbrace forall a. Doc a -> Doc a -> Doc a
<> forall a. Doc a
ellipsis forall a. Doc a -> Doc a -> Doc a
<> Doc OutputAnnotation
rbrace
    prettySe Maybe Int
d Int
p [(Name, Bool)]
bnd (PMetavar FC
_ Name
n)   = forall a. a -> Doc a -> Doc a
annotate (Name
-> Maybe NameOutput
-> Maybe String
-> Maybe String
-> OutputAnnotation
AnnName Name
n (forall a. a -> Maybe a
Just NameOutput
MetavarOutput) forall a. Maybe a
Nothing forall a. Maybe a
Nothing) forall a b. (a -> b) -> a -> b
$  forall a. String -> Doc a
text String
"?" forall a. Doc a -> Doc a -> Doc a
<> 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      = forall a. String -> Doc a
text String
"_"
    prettySe Maybe Int
d Int
p [(Name, Bool)]
bnd (PDoBlock [PDo]
dos)   =
      forall {a} {a}. Ord a => a -> a -> Doc a -> Doc a
bracket Int
p Int
startPrec forall a b. (a -> b) -> a -> b
$
      String -> Doc OutputAnnotation
kwd String
"do" forall a. Doc a -> Doc a -> Doc a
<+> forall a. Doc a -> Doc a
align (forall a. [Doc a] -> Doc a
vsep (forall a b. (a -> b) -> [a] -> [b]
map (forall a. Doc a -> Doc a
group forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. Doc a -> Doc a
align forall b c a. (b -> c) -> (a -> b) -> a -> c
. 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 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 forall a. Doc a -> Doc a -> Doc a
<+> forall a. String -> Doc a
text String
"<-" forall a. Doc a -> Doc a -> Doc a
<+>
                forall a. Doc a -> Doc a
group (forall a. Doc a -> Doc a
align (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)))) forall a. a -> [a] -> [a]
:
               [(Name, Bool)] -> [PDo] -> [Doc OutputAnnotation]
ppdo ((Name
bn, Bool
False)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
               forall a. String -> Doc a
text String
"no pretty printer for pattern-matching do binding" 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" forall a. Doc a -> Doc a -> Doc a
<+> Name -> Bool -> Doc OutputAnnotation
prettyBindingOf Name
ln Bool
False forall a. Doc a -> Doc a -> Doc a
<+>
                (if PTerm
ty forall a. Eq a => a -> a -> Bool
/= PTerm
Placeholder
                   then forall a. Doc a
colon 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 forall a. Doc a -> Doc a -> Doc a
<+> forall a. String -> Doc a
text String
"="
                   else forall a. String -> Doc a
text String
"=") forall a. Doc a -> Doc a -> Doc a
<+>
                forall a. Doc a -> Doc a
group (forall a. Doc a -> Doc a
align (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)))) forall a. a -> [a] -> [a]
:
               [(Name, Bool)] -> [PDo] -> [Doc OutputAnnotation]
ppdo ((Name
ln, Bool
False)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
               forall a. String -> Doc a
text String
"no pretty printer for pattern-matching do binding" 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
               forall a. String -> Doc a
text String
"no pretty printer for pattern-matching do binding" 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)           = 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)  = forall a. String -> Doc a
text String
"`(" 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 forall a. Doc a -> Doc a -> Doc a
<> forall a. String -> Doc a
text String
")"
    prettySe Maybe Int
d Int
p [(Name, Bool)]
bnd (PQuasiquote PTerm
t (Just PTerm
g)) = forall a. String -> Doc a
text String
"`(" 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 forall a. Doc a -> Doc a -> Doc a
<+> forall a. Doc a
colon 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 forall a. Doc a -> Doc a -> Doc a
<> forall a. String -> Doc a
text String
")"
    prettySe Maybe Int
d Int
p [(Name, Bool)]
bnd (PUnquote PTerm
t)             = forall a. String -> Doc a
text String
"~" 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
_)     = forall a. String -> Doc a
text String
start 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 forall a. Doc a -> Doc a -> Doc a
<> 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]
_)        =
      forall {a} {a}. Ord a => a -> a -> Doc a -> Doc a
bracket Int
p Int
funcAppPrec forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. Doc a -> Doc a
group forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. Doc a -> Doc a
align forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. Int -> Doc a -> Doc a
hang Int
2 forall a b. (a -> b) -> a -> b
$
      (Doc OutputAnnotation
percent forall a. Doc a -> Doc a -> Doc a
<> forall a. String -> Doc a
text String
"runElab") 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
_                        = 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 = forall a. a -> Doc a -> Doc a
annotate (Name -> Bool -> OutputAnnotation
AnnBoundName Name
n Bool
imp) (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) = (forall a. [a] -> [[a]] -> [a]
intercalate String
"." forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a b. (a -> b) -> [a] -> [b]
map Text -> String
T.unpack forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. [a] -> [a]
reverse) [Text]
ns forall a. [a] -> [a] -> [a]
++ String
"." forall a. [a] -> [a] -> [a]
++ Name -> String
display Name
n
            display Name
n         = 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)          = 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)  = 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 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 forall a. Doc a -> Doc a -> Doc a
<> forall a ty. Pretty a ty => a -> Doc ty
pretty a
n forall a. Doc a -> Doc a -> Doc a
<+> forall a. String -> Doc a
text String
"=" 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 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 forall a. Doc a -> Doc a -> Doc a
<> Doc OutputAnnotation
lbrace 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 forall a. Doc a -> Doc a -> Doc a
<> Doc OutputAnnotation
rbrace 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 forall a. Doc a -> Doc a -> Doc a
<> String -> Doc OutputAnnotation
kwd String
"auto" forall a. Doc a -> Doc a -> Doc a
<+> forall a ty. Pretty a ty => a -> Doc ty
pretty a
n forall a. Doc a -> Doc a -> Doc a
<+> forall a. String -> Doc a
text String
"=" 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 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 = forall a. a -> Doc a -> Doc a
annotate (Name
-> Maybe NameOutput
-> Maybe String
-> Maybe String
-> OutputAnnotation
AnnName Name
n forall a. Maybe a
Nothing forall a. Maybe a
Nothing 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 forall a. Ord a => a -> a -> Bool
<= Int
0 = forall a. Maybe a
Nothing
    slist' Maybe Int
d Int
_ [(Name, Bool)]
_ PTerm
e
      | PTerm -> Bool
containsHole PTerm
e = 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 forall a. Eq a => a -> a -> Bool
== String -> Name
sUN String
"Nil" = 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 forall a. Eq a => a -> a -> Bool
== String -> Name
sUN String
"Nil" = 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 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 <- forall a. [a] -> [a]
reverse [PArg]
args,
        forall (t :: * -> *) a. Foldable t => (a -> Bool) -> t a -> Bool
all 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
      = 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 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 = 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 = forall a. a -> Maybe a
Just forall a b. (a -> b) -> a -> b
$
      case [Doc OutputAnnotation]
es of
        [] -> forall a. a -> Doc a -> Doc a
annotate (String -> String -> OutputAnnotation
AnnData String
"" String
"") forall a b. (a -> b) -> a -> b
$ forall a. String -> Doc a
text String
"[]"
        [Doc OutputAnnotation
x] -> forall a. Doc a -> Doc a -> Doc a -> Doc a
enclose Doc OutputAnnotation
left Doc OutputAnnotation
right forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. Doc a -> Doc a
group forall a b. (a -> b) -> a -> b
$ Doc OutputAnnotation
x
        [Doc OutputAnnotation]
xs -> forall a. Doc a -> Doc a -> Doc a -> Doc a
enclose Doc OutputAnnotation
left Doc OutputAnnotation
right forall b c a. (b -> c) -> (a -> b) -> a -> c
.
              forall a. Doc a -> Doc a
align forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. Doc a -> Doc a
group forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. [Doc a] -> Doc a
vsep forall b c a. (b -> c) -> (a -> b) -> a -> c
.
              forall a. Doc a -> [Doc a] -> [Doc a]
punctuate Doc OutputAnnotation
comma forall a b. (a -> b) -> a -> b
$ [Doc OutputAnnotation]
xs
      where left :: Doc OutputAnnotation
left  = (forall a. a -> Doc a -> Doc a
annotate (String -> String -> OutputAnnotation
AnnData String
"" String
"") (forall a. String -> Doc a
text String
"["))
            right :: Doc OutputAnnotation
right = (forall a. a -> Doc a -> Doc a
annotate (String -> String -> OutputAnnotation
AnnData String
"" String
"") (forall a. String -> Doc a
text String
"]"))
            comma :: Doc OutputAnnotation
comma = (forall a. a -> Doc a -> Doc a
annotate (String -> String -> OutputAnnotation
AnnData String
"" String
"") (forall a. String -> Doc a
text String
","))
    slist Maybe Int
_ Int
_ [(Name, Bool)]
_ PTerm
_ = 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 = forall a. a -> Maybe a
Just (PTerm
xforall a. a -> [a] -> [a]
:[PTerm]
elts)
                               | Bool
otherwise = forall a. a -> Maybe a
Just [PTerm
x, PTerm
y]
    pairElts 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 = forall a. a -> Maybe a
Just ((PTerm
l, PTerm
t)forall a. a -> [a] -> [a]
:[(PTerm, PTerm)]
elts)
                                   | Bool
otherwise = forall a. a -> Maybe a
Just [(PTerm
l, PTerm
t), (PTerm
Placeholder, PTerm
r)]
    dPairElts 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 = 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 forall a. Ord a => a -> a -> Bool
<= Int
0 = forall a. Maybe a
Nothing
             snat' Maybe Int
d Int
p (PRef FC
_ [FC]
_ Name
z)
               | forall a. Show a => a -> String
show Name
z forall a. Eq a => a -> a -> Bool
== (String
natnsforall a. [a] -> [a] -> [a]
++String
"Z") Bool -> Bool -> Bool
|| forall a. Show a => a -> String
show Name
z forall a. Eq a => a -> a -> Bool
== String
"Z" = 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}])
               | forall a. Show a => a -> String
show PTerm
s forall a. Eq a => a -> a -> Bool
== (String
natnsforall a. [a] -> [a] -> [a]
++String
"S") Bool -> Bool -> Bool
|| forall a. Show a => a -> String
show PTerm
s 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
                 = forall a. a -> Maybe a
Just forall a b. (a -> b) -> a -> b
$ Integer
1 forall a. Num a => a -> a -> a
+ Integer
n'
             snat' Maybe Int
_ Int
_ PTerm
_ = forall a. Maybe a
Nothing

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

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

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

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

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

    fixities :: M.Map String Fixity
    fixities :: Map String Fixity
fixities = 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 = forall a b c. (a -> b -> c) -> b -> a -> c
flip 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 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 = forall (t :: * -> *). Foldable t => t Bool -> Bool
or [Name -> Bool
isHoleName Name
n | PRef FC
_ [FC]
_ Name
n <- forall a. Int -> [a] -> [a]
take Int
1000 forall a b. (a -> b) -> a -> b
$ 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, forall a. Eq a => [a] -> [a] -> Bool
isPrefixOf String
"_" forall a b. (a -> b) -> a -> b
$ Text -> String
T.unpack Text
s = forall a. String -> Doc a
text String
"_"
    | (UN Text
n')   <- Name
n, forall a. Eq a => [a] -> [a] -> Bool
isPrefixOf String
"__" forall a b. (a -> b) -> a -> b
$ Text -> String
T.unpack Text
n' = forall a. String -> Doc a
text String
"_"
    | (UN Text
n')   <- Name
n, Text -> String
T.unpack Text
n' forall a. Eq a => a -> a -> Bool
== String
"_" = forall a. String -> Doc a
text String
"_"
    | Just Bool
imp  <- forall a b. Eq a => a -> [(a, b)] -> Maybe b
lookup Name
n [(Name, Bool)]
bnd = forall a. a -> Doc a -> Doc a
annotate (Name -> Bool -> OutputAnnotation
AnnBoundName Name
n Bool
imp) forall a. Doc a
fullName
    | Bool
otherwise                 = forall a. a -> Doc a -> Doc a
annotate (Name
-> Maybe NameOutput
-> Maybe String
-> Maybe String
-> OutputAnnotation
AnnName Name
n forall a. Maybe a
Nothing forall a. Maybe a
Nothing forall a. Maybe a
Nothing) forall a. Doc a
fullName
  where fullName :: Doc a
fullName = forall a. String -> Doc a
text String
nameSpace forall a. Doc a -> Doc a -> Doc a
<> forall a. Doc a -> Doc a
parenthesise (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      = 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 (forall (t :: * -> *) a b. Foldable t => (a -> [b]) -> t a -> [b]
concatMap (forall a. [a] -> [a] -> [a]
++ String
".") forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a b. (a -> b) -> [a] -> [b]
map Text -> String
T.unpack forall b c a. (b -> c) -> (a -> b) -> a -> c
. 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 forall a. Doc a -> Doc a -> Doc a -> Doc a
enclose forall a. Doc a
lparen forall a. Doc a
rparen else forall a. a -> a
id


showCImp :: PPOption -> PClause -> Doc OutputAnnotation
showCImp :: PPOption -> PClause -> Doc OutputAnnotation
showCImp PPOption
ppo (PClause FC
_ Name
n PTerm
l [PTerm]
ws PTerm
r [PDecl]
w)
 = PPOption -> PTerm -> Doc OutputAnnotation
prettyImp PPOption
ppo PTerm
l forall a. Doc a -> Doc a -> Doc a
<+> [PTerm] -> Doc OutputAnnotation
showWs [PTerm]
ws forall a. Doc a -> Doc a -> Doc a
<+> forall a. String -> Doc a
text String
"=" forall a. Doc a -> Doc a -> Doc a
<+> PPOption -> PTerm -> Doc OutputAnnotation
prettyImp PPOption
ppo PTerm
r
             forall a. Doc a -> Doc a -> Doc a
<+> forall a. String -> Doc a
text String
"where" forall a. Doc a -> Doc a -> Doc a
<+> forall a. String -> Doc a
text (forall a. Show a => a -> String
show [PDecl]
w)
  where
    showWs :: [PTerm] -> Doc OutputAnnotation
showWs []       = forall a. Doc a
empty
    showWs (PTerm
x : [PTerm]
xs) = forall a. String -> Doc a
text String
"|" forall a. Doc a -> Doc a -> Doc a
<+> PPOption -> PTerm -> Doc OutputAnnotation
prettyImp PPOption
ppo PTerm
x 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]
w)
 = PPOption -> PTerm -> Doc OutputAnnotation
prettyImp PPOption
ppo PTerm
l forall a. Doc a -> Doc a -> Doc a
<+> [PTerm] -> Doc OutputAnnotation
showWs [PTerm]
ws forall a. Doc a -> Doc a -> Doc a
<+> forall a. String -> Doc a
text String
"with" forall a. Doc a -> Doc a -> Doc a
<+> PPOption -> PTerm -> Doc OutputAnnotation
prettyImp PPOption
ppo PTerm
r
                 forall a. Doc a -> Doc a -> Doc a
<+> forall a. Doc a -> Doc a
braces (forall a. String -> Doc a
text (forall a. Show a => a -> String
show [PDecl]
w))
  where
    showWs :: [PTerm] -> Doc OutputAnnotation
showWs []       = forall a. Doc a
empty
    showWs (PTerm
x : [PTerm]
xs) = forall a. String -> Doc a
text String
"|" forall a. Doc a -> Doc a -> Doc a
<+> PPOption -> PTerm -> Doc OutputAnnotation
prettyImp PPOption
ppo PTerm
x 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)
 = forall a. String -> Doc a
text String
"data" forall a. Doc a -> Doc a -> Doc a
<+> forall a. String -> Doc a
text (forall a. Show a => a -> String
show Name
n) forall a. Doc a -> Doc a -> Doc a
<+> forall a. Doc a
colon forall a. Doc a -> Doc a -> Doc a
<+> PPOption -> PTerm -> Doc OutputAnnotation
prettyImp PPOption
ppo PTerm
ty forall a. Doc a -> Doc a -> Doc a
<+> forall a. String -> Doc a
text String
"where" forall a. Doc a -> Doc a -> Doc a
<$>
    (forall a. Int -> Doc a -> Doc a
indent Int
2 forall a b. (a -> b) -> a -> b
$ forall a. [Doc a] -> Doc a
vsep (forall a b. (a -> b) -> [a] -> [b]
map (\ (Docstring (Either Err PTerm)
_, [(Name, Docstring (Either Err PTerm))]
_, Name
n, FC
_, PTerm
t, FC
_, [Name]
_) -> forall a. Doc a
pipe forall a. Doc a -> Doc a -> Doc a
<+> Bool -> Bool -> [(Name, Bool)] -> Name -> Doc OutputAnnotation
prettyName Bool
True Bool
False [] Name
n forall a. Doc a -> Doc a -> Doc a
<+> forall a. Doc a
colon 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] -> Doc OutputAnnotation
showDecls PPOption
o [PDecl]
ds = forall a. [Doc a] -> Doc a
vsep (forall a b. (a -> b) -> [a] -> [b]
map (PPOption -> PDecl -> Doc OutputAnnotation
showDeclImp PPOption
o) [PDecl]
ds)

showDeclImp :: PPOption -> PDecl -> Doc OutputAnnotation
showDeclImp PPOption
_ (PFix FC
_ Fixity
f [String]
ops)        = forall a. String -> Doc a
text (forall a. Show a => a -> String
show Fixity
f) forall a. Doc a -> Doc a -> Doc a
<+> forall a. [Doc a] -> Doc a
cat (forall a. Doc a -> [Doc a] -> [Doc a]
punctuate (forall a. String -> Doc a
text String
",") (forall a b. (a -> b) -> [a] -> [b]
map 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) = forall a. String -> Doc a
text String
"tydecl" forall a. Doc a -> Doc a -> Doc a
<+> forall a. String -> Doc a
text (Name -> String
showCG Name
n) forall a. Doc a -> Doc a -> Doc a
<+> forall a. Doc a
colon 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]
cs)   = forall a. String -> Doc a
text String
"pat" forall a. Doc a -> Doc a -> Doc a
<+> forall a. String -> Doc a
text (Name -> String
showCG Name
n) forall a. Doc a -> Doc a -> Doc a
<+> forall a. String -> Doc a
text String
"\t" forall a. Doc a -> Doc a -> Doc a
<+>
                                      forall a. Int -> Doc a -> Doc a
indent Int
2 (forall a. [Doc a] -> Doc a
vsep (forall a b. (a -> b) -> [a] -> [b]
map (PPOption -> PClause -> Doc OutputAnnotation
showCImp PPOption
o) [PClause]
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 :: Bool
ppopt_impl = Bool
True } PData
d
showDeclImp PPOption
o (PParams FC
_ [(Name, PTerm)]
ns [PDecl]
ps)     = forall a. String -> Doc a
text String
"params" forall a. Doc a -> Doc a -> Doc a
<+> forall a. Doc a -> Doc a
braces (forall a. String -> Doc a
text (forall a. Show a => a -> String
show [(Name, PTerm)]
ns) forall a. Doc a -> Doc a -> Doc a
<> forall a. Doc a
line forall a. Doc a -> Doc a -> Doc a
<> PPOption -> [PDecl] -> Doc OutputAnnotation
showDecls PPOption
o [PDecl]
ps forall a. Doc a -> Doc a -> Doc a
<> forall a. Doc a
line)
showDeclImp PPOption
o (POpenInterfaces FC
_ [Name]
ns [PDecl]
ps) = forall a. String -> Doc a
text String
"open" forall a. Doc a -> Doc a -> Doc a
<+> forall a. Doc a -> Doc a
braces (forall a. String -> Doc a
text (forall a. Show a => a -> String
show [Name]
ns) forall a. Doc a -> Doc a -> Doc a
<> forall a. Doc a
line forall a. Doc a -> Doc a -> Doc a
<> PPOption -> [PDecl] -> Doc OutputAnnotation
showDecls PPOption
o [PDecl]
ps forall a. Doc a -> Doc a -> Doc a
<> forall a. Doc a
line)
showDeclImp PPOption
o (PNamespace String
n FC
fc [PDecl]
ps)  = forall a. String -> Doc a
text String
"namespace" forall a. Doc a -> Doc a -> Doc a
<+> forall a. String -> Doc a
text String
n forall a. Doc a -> Doc a -> Doc a
<> forall a. Doc a -> Doc a
braces (forall a. Doc a
line forall a. Doc a -> Doc a -> Doc a
<> PPOption -> [PDecl] -> Doc OutputAnnotation
showDecls PPOption
o [PDecl]
ps forall a. Doc a -> Doc a -> Doc a
<> forall a. Doc a
line)
showDeclImp PPOption
_ (PSyntax FC
_ Syntax
syn) = forall a. String -> Doc a
text String
"syntax" forall a. Doc a -> Doc a -> Doc a
<+> forall a. String -> Doc a
text (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]
ds Maybe (Name, FC)
_ Docstring (Either Err PTerm)
_)
   = forall a. String -> Doc a
text String
"interface" forall a. Doc a -> Doc a -> Doc a
<+> forall a. String -> Doc a
text (forall a. Show a => a -> String
show [(Name, PTerm)]
cs) forall a. Doc a -> Doc a -> Doc a
<+> forall a. String -> Doc a
text (forall a. Show a => a -> String
show Name
n) forall a. Doc a -> Doc a -> Doc a
<+> forall a. String -> Doc a
text (forall a. Show a => a -> String
show [(Name, FC, PTerm)]
ps) forall a. Doc a -> Doc a -> Doc a
<> forall a. Doc a
line forall a. Doc a -> Doc a -> Doc a
<> PPOption -> [PDecl] -> Doc OutputAnnotation
showDecls PPOption
o [PDecl]
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]
ds)
   = forall a. String -> Doc a
text String
"implementation" forall a. Doc a -> Doc a -> Doc a
<+> forall a. String -> Doc a
text (forall a. Show a => a -> String
show [(Name, PTerm)]
cs) forall a. Doc a -> Doc a -> Doc a
<+> forall a. String -> Doc a
text (forall a. Show a => a -> String
show Name
n) forall a. Doc a -> Doc a -> Doc a
<+> PPOption -> PTerm -> Doc OutputAnnotation
prettyImp PPOption
o PTerm
t forall a. Doc a -> Doc a -> Doc a
<> forall a. Doc a
line forall a. Doc a -> Doc a -> Doc a
<> PPOption -> [PDecl] -> Doc OutputAnnotation
showDecls PPOption
o [PDecl]
ds
showDeclImp PPOption
_ PDecl
_ = 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) 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 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 forall a. a -> [a] -> [a]
: [PArg] -> [PArg]
getShowArgs [PArg]
xs
getShowArgs (PArg
e : [PArg]
xs) | ArgOpt
AlwaysShow forall (t :: * -> *) a. (Foldable t, Eq a) => a -> t a -> Bool
`elem` forall t. PArg' t -> [ArgOpt]
argopts PArg
e = PArg
e 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 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 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 = forall a b. (a -> b) -> [a] -> [b]
map 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 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
"." (forall a b. (a -> b) -> [a] -> [b]
map Text -> String
str (forall a. [a] -> [a]
reverse [Text]
s)) forall a. [a] -> [a] -> [a]
++ String
"." forall a. [a] -> [a] -> [a]
++ Name -> String
showbasic Name
n
          showbasic (SN SpecialName
s)    = forall a. Show a => a -> String
show SpecialName
s
          colourise :: Name -> ColourTheme -> String
colourise Name
n ColourTheme
t = let ctxt' :: Maybe Context
ctxt' = 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 <- 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 = forall a. (a -> ShowS) -> SimpleDoc a -> String
displayDecorated (IState -> OutputAnnotation -> ShowS
consoleDecorate IState
ist) forall b c a. (b -> c) -> (a -> b) -> a -> c
.
             forall a. Float -> Int -> Doc a -> SimpleDoc a
renderPretty Float
0.8 Int
100000 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 = forall a b c. (a -> b -> c) -> b -> a -> c
flip (forall a. SimpleDoc a -> ShowS
displayS forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. Doc a -> SimpleDoc a
renderCompact 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 = forall a b c. (a -> b -> c) -> b -> a -> c
flip (forall a. SimpleDoc a -> ShowS
displayS forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. Float -> Int -> Doc a -> SimpleDoc a
renderPretty Float
1.0 Int
10000000 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)               = forall a. Sized a => a -> Int
size Raw
rawTerm
  size (PRef FC
fc [FC]
_ Name
name)               = forall a. Sized a => a -> Int
size Name
name
  size (PLam FC
fc Name
name FC
_ PTerm
ty PTerm
bdy)        = Int
1 forall a. Num a => a -> a -> a
+ forall a. Sized a => a -> Int
size PTerm
ty forall a. Num a => a -> a -> a
+ forall a. Sized a => a -> Int
size PTerm
bdy
  size (PPi Plicity
plicity Name
name FC
fc PTerm
ty PTerm
bdy)   = Int
1 forall a. Num a => a -> a -> a
+ forall a. Sized a => a -> Int
size PTerm
ty forall a. Num a => a -> a -> a
+ forall a. Sized a => a -> Int
size FC
fc forall a. Num a => a -> a -> a
+ 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 forall a. Num a => a -> a -> a
+ forall a. Sized a => a -> Int
size PTerm
ty forall a. Num a => a -> a -> a
+ forall a. Sized a => a -> Int
size PTerm
def forall a. Num a => a -> a -> a
+ forall a. Sized a => a -> Int
size PTerm
bdy
  size (PTyped PTerm
trm PTerm
ty)                = Int
1 forall a. Num a => a -> a -> a
+ forall a. Sized a => a -> Int
size PTerm
trm forall a. Num a => a -> a -> a
+ forall a. Sized a => a -> Int
size PTerm
ty
  size (PApp FC
fc PTerm
name [PArg]
args)            = Int
1 forall a. Num a => a -> a -> a
+ forall a. Sized a => a -> Int
size [PArg]
args
  size (PAppBind FC
fc PTerm
name [PArg]
args)        = Int
1 forall a. Num a => a -> a -> a
+ forall a. Sized a => a -> Int
size [PArg]
args
  size (PCase FC
fc PTerm
trm [(PTerm, PTerm)]
bdy)             = Int
1 forall a. Num a => a -> a -> a
+ forall a. Sized a => a -> Int
size PTerm
trm forall a. Num a => a -> a -> a
+ forall a. Sized a => a -> Int
size [(PTerm, PTerm)]
bdy
  size (PIfThenElse FC
fc PTerm
c PTerm
t PTerm
f)         = Int
1 forall a. Num a => a -> a -> a
+ forall (t :: * -> *) a. (Foldable t, Num a) => t a -> a
sum (forall a b. (a -> b) -> [a] -> [b]
map 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 forall a. Num a => a -> a -> a
+ forall a. Sized a => a -> Int
size PTerm
left forall a. Num a => a -> a -> a
+ forall a. Sized a => a -> Int
size PTerm
right
  size (PPair FC
fc [FC]
_ PunInfo
_ PTerm
left PTerm
right)      = Int
1 forall a. Num a => a -> a -> a
+ forall a. Sized a => a -> Int
size PTerm
left forall a. Num a => a -> a -> a
+ forall a. Sized a => a -> Int
size PTerm
right
  size (PDPair FC
fs [FC]
_ PunInfo
_ PTerm
left PTerm
ty PTerm
right)  = Int
1 forall a. Num a => a -> a -> a
+ forall a. Sized a => a -> Int
size PTerm
left forall a. Num a => a -> a -> a
+ forall a. Sized a => a -> Int
size PTerm
ty forall a. Num a => a -> a -> a
+ forall a. Sized a => a -> Int
size PTerm
right
  size (PAlternative [(Name, Name)]
_ PAltType
a [PTerm]
alts)        = Int
1 forall a. Num a => a -> a -> a
+ forall a. Sized a => a -> Int
size [PTerm]
alts
  size (PHidden PTerm
hidden)               = forall a. Sized a => a -> Int
size PTerm
hidden
  size (PUnifyLog PTerm
tm)                 = forall a. Sized a => a -> Int
size PTerm
tm
  size (PDisamb [[Text]]
_ PTerm
tm)                 = forall a. Sized a => a -> Int
size PTerm
tm
  size (PNoImplicits PTerm
tm)              = 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 forall a. Num a => a -> a -> a
+ forall a. Sized a => a -> Int
size FC
fc forall a. Num a => a -> a -> a
+ forall a. Sized a => a -> Int
size Const
const
  size PTerm
Placeholder                    = Int
1
  size (PDoBlock [PDo]
dos)                 = Int
1 forall a. Num a => a -> a -> a
+ forall a. Sized a => a -> Int
size [PDo]
dos
  size (PIdiom FC
fc PTerm
term)               = Int
1 forall a. Num a => a -> a -> a
+ forall a. Sized a => a -> Int
size PTerm
term
  size (PMetavar FC
_ Name
name)              = Int
1
  size (PProof [PTactic]
tactics)               = forall a. Sized a => a -> Int
size [PTactic]
tactics
  size (PElabError Err
err)               = 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 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 = forall a. Eq a => [a] -> [a]
nub forall a b. (a -> b) -> a -> b
$ 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 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 forall a. [a] -> [a] -> [a]
++ forall (t :: * -> *) a b. Foldable t => (a -> [b]) -> t a -> [b]
concatMap (t -> [Name] -> PTerm -> [Name]
ni t
0 [Name]
env forall b c a. (b -> c) -> (a -> b) -> a -> c
. 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 forall a. [a] -> [a] -> [a]
++ forall (t :: * -> *) a b. Foldable t => (a -> [b]) -> t a -> [b]
concatMap (t -> [Name] -> PTerm -> [Name]
ni t
0 [Name]
env forall b c a. (b -> c) -> (a -> b) -> a -> c
. 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 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 forall a. [a] -> [a] -> [a]
++ forall (t :: * -> *) a b. Foldable t => (a -> [b]) -> t a -> [b]
concatMap (t -> [Name] -> PTerm -> [Name]
ni t
0 [Name]
env forall b c a. (b -> c) -> (a -> b) -> a -> c
. 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 forall a. [a] -> [a] -> [a]
++ t -> [Name] -> PTerm -> [Name]
ni t
0 [Name]
env PTerm
t 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 forall a. [a] -> [a] -> [a]
++ t -> [Name] -> PTerm -> [Name]
ni t
0 (Name
nforall 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 forall a. [a] -> [a] -> [a]
++ t -> [Name] -> PTerm -> [Name]
ni t
0 [Name]
env PTerm
ty forall a. [a] -> [a] -> [a]
++ t -> [Name] -> PTerm -> [Name]
ni t
0 (Name
nforall 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 forall a. [a] -> [a] -> [a]
++ t -> [Name] -> PTerm -> [Name]
ni t
0 [Name]
env PTerm
val forall a. [a] -> [a] -> [a]
++ t -> [Name] -> PTerm -> [Name]
ni t
0 (Name
nforall 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 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 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 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 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 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 forall a. [a] -> [a] -> [a]
++ t -> [Name] -> PTerm -> [Name]
ni t
0 (Name
nforall 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 forall a. [a] -> [a] -> [a]
++ t -> [Name] -> PTerm -> [Name]
ni t
0 [Name]
env PTerm
t 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))
            = forall a b. (a -> b) -> [a] -> [b]
map forall a b. (a, b) -> b
snd [(Name, Name)]
ns 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)   = forall a b. (a -> b) -> [a] -> [b]
map forall a b. (a, b) -> b
snd [(Name, Name)]
ns forall a. [a] -> [a] -> [a]
++ 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]
_)      = forall (t :: * -> *) a b. Foldable t => (a -> [b]) -> t a -> [b]
concatMap (t -> [Name] -> PTerm -> [Name]
ni t
0 [Name]
env) (forall on. Uniplate on => on -> [on]
children PTerm
tm)
    ni t
0 [Name]
env tm :: PTerm
tm@(PProof [PTactic]
_)        = forall (t :: * -> *) a b. Foldable t => (a -> [b]) -> t a -> [b]
concatMap (t -> [Name] -> PTerm -> [Name]
ni t
0 [Name]
env) (forall on. Uniplate on => on -> [on]
children PTerm
tm)
    ni t
0 [Name]
env tm :: PTerm
tm@(PTactics [PTactic]
_)      = forall (t :: * -> *) a b. Foldable t => (a -> [b]) -> t a -> [b]
concatMap (t -> [Name] -> PTerm -> [Name]
ni t
0 [Name]
env) (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
iforall a. Num a => a -> a -> a
+t
1) [Name]
env PTerm
tm forall a. [a] -> [a] -> [a]
++ 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 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                   = forall (t :: * -> *) a b. Foldable t => (a -> [b]) -> t a -> [b]
concatMap (t -> [Name] -> PTerm -> [Name]
ni t
i [Name]
env) (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 = forall a. Set a -> [a]
S.toList (Int -> Set Name -> PTerm -> Set Name
ni Int
0 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) (forall a b. (a -> b) -> [a] -> [b]
map 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) (forall a b. (a -> b) -> [a] -> [b]
map 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) (forall a b. (a -> b) -> [a] -> [b]
map 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)        = forall a. Ord a => a -> Set a -> Set a
S.insert Name
n 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) = forall a. Ord a => a -> Set a -> Set a
S.insert Name
n 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 (forall a. Ord a => a -> Set a -> Set a
S.insert Name
n 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 forall a. Num a => a -> a -> a
+ Int
1) Set Name
set PTerm
tm forall a. Ord a => Set a -> Set a -> Set a
`S.union` forall b a. b -> (a -> b) -> Maybe a -> b
maybe 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 forall a. Num a => a -> a -> a
- Int
1) Set Name
set PTerm
tm

    ni Int
i Set Name
set PTerm
tm                         = forall (t :: * -> *) a b.
Foldable t =>
(a -> b -> b) -> b -> t a -> b
foldr (forall a. Ord a => Set a -> Set a -> Set a
S.union 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 (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) = forall s a. State s a -> s -> s
execState (forall {t} {m :: * -> *}.
(Eq t, Num t, Monad m) =>
t -> [Name] -> PTerm -> StateT ([Name], [Name]) m ()
ni Integer
0 [] PTerm
tm) ([], []) in
            forall a. Eq a => [a] -> [a]
nub [Name]
imps forall a. Eq a => [a] -> [a] -> [a]
\\ forall a. Eq a => [a] -> [a]
nub [Name]
fns
  where
    addImp :: a -> StateT ([a], b) m ()
addImp a
n = do ([a]
imps, b
fns) <- forall (m :: * -> *) s. Monad m => StateT s m s
get
                  forall (m :: * -> *) s. Monad m => s -> StateT s m ()
put (a
n forall a. a -> [a] -> [a]
: [a]
imps, b
fns)
    addFn :: a -> StateT (a, [a]) m ()
addFn a
n = do (a
imps, [a]
fns) <- forall (m :: * -> *) s. Monad m => StateT s m s
get
                 forall (m :: * -> *) s. Monad m => s -> StateT s m ()
put (a
imps, a
nforall 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 forall (t :: * -> *) a. (Foldable t, Eq a) => a -> t a -> Bool
`elem` [Name]
env)
          -- Never implicitly bind if there's a namespace
            = 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 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 forall (t :: * -> *) a. (Foldable t, Eq a) => a -> t a -> Bool
`elem` [Name]
uvars = 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 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
                              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 forall b c a. (b -> c) -> (a -> b) -> a -> c
. 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
                              []  -> forall (m :: * -> *) a. Monad m => a -> m a
return ()
                              [Term]
_   -> forall {m :: * -> *} {a} {a}. Monad m => a -> StateT (a, [a]) m ()
addFn Name
n
                         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 forall b c a. (b -> c) -> (a -> b) -> a -> c
. 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
                                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 forall b c a. (b -> c) -> (a -> b) -> a -> c
. 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
                                    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 forall b c a. (b -> c) -> (a -> b) -> a -> c
. 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
                                  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 forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a b. (a, b) -> b
snd) [(PTerm, PTerm)]
os
                                  ([Name]
imps, [Name]
fns) <- forall (m :: * -> *) s. Monad m => StateT s m s
get
                                  forall (m :: * -> *) s. Monad m => s -> StateT s m ()
put ([] ,[])
                                  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 forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a b. (a, b) -> a
fst) [(PTerm, PTerm)]
os
                                  ([Name]
impsfst, [Name]
_) <- forall (m :: * -> *) s. Monad m => StateT s m s
get
                                  forall (m :: * -> *) s. Monad m => s -> StateT s m ()
put (forall a. Eq a => [a] -> [a]
nub [Name]
imps forall a. Eq a => [a] -> [a] -> [a]
\\ forall a. Eq a => [a] -> [a]
nub [Name]
impsfst, [Name]
fns)
    ni t
0 [Name]
env (PIfThenElse FC
_ PTerm
c PTerm
t PTerm
f)            = 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
nforall 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
nforall 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
nforall 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
nforall 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)           = 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 forall a. Num a => a -> a -> a
+ t
1) [Name]
env PTerm
tm
                                      forall b a. b -> (a -> b) -> Maybe a -> b
maybe (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 forall a. Num a => a -> a -> a
- t
1) [Name]
env PTerm
tm

    ni t
i [Name]
env PTerm
tm = 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) (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 = forall a. Eq a => [a] -> [a]
nub forall a b. (a -> b) -> a -> b
$ 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 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 forall (t :: * -> *) a. (Foldable t, Eq a) => a -> t a -> Bool
`elem` (forall a b. (a -> b) -> [a] -> [b]
map 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 forall a. [a] -> [a] -> [a]
++ forall (t :: * -> *) a b. Foldable t => (a -> [b]) -> t a -> [b]
concatMap (t -> [Name] -> PTerm -> [Name]
ni t
0 [Name]
env forall b c a. (b -> c) -> (a -> b) -> a -> c
. 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 forall a. [a] -> [a] -> [a]
++ forall (t :: * -> *) a b. Foldable t => (a -> [b]) -> t a -> [b]
concatMap (t -> [Name] -> PTerm -> [Name]
ni t
0 [Name]
env forall b c a. (b -> c) -> (a -> b) -> a -> c
. 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 forall a. [a] -> [a] -> [a]
++
    -- names in 'os', not counting the names bound in the cases
                                (forall a. Eq a => [a] -> [a]
nub (forall (t :: * -> *) a b. Foldable t => (a -> [b]) -> t a -> [b]
concatMap (t -> [Name] -> PTerm -> [Name]
ni t
0 [Name]
env forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a b. (a, b) -> b
snd) [(PTerm, PTerm)]
os)
                                     forall a. Eq a => [a] -> [a] -> [a]
\\ forall a. Eq a => [a] -> [a]
nub (forall (t :: * -> *) a b. Foldable t => (a -> [b]) -> t a -> [b]
concatMap (t -> [Name] -> PTerm -> [Name]
ni t
0 [Name]
env forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a b. (a, b) -> a
fst) [(PTerm, PTerm)]
os))
    ni t
0 [Name]
env (PIfThenElse FC
_ PTerm
c PTerm
t PTerm
f)  = 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 forall a. [a] -> [a] -> [a]
++ t -> [Name] -> PTerm -> [Name]
ni t
0 (Name
nforall 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 forall a. [a] -> [a] -> [a]
++ t -> [Name] -> PTerm -> [Name]
ni t
0 [Name]
env PTerm
ty forall a. [a] -> [a] -> [a]
++ t -> [Name] -> PTerm -> [Name]
ni t
0 (Name
nforall 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 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 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 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 forall a. [a] -> [a] -> [a]
++ t -> [Name] -> PTerm -> [Name]
ni t
0 (Name
nforall 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 forall a. [a] -> [a] -> [a]
++ t -> [Name] -> PTerm -> [Name]
ni t
0 [Name]
env PTerm
t 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) = 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 forall a. Num a => a -> a -> a
+ t
1) [Name]
env PTerm
tm forall a. [a] -> [a] -> [a]
++ 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 forall a. Num a => a -> a -> a
- t
1) [Name]
env PTerm
tm

    ni t
i [Name]
env PTerm
tm                     = forall (t :: * -> *) a b. Foldable t => (a -> [b]) -> t a -> [b]
concatMap (t -> [Name] -> PTerm -> [Name]
ni t
i [Name]
env) (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 = forall a. Eq a => [a] -> [a]
nub forall a b. (a -> b) -> a -> b
$ 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 forall (t :: * -> *) a. (Foldable t, Eq a) => a -> t a -> Bool
`elem` [Name]
vars Bool -> Bool -> Bool
&& Bool -> Bool
not (Name
n 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 forall a. [a] -> [a] -> [a]
++ forall (t :: * -> *) a b. Foldable t => (a -> [b]) -> t a -> [b]
concatMap (t -> [Name] -> PTerm -> [Name]
ni t
0 [Name]
env forall b c a. (b -> c) -> (a -> b) -> a -> c
. 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 forall a. [a] -> [a] -> [a]
++ forall (t :: * -> *) a b. Foldable t => (a -> [b]) -> t a -> [b]
concatMap (t -> [Name] -> PTerm -> [Name]
ni t
0 [Name]
env forall b c a. (b -> c) -> (a -> b) -> a -> c
. 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 forall a. [a] -> [a] -> [a]
++ forall (t :: * -> *) a b. Foldable t => (a -> [b]) -> t a -> [b]
concatMap (t -> [Name] -> PTerm -> [Name]
ni t
0 [Name]
env forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a b. (a, b) -> b
snd) [(PTerm, PTerm)]
os
    ni t
0 [Name]
env (PIfThenElse FC
_ PTerm
c PTerm
t PTerm
f)  = 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 forall a. [a] -> [a] -> [a]
++ t -> [Name] -> PTerm -> [Name]
ni t
0 (Name
nforall 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 forall a. [a] -> [a] -> [a]
++ t -> [Name] -> PTerm -> [Name]
ni t
0 [Name]
env PTerm
ty forall a. [a] -> [a] -> [a]
++ t -> [Name] -> PTerm -> [Name]
ni t
0 (Name
nforall 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 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 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 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 forall a. [a] -> [a] -> [a]
++ t -> [Name] -> PTerm -> [Name]
ni t
0 (Name
nforall 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 forall a. [a] -> [a] -> [a]
++ t -> [Name] -> PTerm -> [Name]
ni t
0 [Name]
env PTerm
t 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) = 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 forall a. Num a => a -> a -> a
+ t
1) [Name]
env PTerm
tm forall a. [a] -> [a] -> [a]
++ 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 forall a. Num a => a -> a -> a
- t
1) [Name]
env PTerm
tm

    ni t
i [Name]
env PTerm
tm                     = forall (t :: * -> *) a b. Foldable t => (a -> [b]) -> t a -> [b]
concatMap (t -> [Name] -> PTerm -> [Name]
ni t
i [Name]
env) (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 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]
_) -> forall a b. (a -> b) -> [a] -> [b]
map forall a b. (a, b) -> a
fst [(Int, Name)]
inacc
        Maybe OptInfo
Nothing -> []