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

License     : BSD3
Maintainer  : The Idris Community.
-}

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

module Idris.AbsSyntaxTree where

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

import Idris.Colours

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

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

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

data ElabWhat = ETypes | EDefns | EAll
  deriving (Int -> ElabWhat -> ShowS
[ElabWhat] -> ShowS
ElabWhat -> String
(Int -> ElabWhat -> ShowS)
-> (ElabWhat -> String) -> ([ElabWhat] -> ShowS) -> Show ElabWhat
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [ElabWhat] -> ShowS
$cshowList :: [ElabWhat] -> ShowS
show :: ElabWhat -> String
$cshow :: ElabWhat -> String
showsPrec :: Int -> ElabWhat -> ShowS
$cshowsPrec :: Int -> ElabWhat -> ShowS
Show, ElabWhat -> ElabWhat -> Bool
(ElabWhat -> ElabWhat -> Bool)
-> (ElabWhat -> ElabWhat -> Bool) -> Eq ElabWhat
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 [] Ctxt [Name]
forall k a. Map k a
emptyContext Name -> Name
forall a. a -> a
id [] Maybe FC
forall a. Maybe a
Nothing "(toplevel)" 0 [] PTerm -> PTerm
forall a. a -> a
id (\_ _ _ -> String -> Idris ()
forall (m :: * -> *) a. MonadFail m => String -> m a
fail "Not implemented")

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

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

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

defaultOpts :: IOption
defaultOpts :: IOption
defaultOpts = IOption :: Int
-> [LogCat]
-> Bool
-> Bool
-> Bool
-> Bool
-> Bool
-> Bool
-> Int
-> Bool
-> Bool
-> Codegen
-> OutputType
-> String
-> [String]
-> [String]
-> String
-> String
-> [Opt]
-> Bool
-> Bool
-> [String]
-> [Optimisation]
-> Maybe Int
-> Bool
-> Bool
-> Bool
-> IOption
IOption { opt_logLevel :: Int
opt_logLevel   = 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    = 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 "c"
                      , opt_outputTy :: OutputType
opt_outputTy   = OutputType
Executable
                      , opt_ibcsubdir :: String
opt_ibcsubdir  = ""
                      , opt_importdirs :: [String]
opt_importdirs = []
                      , opt_sourcedirs :: [String]
opt_sourcedirs = []
                      , opt_triple :: String
opt_triple     = ""
                      , opt_cpu :: String
opt_cpu        = ""
                      , opt_cmdline :: [Opt]
opt_cmdline    = []
                      , opt_origerr :: Bool
opt_origerr    = Bool
False
                      , opt_autoSolve :: Bool
opt_autoSolve  = Bool
True
                      , opt_autoImport :: [String]
opt_autoImport = []
                      , opt_optimise :: [Optimisation]
opt_optimise   = [Optimisation]
defaultOptimise
                      , opt_printdepth :: Maybe Int
opt_printdepth = Int -> Maybe Int
forall a. a -> Maybe a
Just 5000
                      , opt_evaltypes :: Bool
opt_evaltypes  = Bool
True
                      , opt_desugarnats :: Bool
opt_desugarnats = Bool
False
                      , opt_autoimpls :: Bool
opt_autoimpls  = Bool
True
                      }

data PPOption = PPOption {
    PPOption -> Bool
ppopt_impl        :: Bool -- ^ whether to show implicits
  , PPOption -> Bool
ppopt_desugarnats :: Bool
  , PPOption -> Bool
ppopt_pinames     :: Bool -- ^ whether to show names in pi bindings
  , PPOption -> Maybe Int
ppopt_depth       :: Maybe Int
  , PPOption -> Bool
ppopt_displayrig  :: Bool -- ^ whether to display multiplicities in binders
  } deriving (Int -> PPOption -> ShowS
[PPOption] -> ShowS
PPOption -> String
(Int -> PPOption -> ShowS)
-> (PPOption -> String) -> ([PPOption] -> ShowS) -> Show PPOption
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
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 :: Bool -> Bool -> Bool -> Maybe Int -> Bool -> PPOption
PPOption {
    ppopt_impl :: Bool
ppopt_impl = Bool
False
  , ppopt_desugarnats :: Bool
ppopt_desugarnats = Bool
False
  , ppopt_pinames :: Bool
ppopt_pinames = Bool
False
  , ppopt_depth :: Maybe Int
ppopt_depth = Maybe Int
forall a. Maybe a
Nothing
  , ppopt_displayrig :: Bool
ppopt_displayrig = Bool
False
  }

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

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

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


-- | The output mode in use
data OutputMode = RawOutput Handle       -- ^ Print user output directly to the handle
                | IdeMode Integer Handle -- ^ Send IDE output for some request ID to the handle
                deriving Int -> OutputMode -> ShowS
[OutputMode] -> ShowS
OutputMode -> String
(Int -> OutputMode -> ShowS)
-> (OutputMode -> String)
-> ([OutputMode] -> ShowS)
-> Show OutputMode
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
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
(Int -> DefaultTotality -> ShowS)
-> (DefaultTotality -> String)
-> ([DefaultTotality] -> ShowS)
-> Show DefaultTotality
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
(DefaultTotality -> DefaultTotality -> Bool)
-> (DefaultTotality -> DefaultTotality -> Bool)
-> Eq DefaultTotality
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. DefaultTotality -> Rep DefaultTotality x)
-> (forall x. Rep DefaultTotality x -> DefaultTotality)
-> Generic DefaultTotality
forall x. Rep DefaultTotality x -> DefaultTotality
forall x. DefaultTotality -> Rep DefaultTotality x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$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
(Int -> InteractiveOpts -> ShowS)
-> (InteractiveOpts -> String)
-> ([InteractiveOpts] -> ShowS)
-> Show InteractiveOpts
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. InteractiveOpts -> Rep InteractiveOpts x)
-> (forall x. Rep InteractiveOpts x -> InteractiveOpts)
-> Generic InteractiveOpts
forall x. Rep InteractiveOpts x -> InteractiveOpts
forall x. InteractiveOpts -> Rep InteractiveOpts x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$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. IState -> Rep IState x)
-> (forall x. Rep IState x -> IState) -> Generic IState
forall x. Rep IState x -> IState
forall x. IState -> Rep IState x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$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 = String -> IState -> String
forall a b. a -> b -> a
const "{internal state}"

data SizeChange = Smaller | Same | Bigger | Unknown
    deriving (Int -> SizeChange -> ShowS
[SizeChange] -> ShowS
SizeChange -> String
(Int -> SizeChange -> ShowS)
-> (SizeChange -> String)
-> ([SizeChange] -> ShowS)
-> Show SizeChange
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [SizeChange] -> ShowS
$cshowList :: [SizeChange] -> ShowS
show :: SizeChange -> String
$cshow :: SizeChange -> String
showsPrec :: Int -> SizeChange -> ShowS
$cshowsPrec :: Int -> SizeChange -> ShowS
Show, SizeChange -> SizeChange -> Bool
(SizeChange -> SizeChange -> Bool)
-> (SizeChange -> SizeChange -> Bool) -> Eq SizeChange
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. SizeChange -> Rep SizeChange x)
-> (forall x. Rep SizeChange x -> SizeChange) -> Generic SizeChange
forall x. Rep SizeChange x -> SizeChange
forall x. SizeChange -> Rep SizeChange x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$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
(Int -> CGInfo -> ShowS)
-> (CGInfo -> String) -> ([CGInfo] -> ShowS) -> Show CGInfo
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. CGInfo -> Rep CGInfo x)
-> (forall x. Rep CGInfo x -> CGInfo) -> Generic CGInfo
forall x. Rep CGInfo x -> CGInfo
forall x. CGInfo -> Rep CGInfo x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$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 "unsafePerformPrimIO"
           , String -> Name
sUN "mkLazyForeignPrim"
           , String -> Name
sUN "mkForeignPrim"
           , String -> Name
sUN "void"
           , String -> Name
sUN "assert_unreachable"
           , String -> Name
sUN "idris_crash"
           ]

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

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

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


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

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

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

-- Commands in the REPL




data ElabShellCmd = EQED
                  | EAbandon
                  | EUndo
                  | EProofState
                  | EProofTerm
                  | EEval PTerm
                  | ECheck PTerm
                  | ESearch PTerm
                  | EDocStr (Either Name Const)
  deriving (Int -> ElabShellCmd -> ShowS
[ElabShellCmd] -> ShowS
ElabShellCmd -> String
(Int -> ElabShellCmd -> ShowS)
-> (ElabShellCmd -> String)
-> ([ElabShellCmd] -> ShowS)
-> Show ElabShellCmd
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [ElabShellCmd] -> ShowS
$cshowList :: [ElabShellCmd] -> ShowS
show :: ElabShellCmd -> String
$cshow :: ElabShellCmd -> String
showsPrec :: Int -> ElabShellCmd -> ShowS
$cshowsPrec :: Int -> ElabShellCmd -> ShowS
Show, ElabShellCmd -> ElabShellCmd -> Bool
(ElabShellCmd -> ElabShellCmd -> Bool)
-> (ElabShellCmd -> ElabShellCmd -> Bool) -> Eq ElabShellCmd
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
(Fixity -> Fixity -> Bool)
-> (Fixity -> Fixity -> Bool) -> Eq Fixity
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. Fixity -> Rep Fixity x)
-> (forall x. Rep Fixity x -> Fixity) -> Generic Fixity
forall x. Rep Fixity x -> Fixity
forall x. Fixity -> Rep Fixity x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$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 i :: Int
i)  = "infixl " String -> ShowS
forall a. [a] -> [a] -> [a]
++ Int -> String
forall a. Show a => a -> String
show Int
i
    show (Infixr i :: Int
i)  = "infixr " String -> ShowS
forall a. [a] -> [a] -> [a]
++ Int -> String
forall a. Show a => a -> String
show Int
i
    show (InfixN i :: Int
i)  = "infix "  String -> ShowS
forall a. [a] -> [a] -> [a]
++ Int -> String
forall a. Show a => a -> String
show Int
i
    show (PrefixN i :: Int
i) = "prefix " String -> ShowS
forall a. [a] -> [a] -> [a]
++ Int -> String
forall a. Show a => a -> String
show Int
i

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

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

{-!
deriving instance Binary FixDecl
!-}

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


data Static = Static | Dynamic
  deriving (Int -> Static -> ShowS
[Static] -> ShowS
Static -> String
(Int -> Static -> ShowS)
-> (Static -> String) -> ([Static] -> ShowS) -> Show Static
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Static] -> ShowS
$cshowList :: [Static] -> ShowS
show :: Static -> String
$cshow :: Static -> String
showsPrec :: Int -> Static -> ShowS
$cshowsPrec :: Int -> Static -> ShowS
Show, Static -> Static -> Bool
(Static -> Static -> Bool)
-> (Static -> Static -> Bool) -> Eq Static
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
Eq Static =>
(Static -> Static -> Ordering)
-> (Static -> Static -> Bool)
-> (Static -> Static -> Bool)
-> (Static -> Static -> Bool)
-> (Static -> Static -> Bool)
-> (Static -> Static -> Static)
-> (Static -> Static -> Static)
-> Ord Static
Static -> Static -> Bool
Static -> Static -> Ordering
Static -> Static -> Static
forall a.
Eq a =>
(a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
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
$cp1Ord :: Eq Static
Ord, Typeable Static
Constr
DataType
Typeable Static =>
(forall (c :: * -> *).
 (forall d b. Data d => c (d -> b) -> d -> c b)
 -> (forall g. g -> c g) -> Static -> c Static)
-> (forall (c :: * -> *).
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c Static)
-> (Static -> Constr)
-> (Static -> DataType)
-> (forall (t :: * -> *) (c :: * -> *).
    Typeable t =>
    (forall d. Data d => c (t d)) -> Maybe (c Static))
-> (forall (t :: * -> * -> *) (c :: * -> *).
    Typeable t =>
    (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c Static))
-> ((forall b. Data b => b -> b) -> Static -> Static)
-> (forall r r'.
    (r -> r' -> r)
    -> r -> (forall d. Data d => d -> r') -> Static -> r)
-> (forall r r'.
    (r' -> r -> r)
    -> r -> (forall d. Data d => d -> r') -> Static -> r)
-> (forall u. (forall d. Data d => d -> u) -> Static -> [u])
-> (forall u. Int -> (forall d. Data d => d -> u) -> Static -> u)
-> (forall (m :: * -> *).
    Monad m =>
    (forall d. Data d => d -> m d) -> Static -> m Static)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> Static -> m Static)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> Static -> m Static)
-> Data Static
Static -> Constr
Static -> DataType
(forall b. Data b => b -> b) -> Static -> Static
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> Static -> c Static
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c 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)
$cDynamic :: Constr
$cStatic :: Constr
$tStatic :: DataType
gmapMo :: (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 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 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 :: Int -> (forall d. Data d => d -> u) -> Static -> u
$cgmapQi :: forall u. Int -> (forall d. Data d => d -> u) -> Static -> u
gmapQ :: (forall d. Data d => d -> u) -> Static -> [u]
$cgmapQ :: forall u. (forall d. Data d => d -> u) -> Static -> [u]
gmapQr :: (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 :: (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 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 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 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 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
$cp1Data :: Typeable Static
Data, (forall x. Static -> Rep Static x)
-> (forall x. Rep Static x -> Static) -> Generic Static
forall x. Rep Static x -> Static
forall x. Static -> Rep Static x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$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
(Int -> Plicity -> ShowS)
-> (Plicity -> String) -> ([Plicity] -> ShowS) -> Show Plicity
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
(Plicity -> Plicity -> Bool)
-> (Plicity -> Plicity -> Bool) -> Eq Plicity
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
Eq Plicity =>
(Plicity -> Plicity -> Ordering)
-> (Plicity -> Plicity -> Bool)
-> (Plicity -> Plicity -> Bool)
-> (Plicity -> Plicity -> Bool)
-> (Plicity -> Plicity -> Bool)
-> (Plicity -> Plicity -> Plicity)
-> (Plicity -> Plicity -> Plicity)
-> Ord Plicity
Plicity -> Plicity -> Bool
Plicity -> Plicity -> Ordering
Plicity -> Plicity -> Plicity
forall a.
Eq a =>
(a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
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
$cp1Ord :: Eq Plicity
Ord, Typeable Plicity
Constr
DataType
Typeable Plicity =>
(forall (c :: * -> *).
 (forall d b. Data d => c (d -> b) -> d -> c b)
 -> (forall g. g -> c g) -> Plicity -> c Plicity)
-> (forall (c :: * -> *).
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c Plicity)
-> (Plicity -> Constr)
-> (Plicity -> DataType)
-> (forall (t :: * -> *) (c :: * -> *).
    Typeable t =>
    (forall d. Data d => c (t d)) -> Maybe (c Plicity))
-> (forall (t :: * -> * -> *) (c :: * -> *).
    Typeable t =>
    (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c Plicity))
-> ((forall b. Data b => b -> b) -> Plicity -> Plicity)
-> (forall r r'.
    (r -> r' -> r)
    -> r -> (forall d. Data d => d -> r') -> Plicity -> r)
-> (forall r r'.
    (r' -> r -> r)
    -> r -> (forall d. Data d => d -> r') -> Plicity -> r)
-> (forall u. (forall d. Data d => d -> u) -> Plicity -> [u])
-> (forall u. Int -> (forall d. Data d => d -> u) -> Plicity -> u)
-> (forall (m :: * -> *).
    Monad m =>
    (forall d. Data d => d -> m d) -> Plicity -> m Plicity)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> Plicity -> m Plicity)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> Plicity -> m Plicity)
-> Data Plicity
Plicity -> Constr
Plicity -> DataType
(forall b. Data b => b -> b) -> Plicity -> Plicity
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> Plicity -> c Plicity
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c 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)
$cTacImp :: Constr
$cConstraint :: Constr
$cExp :: Constr
$cImp :: Constr
$tPlicity :: DataType
gmapMo :: (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 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 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 :: Int -> (forall d. Data d => d -> u) -> Plicity -> u
$cgmapQi :: forall u. Int -> (forall d. Data d => d -> u) -> Plicity -> u
gmapQ :: (forall d. Data d => d -> u) -> Plicity -> [u]
$cgmapQ :: forall u. (forall d. Data d => d -> u) -> Plicity -> [u]
gmapQr :: (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 :: (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 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 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 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 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
$cp1Data :: Typeable Plicity
Data, (forall x. Plicity -> Rep Plicity x)
-> (forall x. Rep Plicity x -> Plicity) -> Generic Plicity
forall x. Rep Plicity x -> Plicity
forall x. Plicity -> Rep Plicity x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$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 _ _ _ s :: Maybe ImplicitInfo
s _ _) = Maybe ImplicitInfo
s
is_scoped _                 = Maybe ImplicitInfo
forall a. Maybe a
Nothing

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

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

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

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

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

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

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

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


-- | Type provider - what to provide
data ProvideWhat' t = ProvTerm t t     -- ^ the first is the goal type, the second is the term
                    | ProvPostulate t  -- ^ goal type must be Type, so only term
    deriving (Int -> ProvideWhat' t -> ShowS
[ProvideWhat' t] -> ShowS
ProvideWhat' t -> String
(Int -> ProvideWhat' t -> ShowS)
-> (ProvideWhat' t -> String)
-> ([ProvideWhat' t] -> ShowS)
-> Show (ProvideWhat' t)
forall t. Show t => Int -> ProvideWhat' t -> ShowS
forall t. Show t => [ProvideWhat' t] -> ShowS
forall t. Show t => ProvideWhat' t -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
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
(ProvideWhat' t -> ProvideWhat' t -> Bool)
-> (ProvideWhat' t -> ProvideWhat' t -> Bool)
-> Eq (ProvideWhat' t)
forall t. Eq t => ProvideWhat' t -> ProvideWhat' t -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: 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, a -> ProvideWhat' b -> ProvideWhat' a
(a -> b) -> ProvideWhat' a -> ProvideWhat' b
(forall a b. (a -> b) -> ProvideWhat' a -> ProvideWhat' b)
-> (forall a b. a -> ProvideWhat' b -> ProvideWhat' a)
-> Functor ProvideWhat'
forall a b. a -> ProvideWhat' b -> ProvideWhat' a
forall a b. (a -> b) -> ProvideWhat' a -> ProvideWhat' b
forall (f :: * -> *).
(forall a b. (a -> b) -> f a -> f b)
-> (forall a b. a -> f b -> f a) -> Functor f
<$ :: a -> ProvideWhat' b -> ProvideWhat' a
$c<$ :: forall a b. a -> ProvideWhat' b -> ProvideWhat' a
fmap :: (a -> b) -> ProvideWhat' a -> ProvideWhat' b
$cfmap :: forall a b. (a -> b) -> ProvideWhat' a -> ProvideWhat' b
Functor, (forall x. ProvideWhat' t -> Rep (ProvideWhat' t) x)
-> (forall x. Rep (ProvideWhat' t) x -> ProvideWhat' t)
-> Generic (ProvideWhat' t)
forall x. Rep (ProvideWhat' t) x -> ProvideWhat' t
forall x. ProvideWhat' t -> Rep (ProvideWhat' t) x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
forall t x. Rep (ProvideWhat' t) x -> ProvideWhat' t
forall t x. ProvideWhat' t -> Rep (ProvideWhat' t) x
$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 (a -> PDecl' b -> PDecl' a
(a -> b) -> PDecl' a -> PDecl' b
(forall a b. (a -> b) -> PDecl' a -> PDecl' b)
-> (forall a b. a -> PDecl' b -> PDecl' a) -> Functor PDecl'
forall a b. a -> PDecl' b -> PDecl' a
forall a b. (a -> b) -> PDecl' a -> PDecl' b
forall (f :: * -> *).
(forall a b. (a -> b) -> f a -> f b)
-> (forall a b. a -> f b -> f a) -> Functor f
<$ :: a -> PDecl' b -> PDecl' a
$c<$ :: forall a b. a -> PDecl' b -> PDecl' a
fmap :: (a -> b) -> PDecl' a -> PDecl' b
$cfmap :: forall a b. (a -> b) -> PDecl' a -> PDecl' b
Functor, (forall x. PDecl' t -> Rep (PDecl' t) x)
-> (forall x. Rep (PDecl' t) x -> PDecl' t) -> Generic (PDecl' t)
forall x. Rep (PDecl' t) x -> PDecl' t
forall x. PDecl' t -> Rep (PDecl' t) x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
forall t x. Rep (PDecl' t) x -> PDecl' t
forall t x. PDecl' t -> Rep (PDecl' t) x
$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. Directive -> Rep Directive x)
-> (forall x. Rep Directive x -> Directive) -> Generic Directive
forall x. Rep Directive x -> Directive
forall x. Directive -> Rep Directive x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$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 [] [] [] Set (FC', OutputAnnotation)
forall a. Set a
S.empty [] []

type ElabD a = Elab' EState a

highlightSource :: FC -> OutputAnnotation -> ElabD ()
highlightSource :: FC -> OutputAnnotation -> Elab' EState ()
highlightSource fc :: FC
fc annot :: OutputAnnotation
annot =
  (EState -> EState) -> Elab' EState ()
forall aux. (aux -> aux) -> Elab' aux ()
updateAux (\aux :: EState
aux -> EState
aux { highlighting :: Set (FC', OutputAnnotation)
highlighting = (FC', OutputAnnotation)
-> Set (FC', OutputAnnotation) -> Set (FC', OutputAnnotation)
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 (a -> PClause' b -> PClause' a
(a -> b) -> PClause' a -> PClause' b
(forall a b. (a -> b) -> PClause' a -> PClause' b)
-> (forall a b. a -> PClause' b -> PClause' a) -> Functor PClause'
forall a b. a -> PClause' b -> PClause' a
forall a b. (a -> b) -> PClause' a -> PClause' b
forall (f :: * -> *).
(forall a b. (a -> b) -> f a -> f b)
-> (forall a b. a -> f b -> f a) -> Functor f
<$ :: a -> PClause' b -> PClause' a
$c<$ :: forall a b. a -> PClause' b -> PClause' a
fmap :: (a -> b) -> PClause' a -> PClause' b
$cfmap :: forall a b. (a -> b) -> PClause' a -> PClause' b
Functor, (forall x. PClause' t -> Rep (PClause' t) x)
-> (forall x. Rep (PClause' t) x -> PClause' t)
-> Generic (PClause' t)
forall x. Rep (PClause' t) x -> PClause' t
forall x. PClause' t -> Rep (PClause' t) x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
forall t x. Rep (PClause' t) x -> PClause' t
forall t x. PClause' t -> Rep (PClause' t) x
$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 { PData' t -> Name
d_name    :: Name -- ^ The name of the datatype
              , PData' t -> FC
d_name_fc :: FC   -- ^ The precise location of the type constructor name
              , PData' t -> t
d_tcon    :: t    -- ^ Type constructor
              , 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 (a -> PData' b -> PData' a
(a -> b) -> PData' a -> PData' b
(forall a b. (a -> b) -> PData' a -> PData' b)
-> (forall a b. a -> PData' b -> PData' a) -> Functor PData'
forall a b. a -> PData' b -> PData' a
forall a b. (a -> b) -> PData' a -> PData' b
forall (f :: * -> *).
(forall a b. (a -> b) -> f a -> f b)
-> (forall a b. a -> f b -> f a) -> Functor f
<$ :: a -> PData' b -> PData' a
$c<$ :: forall a b. a -> PData' b -> PData' a
fmap :: (a -> b) -> PData' a -> PData' b
$cfmap :: forall a b. (a -> b) -> PData' a -> PData' b
Functor, (forall x. PData' t -> Rep (PData' t) x)
-> (forall x. Rep (PData' t) x -> PData' t) -> Generic (PData' t)
forall x. Rep (PData' t) x -> PData' t
forall x. PData' t -> Rep (PData' t) x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
forall t x. Rep (PData' t) x -> PData' t
forall t x. PData' t -> Rep (PData' t) x
$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 f :: FC -> FC
f g :: FC -> FC
g (PDatadecl n :: Name
n nfc :: FC
nfc tycon :: PTerm
tycon ctors :: [(Docstring (Either Err PTerm),
  [(Name, Docstring (Either Err PTerm))], Name, FC, PTerm, FC,
  [Name])]
ctors) =
  Name
-> FC
-> PTerm
-> [(Docstring (Either Err PTerm),
     [(Name, Docstring (Either Err PTerm))], Name, FC, PTerm, FC,
     [Name])]
-> PData
forall t.
Name
-> FC
-> t
-> [(Docstring (Either Err PTerm),
     [(Name, Docstring (Either Err PTerm))], Name, FC, t, FC, [Name])]
-> PData' t
PDatadecl Name
n (FC -> FC
g FC
nfc) ((FC -> FC) -> (FC -> FC) -> PTerm -> PTerm
mapPTermFC FC -> FC
f FC -> FC
g PTerm
tycon) (((Docstring (Either Err PTerm),
  [(Name, Docstring (Either Err PTerm))], Name, FC, PTerm, FC,
  [Name])
 -> (Docstring (Either Err PTerm),
     [(Name, Docstring (Either Err PTerm))], Name, FC, PTerm, FC,
     [Name]))
-> [(Docstring (Either Err PTerm),
     [(Name, Docstring (Either Err PTerm))], Name, FC, PTerm, FC,
     [Name])]
-> [(Docstring (Either Err PTerm),
     [(Name, Docstring (Either Err PTerm))], Name, FC, PTerm, FC,
     [Name])]
forall a b. (a -> b) -> [a] -> [b]
map (Docstring (Either Err PTerm),
 [(Name, Docstring (Either Err PTerm))], Name, FC, PTerm, FC,
 [Name])
-> (Docstring (Either Err PTerm),
    [(Name, Docstring (Either Err PTerm))], Name, FC, PTerm, FC,
    [Name])
forall a b c g.
(a, b, c, FC, PTerm, FC, g) -> (a, b, c, FC, PTerm, FC, g)
ctorFC [(Docstring (Either Err PTerm),
  [(Name, Docstring (Either Err PTerm))], Name, FC, PTerm, FC,
  [Name])]
ctors)
    where ctorFC :: (a, b, c, FC, PTerm, FC, g) -> (a, b, c, FC, PTerm, FC, g)
ctorFC (doc :: a
doc, argDocs :: b
argDocs, n :: c
n, nfc :: FC
nfc, ty :: PTerm
ty, fc :: FC
fc, ns :: 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 f :: FC -> FC
f g :: FC -> FC
g (PLaterdecl n :: Name
n nfc :: FC
nfc tycon :: PTerm
tycon) =
  Name -> FC -> PTerm -> PData
forall t. Name -> FC -> t -> PData' t
PLaterdecl Name
n (FC -> FC
g FC
nfc) ((FC -> FC) -> (FC -> FC) -> PTerm -> PTerm
mapPTermFC FC -> FC
f FC -> FC
g PTerm
tycon)
{-!
deriving instance Binary PData'
!-}

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

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

-- | Transform the FCs in a PTerm. The first function transforms the
-- general-purpose FCs, and the second transforms those that are used
-- for semantic source highlighting, so they can be treated specially.
mapPDeclFC :: (FC -> FC) -> (FC -> FC) -> PDecl -> PDecl
mapPDeclFC :: (FC -> FC) -> (FC -> FC) -> PDecl -> PDecl
mapPDeclFC f :: FC -> FC
f g :: FC -> FC
g (PFix fc :: FC
fc fixity :: Fixity
fixity ops :: [String]
ops) =
    FC -> Fixity -> [String] -> PDecl
forall t. FC -> Fixity -> [String] -> PDecl' t
PFix (FC -> FC
f FC
fc) Fixity
fixity [String]
ops
mapPDeclFC f :: FC -> FC
f g :: FC -> FC
g (PTy doc :: Docstring (Either Err PTerm)
doc argdocs :: [(Name, Docstring (Either Err PTerm))]
argdocs syn :: SyntaxInfo
syn fc :: FC
fc opts :: [FnOpt]
opts n :: Name
n nfc :: FC
nfc ty :: PTerm
ty) =
    Docstring (Either Err PTerm)
-> [(Name, Docstring (Either Err PTerm))]
-> SyntaxInfo
-> FC
-> [FnOpt]
-> Name
-> FC
-> PTerm
-> PDecl
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 f :: FC -> FC
f g :: FC -> FC
g (PPostulate ext :: Bool
ext doc :: Docstring (Either Err PTerm)
doc syn :: SyntaxInfo
syn fc :: FC
fc nfc :: FC
nfc opts :: [FnOpt]
opts n :: Name
n ty :: PTerm
ty) =
    Bool
-> Docstring (Either Err PTerm)
-> SyntaxInfo
-> FC
-> FC
-> [FnOpt]
-> Name
-> PTerm
-> PDecl
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 f :: FC -> FC
f g :: FC -> FC
g (PClauses fc :: FC
fc opts :: [FnOpt]
opts n :: Name
n clauses :: [PClause' PTerm]
clauses) =
    FC -> [FnOpt] -> Name -> [PClause' PTerm] -> PDecl
forall t. FC -> [FnOpt] -> Name -> [PClause' t] -> PDecl' t
PClauses (FC -> FC
f FC
fc) [FnOpt]
opts Name
n ((PClause' PTerm -> PClause' PTerm)
-> [PClause' PTerm] -> [PClause' PTerm]
forall a b. (a -> b) -> [a] -> [b]
map ((PTerm -> PTerm) -> PClause' PTerm -> PClause' PTerm
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap ((FC -> FC) -> (FC -> FC) -> PTerm -> PTerm
mapPTermFC FC -> FC
f FC -> FC
g)) [PClause' PTerm]
clauses)
mapPDeclFC f :: FC -> FC
f g :: FC -> FC
g (PCAF fc :: FC
fc n :: Name
n tm :: PTerm
tm) = FC -> Name -> PTerm -> PDecl
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 f :: FC -> FC
f g :: FC -> FC
g (PData doc :: Docstring (Either Err PTerm)
doc argdocs :: [(Name, Docstring (Either Err PTerm))]
argdocs syn :: SyntaxInfo
syn fc :: FC
fc opts :: DataOpts
opts dat :: PData
dat) =
    Docstring (Either Err PTerm)
-> [(Name, Docstring (Either Err PTerm))]
-> SyntaxInfo
-> FC
-> DataOpts
-> PData
-> PDecl
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 f :: FC -> FC
f g :: FC -> FC
g (PParams fc :: FC
fc params :: [(Name, PTerm)]
params decls :: [PDecl]
decls) =
    FC -> [(Name, PTerm)] -> [PDecl] -> PDecl
forall t. FC -> [(Name, t)] -> [PDecl' t] -> PDecl' t
PParams (FC -> FC
f FC
fc)
            (((Name, PTerm) -> (Name, PTerm))
-> [(Name, PTerm)] -> [(Name, PTerm)]
forall a b. (a -> b) -> [a] -> [b]
map (\(n :: Name
n, ty :: PTerm
ty) -> (Name
n, (FC -> FC) -> (FC -> FC) -> PTerm -> PTerm
mapPTermFC FC -> FC
f FC -> FC
g PTerm
ty)) [(Name, PTerm)]
params)
            ((PDecl -> PDecl) -> [PDecl] -> [PDecl]
forall a b. (a -> b) -> [a] -> [b]
map ((FC -> FC) -> (FC -> FC) -> PDecl -> PDecl
mapPDeclFC FC -> FC
f FC -> FC
g) [PDecl]
decls)
mapPDeclFC f :: FC -> FC
f g :: FC -> FC
g (POpenInterfaces fc :: FC
fc ifs :: [Name]
ifs decls :: [PDecl]
decls) =
    FC -> [Name] -> [PDecl] -> PDecl
forall t. FC -> [Name] -> [PDecl' t] -> PDecl' t
POpenInterfaces (FC -> FC
f FC
fc) [Name]
ifs ((PDecl -> PDecl) -> [PDecl] -> [PDecl]
forall a b. (a -> b) -> [a] -> [b]
map ((FC -> FC) -> (FC -> FC) -> PDecl -> PDecl
mapPDeclFC FC -> FC
f FC -> FC
g) [PDecl]
decls)
mapPDeclFC f :: FC -> FC
f g :: FC -> FC
g (PNamespace ns :: String
ns fc :: FC
fc decls :: [PDecl]
decls) =
    String -> FC -> [PDecl] -> PDecl
forall t. String -> FC -> [PDecl' t] -> PDecl' t
PNamespace String
ns (FC -> FC
f FC
fc) ((PDecl -> PDecl) -> [PDecl] -> [PDecl]
forall a b. (a -> b) -> [a] -> [b]
map ((FC -> FC) -> (FC -> FC) -> PDecl -> PDecl
mapPDeclFC FC -> FC
f FC -> FC
g) [PDecl]
decls)
mapPDeclFC f :: FC -> FC
f g :: FC -> FC
g (PRecord doc :: Docstring (Either Err PTerm)
doc syn :: SyntaxInfo
syn fc :: FC
fc opts :: DataOpts
opts n :: Name
n nfc :: FC
nfc params :: [(Name, FC, Plicity, PTerm)]
params paramdocs :: [(Name, Docstring (Either Err PTerm))]
paramdocs fields :: [(Maybe (Name, FC), Plicity, PTerm,
  Maybe (Docstring (Either Err PTerm)))]
fields ctor :: Maybe (Name, FC)
ctor ctorDoc :: Docstring (Either Err PTerm)
ctorDoc syn' :: SyntaxInfo
syn') =
    Docstring (Either Err PTerm)
-> SyntaxInfo
-> FC
-> DataOpts
-> Name
-> FC
-> [(Name, FC, Plicity, PTerm)]
-> [(Name, Docstring (Either Err PTerm))]
-> [(Maybe (Name, FC), Plicity, PTerm,
     Maybe (Docstring (Either Err PTerm)))]
-> Maybe (Name, FC)
-> Docstring (Either Err PTerm)
-> SyntaxInfo
-> PDecl
forall t.
Docstring (Either Err t)
-> SyntaxInfo
-> FC
-> DataOpts
-> Name
-> FC
-> [(Name, FC, Plicity, t)]
-> [(Name, Docstring (Either Err t))]
-> [(Maybe (Name, FC), Plicity, t,
     Maybe (Docstring (Either Err t)))]
-> Maybe (Name, FC)
-> Docstring (Either Err t)
-> SyntaxInfo
-> PDecl' t
PRecord Docstring (Either Err PTerm)
doc SyntaxInfo
syn (FC -> FC
f FC
fc) DataOpts
opts Name
n (FC -> FC
g FC
nfc)
            (((Name, FC, Plicity, PTerm) -> (Name, FC, Plicity, PTerm))
-> [(Name, FC, Plicity, PTerm)] -> [(Name, FC, Plicity, PTerm)]
forall a b. (a -> b) -> [a] -> [b]
map (\(pn :: Name
pn, pnfc :: FC
pnfc, plic :: Plicity
plic, ty :: PTerm
ty) -> (Name
pn, FC -> FC
g FC
pnfc, Plicity
plic, (FC -> FC) -> (FC -> FC) -> PTerm -> PTerm
mapPTermFC FC -> FC
f FC -> FC
g PTerm
ty)) [(Name, FC, Plicity, PTerm)]
params)
            [(Name, Docstring (Either Err PTerm))]
paramdocs
            (((Maybe (Name, FC), Plicity, PTerm,
  Maybe (Docstring (Either Err PTerm)))
 -> (Maybe (Name, FC), Plicity, PTerm,
     Maybe (Docstring (Either Err PTerm))))
-> [(Maybe (Name, FC), Plicity, PTerm,
     Maybe (Docstring (Either Err PTerm)))]
-> [(Maybe (Name, FC), Plicity, PTerm,
     Maybe (Docstring (Either Err PTerm)))]
forall a b. (a -> b) -> [a] -> [b]
map (\(fn :: Maybe (Name, FC)
fn, plic :: Plicity
plic, ty :: PTerm
ty, fdoc :: Maybe (Docstring (Either Err PTerm))
fdoc) -> (((Name, FC) -> (Name, FC)) -> Maybe (Name, FC) -> Maybe (Name, FC)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (\(fn' :: Name
fn', fnfc :: FC
fnfc) -> (Name
fn', FC -> FC
g FC
fnfc)) Maybe (Name, FC)
fn,
                                            Plicity
plic, (FC -> FC) -> (FC -> FC) -> PTerm -> PTerm
mapPTermFC FC -> FC
f FC -> FC
g PTerm
ty, Maybe (Docstring (Either Err PTerm))
fdoc))
                 [(Maybe (Name, FC), Plicity, PTerm,
  Maybe (Docstring (Either Err PTerm)))]
fields)
            (((Name, FC) -> (Name, FC)) -> Maybe (Name, FC) -> Maybe (Name, FC)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (\(ctorN :: Name
ctorN, ctorNFC :: FC
ctorNFC) -> (Name
ctorN, FC -> FC
g FC
ctorNFC)) Maybe (Name, FC)
ctor)
            Docstring (Either Err PTerm)
ctorDoc
            SyntaxInfo
syn'
mapPDeclFC f :: FC -> FC
f g :: FC -> FC
g (PInterface doc :: Docstring (Either Err PTerm)
doc syn :: SyntaxInfo
syn fc :: FC
fc constrs :: [(Name, PTerm)]
constrs n :: Name
n nfc :: FC
nfc params :: [(Name, FC, PTerm)]
params paramDocs :: [(Name, Docstring (Either Err PTerm))]
paramDocs det :: [(Name, FC)]
det body :: [PDecl]
body ctor :: Maybe (Name, FC)
ctor ctorDoc :: Docstring (Either Err PTerm)
ctorDoc) =
    Docstring (Either Err PTerm)
-> SyntaxInfo
-> FC
-> [(Name, PTerm)]
-> Name
-> FC
-> [(Name, FC, PTerm)]
-> [(Name, Docstring (Either Err PTerm))]
-> [(Name, FC)]
-> [PDecl]
-> Maybe (Name, FC)
-> Docstring (Either Err PTerm)
-> PDecl
forall t.
Docstring (Either Err t)
-> SyntaxInfo
-> FC
-> [(Name, t)]
-> Name
-> FC
-> [(Name, FC, t)]
-> [(Name, Docstring (Either Err t))]
-> [(Name, FC)]
-> [PDecl' t]
-> Maybe (Name, FC)
-> Docstring (Either Err t)
-> PDecl' t
PInterface Docstring (Either Err PTerm)
doc SyntaxInfo
syn (FC -> FC
f FC
fc)
           (((Name, PTerm) -> (Name, PTerm))
-> [(Name, PTerm)] -> [(Name, PTerm)]
forall a b. (a -> b) -> [a] -> [b]
map (\(constrn :: Name
constrn, constr :: PTerm
constr) -> (Name
constrn, (FC -> FC) -> (FC -> FC) -> PTerm -> PTerm
mapPTermFC FC -> FC
f FC -> FC
g PTerm
constr)) [(Name, PTerm)]
constrs)
           Name
n (FC -> FC
g FC
nfc) (((Name, FC, PTerm) -> (Name, FC, PTerm))
-> [(Name, FC, PTerm)] -> [(Name, FC, PTerm)]
forall a b. (a -> b) -> [a] -> [b]
map (\(n :: Name
n, nfc :: FC
nfc, pty :: PTerm
pty) -> (Name
n, FC -> FC
g FC
nfc, (FC -> FC) -> (FC -> FC) -> PTerm -> PTerm
mapPTermFC FC -> FC
f FC -> FC
g PTerm
pty)) [(Name, FC, PTerm)]
params)
           [(Name, Docstring (Either Err PTerm))]
paramDocs (((Name, FC) -> (Name, FC)) -> [(Name, FC)] -> [(Name, FC)]
forall a b. (a -> b) -> [a] -> [b]
map (\(dn :: Name
dn, dnfc :: FC
dnfc) -> (Name
dn, FC -> FC
g FC
dnfc)) [(Name, FC)]
det)
           ((PDecl -> PDecl) -> [PDecl] -> [PDecl]
forall a b. (a -> b) -> [a] -> [b]
map ((FC -> FC) -> (FC -> FC) -> PDecl -> PDecl
mapPDeclFC FC -> FC
f FC -> FC
g) [PDecl]
body)
           (((Name, FC) -> (Name, FC)) -> Maybe (Name, FC) -> Maybe (Name, FC)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (\(n :: Name
n, nfc :: FC
nfc) -> (Name
n, FC -> FC
g FC
nfc)) Maybe (Name, FC)
ctor)
           Docstring (Either Err PTerm)
ctorDoc
mapPDeclFC f :: FC -> FC
f g :: FC -> FC
g (PImplementation doc :: Docstring (Either Err PTerm)
doc paramDocs :: [(Name, Docstring (Either Err PTerm))]
paramDocs syn :: SyntaxInfo
syn fc :: FC
fc constrs :: [(Name, PTerm)]
constrs pnames :: [Name]
pnames cn :: Accessibility
cn acc :: [FnOpt]
acc opts :: Name
opts cnfc :: FC
cnfc params :: [PTerm]
params pextra :: [(Name, PTerm)]
pextra implTy :: PTerm
implTy implN :: Maybe Name
implN body :: [PDecl]
body) =
    Docstring (Either Err PTerm)
-> [(Name, Docstring (Either Err PTerm))]
-> SyntaxInfo
-> FC
-> [(Name, PTerm)]
-> [Name]
-> Accessibility
-> [FnOpt]
-> Name
-> FC
-> [PTerm]
-> [(Name, PTerm)]
-> PTerm
-> Maybe Name
-> [PDecl]
-> PDecl
forall t.
Docstring (Either Err t)
-> [(Name, Docstring (Either Err t))]
-> SyntaxInfo
-> FC
-> [(Name, t)]
-> [Name]
-> Accessibility
-> [FnOpt]
-> Name
-> FC
-> [t]
-> [(Name, t)]
-> t
-> Maybe Name
-> [PDecl' t]
-> PDecl' t
PImplementation Docstring (Either Err PTerm)
doc [(Name, Docstring (Either Err PTerm))]
paramDocs SyntaxInfo
syn (FC -> FC
f FC
fc)
                    (((Name, PTerm) -> (Name, PTerm))
-> [(Name, PTerm)] -> [(Name, PTerm)]
forall a b. (a -> b) -> [a] -> [b]
map (\(constrN :: Name
constrN, constrT :: PTerm
constrT) -> (Name
constrN, (FC -> FC) -> (FC -> FC) -> PTerm -> PTerm
mapPTermFC FC -> FC
f FC -> FC
g PTerm
constrT)) [(Name, PTerm)]
constrs)
                    [Name]
pnames Accessibility
cn [FnOpt]
acc Name
opts (FC -> FC
g FC
cnfc) ((PTerm -> PTerm) -> [PTerm] -> [PTerm]
forall a b. (a -> b) -> [a] -> [b]
map ((FC -> FC) -> (FC -> FC) -> PTerm -> PTerm
mapPTermFC FC -> FC
f FC -> FC
g) [PTerm]
params)
                    (((Name, PTerm) -> (Name, PTerm))
-> [(Name, PTerm)] -> [(Name, PTerm)]
forall a b. (a -> b) -> [a] -> [b]
map (\(en :: Name
en, et :: PTerm
et) -> (Name
en, (FC -> FC) -> (FC -> FC) -> PTerm -> PTerm
mapPTermFC FC -> FC
f FC -> FC
g PTerm
et)) [(Name, PTerm)]
pextra)
                    ((FC -> FC) -> (FC -> FC) -> PTerm -> PTerm
mapPTermFC FC -> FC
f FC -> FC
g PTerm
implTy)
                    Maybe Name
implN
                    ((PDecl -> PDecl) -> [PDecl] -> [PDecl]
forall a b. (a -> b) -> [a] -> [b]
map ((FC -> FC) -> (FC -> FC) -> PDecl -> PDecl
mapPDeclFC FC -> FC
f FC -> FC
g) [PDecl]
body)
mapPDeclFC f :: FC -> FC
f g :: FC -> FC
g (PDSL n :: Name
n dsl :: DSL
dsl) = Name -> DSL -> PDecl
forall t. Name -> DSL' t -> PDecl' t
PDSL Name
n ((PTerm -> PTerm) -> DSL -> DSL
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 f :: FC -> FC
f g :: FC -> FC
g (PSyntax fc :: FC
fc syn :: Syntax
syn) = FC -> Syntax -> PDecl
forall t. FC -> Syntax -> PDecl' t
PSyntax (FC -> FC
f FC
fc) (Syntax -> PDecl) -> Syntax -> PDecl
forall a b. (a -> b) -> a -> b
$
                                    case Syntax
syn of
                                      Rule syms :: [SSymbol]
syms tm :: PTerm
tm ctxt :: 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 syms :: [SSymbol]
syms decls :: [PDecl]
decls -> [SSymbol] -> [PDecl] -> Syntax
DeclRule [SSymbol]
syms ((PDecl -> PDecl) -> [PDecl] -> [PDecl]
forall a b. (a -> b) -> [a] -> [b]
map ((FC -> FC) -> (FC -> FC) -> PDecl -> PDecl
mapPDeclFC FC -> FC
f FC -> FC
g) [PDecl]
decls)
mapPDeclFC f :: FC -> FC
f g :: FC -> FC
g (PMutual fc :: FC
fc decls :: [PDecl]
decls) =
    FC -> [PDecl] -> PDecl
forall t. FC -> [PDecl' t] -> PDecl' t
PMutual (FC -> FC
f FC
fc) ((PDecl -> PDecl) -> [PDecl] -> [PDecl]
forall a b. (a -> b) -> [a] -> [b]
map ((FC -> FC) -> (FC -> FC) -> PDecl -> PDecl
mapPDeclFC FC -> FC
f FC -> FC
g) [PDecl]
decls)
mapPDeclFC f :: FC -> FC
f g :: FC -> FC
g (PDirective d :: Directive
d) =
    Directive -> PDecl
forall t. Directive -> PDecl' t
PDirective (Directive -> PDecl) -> Directive -> PDecl
forall a b. (a -> b) -> a -> b
$
      case Directive
d of
        DNameHint n :: Name
n nfc :: FC
nfc ns :: [(Name, FC)]
ns ->
            Name -> FC -> [(Name, FC)] -> Directive
DNameHint Name
n (FC -> FC
g FC
nfc) (((Name, FC) -> (Name, FC)) -> [(Name, FC)] -> [(Name, FC)]
forall a b. (a -> b) -> [a] -> [b]
map (\(hn :: Name
hn, hnfc :: FC
hnfc) -> (Name
hn, FC -> FC
g FC
hnfc)) [(Name, FC)]
ns)
        DErrorHandlers n :: Name
n nfc :: FC
nfc n' :: Name
n' nfc' :: FC
nfc' ns :: [(Name, FC)]
ns ->
            Name -> FC -> Name -> FC -> [(Name, FC)] -> Directive
DErrorHandlers Name
n (FC -> FC
g FC
nfc) Name
n' (FC -> FC
g FC
nfc') ([(Name, FC)] -> Directive) -> [(Name, FC)] -> Directive
forall a b. (a -> b) -> a -> b
$
                ((Name, FC) -> (Name, FC)) -> [(Name, FC)] -> [(Name, FC)]
forall a b. (a -> b) -> [a] -> [b]
map (\(an :: Name
an, anfc :: FC
anfc) -> (Name
an, FC -> FC
g FC
anfc)) [(Name, FC)]
ns
mapPDeclFC f :: FC -> FC
f g :: FC -> FC
g (PProvider doc :: Docstring (Either Err PTerm)
doc syn :: SyntaxInfo
syn fc :: FC
fc nfc :: FC
nfc what :: ProvideWhat' PTerm
what n :: Name
n) =
    Docstring (Either Err PTerm)
-> SyntaxInfo -> FC -> FC -> ProvideWhat' PTerm -> Name -> PDecl
forall t.
Docstring (Either Err t)
-> SyntaxInfo -> FC -> FC -> ProvideWhat' t -> Name -> PDecl' t
PProvider Docstring (Either Err PTerm)
doc SyntaxInfo
syn (FC -> FC
f FC
fc) (FC -> FC
g FC
nfc) ((PTerm -> PTerm) -> ProvideWhat' PTerm -> ProvideWhat' PTerm
forall (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 f :: FC -> FC
f g :: FC -> FC
g (PTransform fc :: FC
fc safe :: Bool
safe l :: PTerm
l r :: PTerm
r) =
    FC -> Bool -> PTerm -> PTerm -> PDecl
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 f :: FC -> FC
f g :: FC -> FC
g (PRunElabDecl fc :: FC
fc script :: PTerm
script ns :: [String]
ns) =
    FC -> PTerm -> [String] -> PDecl
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 _ _ _) = []
declared (PTy _ _ _ _ _ n :: Name
n fc :: FC
fc t :: PTerm
t) = [Name
n]
declared (PPostulate _ _ _ _ _ _ n :: Name
n t :: PTerm
t) = [Name
n]
declared (PClauses _ _ n :: Name
n _) = [] -- not a declaration
declared (PCAF _ n :: Name
n _) = [Name
n]
declared (PData _ _ _ _ _ (PDatadecl n :: Name
n _ _ ts :: [(Docstring (Either Err PTerm),
  [(Name, Docstring (Either Err PTerm))], Name, FC, PTerm, FC,
  [Name])]
ts)) = Name
n Name -> [Name] -> [Name]
forall a. a -> [a] -> [a]
: ((Docstring (Either Err PTerm),
  [(Name, Docstring (Either Err PTerm))], Name, FC, PTerm, FC,
  [Name])
 -> Name)
-> [(Docstring (Either Err PTerm),
     [(Name, Docstring (Either Err PTerm))], Name, FC, PTerm, FC,
     [Name])]
-> [Name]
forall a b. (a -> b) -> [a] -> [b]
map (Docstring (Either Err PTerm),
 [(Name, Docstring (Either Err PTerm))], Name, FC, PTerm, FC,
 [Name])
-> Name
forall a b c d e f g. (a, b, c, d, e, f, g) -> c
fstt [(Docstring (Either Err PTerm),
  [(Name, Docstring (Either Err PTerm))], Name, FC, PTerm, FC,
  [Name])]
ts
   where fstt :: (a, b, c, d, e, f, g) -> c
fstt (_, _, a :: c
a, _, _, _, _) = c
a
declared (PData _ _ _ _ _ (PLaterdecl n :: Name
n _ _)) = [Name
n]
declared (PParams _ _ ds :: [PDecl]
ds) = (PDecl -> [Name]) -> [PDecl] -> [Name]
forall (t :: * -> *) a b. Foldable t => (a -> [b]) -> t a -> [b]
concatMap PDecl -> [Name]
declared [PDecl]
ds
declared (POpenInterfaces _ _ ds :: [PDecl]
ds) = (PDecl -> [Name]) -> [PDecl] -> [Name]
forall (t :: * -> *) a b. Foldable t => (a -> [b]) -> t a -> [b]
concatMap PDecl -> [Name]
declared [PDecl]
ds
declared (PNamespace _ _ ds :: [PDecl]
ds) = (PDecl -> [Name]) -> [PDecl] -> [Name]
forall (t :: * -> *) a b. Foldable t => (a -> [b]) -> t a -> [b]
concatMap PDecl -> [Name]
declared [PDecl]
ds
declared (PRecord _ _ _ _ n :: Name
n  _ _ _ _ cn :: Maybe (Name, FC)
cn _ _) = Name
n Name -> [Name] -> [Name]
forall a. a -> [a] -> [a]
: ((Name, FC) -> Name) -> [(Name, FC)] -> [Name]
forall a b. (a -> b) -> [a] -> [b]
map (Name, FC) -> Name
forall a b. (a, b) -> a
fst (Maybe (Name, FC) -> [(Name, FC)]
forall a. Maybe a -> [a]
maybeToList Maybe (Name, FC)
cn)
declared (PInterface _ _ _ _ n :: Name
n _ _ _ _ ms :: [PDecl]
ms cn :: Maybe (Name, FC)
cn cd :: Docstring (Either Err PTerm)
cd) = Name
n Name -> [Name] -> [Name]
forall a. a -> [a] -> [a]
: (((Name, FC) -> Name) -> [(Name, FC)] -> [Name]
forall a b. (a -> b) -> [a] -> [b]
map (Name, FC) -> Name
forall a b. (a, b) -> a
fst (Maybe (Name, FC) -> [(Name, FC)]
forall a. Maybe a -> [a]
maybeToList Maybe (Name, FC)
cn) [Name] -> [Name] -> [Name]
forall a. [a] -> [a] -> [a]
++ (PDecl -> [Name]) -> [PDecl] -> [Name]
forall (t :: * -> *) a b. Foldable t => (a -> [b]) -> t a -> [b]
concatMap PDecl -> [Name]
declared [PDecl]
ms)
declared (PImplementation _ _ _ _ _ _ _ _ _ _ _ _ _ mn :: Maybe Name
mn _)
    = case Maybe Name
mn of
           Nothing -> []
           Just n :: Name
n -> [Name
n]
declared (PDSL n :: Name
n _) = [Name
n]
declared (PSyntax _ _) = []
declared (PMutual _ ds :: [PDecl]
ds) = (PDecl -> [Name]) -> [PDecl] -> [Name]
forall (t :: * -> *) a b. Foldable t => (a -> [b]) -> t a -> [b]
concatMap PDecl -> [Name]
declared [PDecl]
ds
declared (PDirective _) = []
declared _ = []

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

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

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

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

data PunInfo = IsType
             | IsTerm
             | TypeOrTerm
             deriving (PunInfo -> PunInfo -> Bool
(PunInfo -> PunInfo -> Bool)
-> (PunInfo -> PunInfo -> Bool) -> Eq PunInfo
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: PunInfo -> PunInfo -> Bool
$c/= :: PunInfo -> PunInfo -> Bool
== :: PunInfo -> PunInfo -> Bool
$c== :: PunInfo -> PunInfo -> Bool
Eq, Int -> PunInfo -> ShowS
[PunInfo] -> ShowS
PunInfo -> String
(Int -> PunInfo -> ShowS)
-> (PunInfo -> String) -> ([PunInfo] -> ShowS) -> Show PunInfo
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [PunInfo] -> ShowS
$cshowList :: [PunInfo] -> ShowS
show :: PunInfo -> String
$cshow :: PunInfo -> String
showsPrec :: Int -> PunInfo -> ShowS
$cshowsPrec :: Int -> PunInfo -> ShowS
Show, Eq PunInfo
Eq PunInfo =>
(PunInfo -> PunInfo -> Ordering)
-> (PunInfo -> PunInfo -> Bool)
-> (PunInfo -> PunInfo -> Bool)
-> (PunInfo -> PunInfo -> Bool)
-> (PunInfo -> PunInfo -> Bool)
-> (PunInfo -> PunInfo -> PunInfo)
-> (PunInfo -> PunInfo -> PunInfo)
-> Ord PunInfo
PunInfo -> PunInfo -> Bool
PunInfo -> PunInfo -> Ordering
PunInfo -> PunInfo -> PunInfo
forall a.
Eq a =>
(a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
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
$cp1Ord :: Eq PunInfo
Ord, Typeable PunInfo
Constr
DataType
Typeable PunInfo =>
(forall (c :: * -> *).
 (forall d b. Data d => c (d -> b) -> d -> c b)
 -> (forall g. g -> c g) -> PunInfo -> c PunInfo)
-> (forall (c :: * -> *).
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c PunInfo)
-> (PunInfo -> Constr)
-> (PunInfo -> DataType)
-> (forall (t :: * -> *) (c :: * -> *).
    Typeable t =>
    (forall d. Data d => c (t d)) -> Maybe (c PunInfo))
-> (forall (t :: * -> * -> *) (c :: * -> *).
    Typeable t =>
    (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c PunInfo))
-> ((forall b. Data b => b -> b) -> PunInfo -> PunInfo)
-> (forall r r'.
    (r -> r' -> r)
    -> r -> (forall d. Data d => d -> r') -> PunInfo -> r)
-> (forall r r'.
    (r' -> r -> r)
    -> r -> (forall d. Data d => d -> r') -> PunInfo -> r)
-> (forall u. (forall d. Data d => d -> u) -> PunInfo -> [u])
-> (forall u. Int -> (forall d. Data d => d -> u) -> PunInfo -> u)
-> (forall (m :: * -> *).
    Monad m =>
    (forall d. Data d => d -> m d) -> PunInfo -> m PunInfo)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> PunInfo -> m PunInfo)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> PunInfo -> m PunInfo)
-> Data PunInfo
PunInfo -> Constr
PunInfo -> DataType
(forall b. Data b => b -> b) -> PunInfo -> PunInfo
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> PunInfo -> c PunInfo
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c 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)
$cTypeOrTerm :: Constr
$cIsTerm :: Constr
$cIsType :: Constr
$tPunInfo :: DataType
gmapMo :: (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 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 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 :: Int -> (forall d. Data d => d -> u) -> PunInfo -> u
$cgmapQi :: forall u. Int -> (forall d. Data d => d -> u) -> PunInfo -> u
gmapQ :: (forall d. Data d => d -> u) -> PunInfo -> [u]
$cgmapQ :: forall u. (forall d. Data d => d -> u) -> PunInfo -> [u]
gmapQr :: (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 :: (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 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 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 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 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
$cp1Data :: Typeable PunInfo
Data, Typeable, (forall x. PunInfo -> Rep PunInfo x)
-> (forall x. Rep PunInfo x -> PunInfo) -> Generic PunInfo
forall x. Rep PunInfo x -> PunInfo
forall x. PunInfo -> Rep PunInfo x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$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
(PTerm -> PTerm -> Bool) -> (PTerm -> PTerm -> Bool) -> Eq PTerm
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
Eq PTerm =>
(PTerm -> PTerm -> Ordering)
-> (PTerm -> PTerm -> Bool)
-> (PTerm -> PTerm -> Bool)
-> (PTerm -> PTerm -> Bool)
-> (PTerm -> PTerm -> Bool)
-> (PTerm -> PTerm -> PTerm)
-> (PTerm -> PTerm -> PTerm)
-> Ord PTerm
PTerm -> PTerm -> Bool
PTerm -> PTerm -> Ordering
PTerm -> PTerm -> PTerm
forall a.
Eq a =>
(a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
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
$cp1Ord :: Eq PTerm
Ord, Typeable PTerm
Constr
DataType
Typeable PTerm =>
(forall (c :: * -> *).
 (forall d b. Data d => c (d -> b) -> d -> c b)
 -> (forall g. g -> c g) -> PTerm -> c PTerm)
-> (forall (c :: * -> *).
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c PTerm)
-> (PTerm -> Constr)
-> (PTerm -> DataType)
-> (forall (t :: * -> *) (c :: * -> *).
    Typeable t =>
    (forall d. Data d => c (t d)) -> Maybe (c PTerm))
-> (forall (t :: * -> * -> *) (c :: * -> *).
    Typeable t =>
    (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c PTerm))
-> ((forall b. Data b => b -> b) -> PTerm -> PTerm)
-> (forall r r'.
    (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> PTerm -> r)
-> (forall r r'.
    (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> PTerm -> r)
-> (forall u. (forall d. Data d => d -> u) -> PTerm -> [u])
-> (forall u. Int -> (forall d. Data d => d -> u) -> PTerm -> u)
-> (forall (m :: * -> *).
    Monad m =>
    (forall d. Data d => d -> m d) -> PTerm -> m PTerm)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> PTerm -> m PTerm)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> PTerm -> m PTerm)
-> Data PTerm
PTerm -> Constr
PTerm -> DataType
(forall b. Data b => b -> b) -> PTerm -> PTerm
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> PTerm -> c PTerm
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c 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)
$cPConstSugar :: Constr
$cPRunElab :: Constr
$cPQuoteName :: Constr
$cPUnquote :: Constr
$cPQuasiquote :: Constr
$cPNoImplicits :: Constr
$cPUnifyLog :: Constr
$cPDisamb :: Constr
$cPCoerced :: Constr
$cPImpossible :: Constr
$cPElabError :: Constr
$cPTactics :: Constr
$cPProof :: Constr
$cPMetavar :: Constr
$cPIdiom :: Constr
$cPDoBlock :: Constr
$cPlaceholder :: Constr
$cPConstant :: Constr
$cPGoal :: Constr
$cPUniverse :: Constr
$cPType :: Constr
$cPHidden :: Constr
$cPAlternative :: Constr
$cPAs :: Constr
$cPDPair :: Constr
$cPPair :: Constr
$cPRewrite :: Constr
$cPResolveTC :: Constr
$cPTrue :: Constr
$cPCase :: Constr
$cPIfThenElse :: Constr
$cPMatchApp :: Constr
$cPAppBind :: Constr
$cPAppImpl :: Constr
$cPWithApp :: Constr
$cPApp :: Constr
$cPTyped :: Constr
$cPLet :: Constr
$cPPi :: Constr
$cPLam :: Constr
$cPPatvar :: Constr
$cPInferRef :: Constr
$cPRef :: Constr
$cPQuote :: Constr
$tPTerm :: DataType
gmapMo :: (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 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 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 :: Int -> (forall d. Data d => d -> u) -> PTerm -> u
$cgmapQi :: forall u. Int -> (forall d. Data d => d -> u) -> PTerm -> u
gmapQ :: (forall d. Data d => d -> u) -> PTerm -> [u]
$cgmapQ :: forall u. (forall d. Data d => d -> u) -> PTerm -> [u]
gmapQr :: (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 :: (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 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 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 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 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
$cp1Data :: Typeable PTerm
Data, Typeable, (forall x. PTerm -> Rep PTerm x)
-> (forall x. Rep PTerm x -> PTerm) -> Generic PTerm
forall x. Rep PTerm x -> PTerm
forall x. PTerm -> Rep PTerm x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$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
(PAltType -> PAltType -> Bool)
-> (PAltType -> PAltType -> Bool) -> Eq PAltType
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
Eq PAltType =>
(PAltType -> PAltType -> Ordering)
-> (PAltType -> PAltType -> Bool)
-> (PAltType -> PAltType -> Bool)
-> (PAltType -> PAltType -> Bool)
-> (PAltType -> PAltType -> Bool)
-> (PAltType -> PAltType -> PAltType)
-> (PAltType -> PAltType -> PAltType)
-> Ord PAltType
PAltType -> PAltType -> Bool
PAltType -> PAltType -> Ordering
PAltType -> PAltType -> PAltType
forall a.
Eq a =>
(a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
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
$cp1Ord :: Eq PAltType
Ord, Typeable PAltType
Constr
DataType
Typeable PAltType =>
(forall (c :: * -> *).
 (forall d b. Data d => c (d -> b) -> d -> c b)
 -> (forall g. g -> c g) -> PAltType -> c PAltType)
-> (forall (c :: * -> *).
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c PAltType)
-> (PAltType -> Constr)
-> (PAltType -> DataType)
-> (forall (t :: * -> *) (c :: * -> *).
    Typeable t =>
    (forall d. Data d => c (t d)) -> Maybe (c PAltType))
-> (forall (t :: * -> * -> *) (c :: * -> *).
    Typeable t =>
    (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c PAltType))
-> ((forall b. Data b => b -> b) -> PAltType -> PAltType)
-> (forall r r'.
    (r -> r' -> r)
    -> r -> (forall d. Data d => d -> r') -> PAltType -> r)
-> (forall r r'.
    (r' -> r -> r)
    -> r -> (forall d. Data d => d -> r') -> PAltType -> r)
-> (forall u. (forall d. Data d => d -> u) -> PAltType -> [u])
-> (forall u. Int -> (forall d. Data d => d -> u) -> PAltType -> u)
-> (forall (m :: * -> *).
    Monad m =>
    (forall d. Data d => d -> m d) -> PAltType -> m PAltType)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> PAltType -> m PAltType)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> PAltType -> m PAltType)
-> Data PAltType
PAltType -> Constr
PAltType -> DataType
(forall b. Data b => b -> b) -> PAltType -> PAltType
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> PAltType -> c PAltType
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c 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)
$cTryImplicit :: Constr
$cFirstSuccess :: Constr
$cExactlyOne :: Constr
$tPAltType :: DataType
gmapMo :: (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 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 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 :: Int -> (forall d. Data d => d -> u) -> PAltType -> u
$cgmapQi :: forall u. Int -> (forall d. Data d => d -> u) -> PAltType -> u
gmapQ :: (forall d. Data d => d -> u) -> PAltType -> [u]
$cgmapQ :: forall u. (forall d. Data d => d -> u) -> PAltType -> [u]
gmapQr :: (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 :: (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 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 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 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 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
$cp1Data :: Typeable PAltType
Data, (forall x. PAltType -> Rep PAltType x)
-> (forall x. Rep PAltType x -> PAltType) -> Generic PAltType
forall x. Rep PAltType x -> PAltType
forall x. PAltType -> Rep PAltType x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$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 f :: FC -> FC
f g :: FC -> FC
g (PQuote q :: Raw
q)                     = Raw -> PTerm
PQuote Raw
q
mapPTermFC f :: FC -> FC
f g :: FC -> FC
g (PRef fc :: FC
fc fcs :: [FC]
fcs n :: Name
n)                = FC -> [FC] -> Name -> PTerm
PRef (FC -> FC
g FC
fc) ((FC -> FC) -> [FC] -> [FC]
forall a b. (a -> b) -> [a] -> [b]
map FC -> FC
g [FC]
fcs) Name
n
mapPTermFC f :: FC -> FC
f g :: FC -> FC
g (PInferRef fc :: FC
fc fcs :: [FC]
fcs n :: Name
n)           = FC -> [FC] -> Name -> PTerm
PInferRef (FC -> FC
g FC
fc) ((FC -> FC) -> [FC] -> [FC]
forall a b. (a -> b) -> [a] -> [b]
map FC -> FC
g [FC]
fcs) Name
n
mapPTermFC f :: FC -> FC
f g :: FC -> FC
g (PPatvar fc :: FC
fc n :: Name
n)                 = FC -> Name -> PTerm
PPatvar (FC -> FC
g FC
fc) Name
n
mapPTermFC f :: FC -> FC
f g :: FC -> FC
g (PLam fc :: FC
fc n :: Name
n fc' :: FC
fc' t1 :: PTerm
t1 t2 :: 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 f :: FC -> FC
f g :: FC -> FC
g (PPi plic :: Plicity
plic n :: Name
n fc :: FC
fc t1 :: PTerm
t1 t2 :: 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 f :: FC -> FC
f g :: FC -> FC
g (PLet fc :: FC
fc rc :: RigCount
rc n :: Name
n fc' :: FC
fc' t1 :: PTerm
t1 t2 :: PTerm
t2 t3 :: 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 f :: FC -> FC
f g :: FC -> FC
g (PTyped t1 :: PTerm
t1 t2 :: 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 f :: FC -> FC
f g :: FC -> FC
g (PApp fc :: FC
fc t :: PTerm
t args :: [PArg]
args)               = FC -> PTerm -> [PArg] -> PTerm
PApp (FC -> FC
f FC
fc) ((FC -> FC) -> (FC -> FC) -> PTerm -> PTerm
mapPTermFC FC -> FC
f FC -> FC
g PTerm
t) ((PArg -> PArg) -> [PArg] -> [PArg]
forall a b. (a -> b) -> [a] -> [b]
map ((PTerm -> PTerm) -> PArg -> PArg
forall (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 f :: FC -> FC
f g :: FC -> FC
g (PWithApp fc :: FC
fc t :: PTerm
t arg :: 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 f :: FC -> FC
f g :: FC -> FC
g (PAppImpl t1 :: PTerm
t1 impls :: [ImplicitInfo]
impls)            = PTerm -> [ImplicitInfo] -> PTerm
PAppImpl ((FC -> FC) -> (FC -> FC) -> PTerm -> PTerm
mapPTermFC FC -> FC
f FC -> FC
g PTerm
t1) [ImplicitInfo]
impls
mapPTermFC f :: FC -> FC
f g :: FC -> FC
g (PAppBind fc :: FC
fc t :: PTerm
t args :: [PArg]
args)           = FC -> PTerm -> [PArg] -> PTerm
PAppBind (FC -> FC
f FC
fc) ((FC -> FC) -> (FC -> FC) -> PTerm -> PTerm
mapPTermFC FC -> FC
f FC -> FC
g PTerm
t) ((PArg -> PArg) -> [PArg] -> [PArg]
forall a b. (a -> b) -> [a] -> [b]
map ((PTerm -> PTerm) -> PArg -> PArg
forall (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 f :: FC -> FC
f g :: FC -> FC
g (PMatchApp fc :: FC
fc n :: Name
n)               = FC -> Name -> PTerm
PMatchApp (FC -> FC
f FC
fc) Name
n
mapPTermFC f :: FC -> FC
f g :: FC -> FC
g (PIfThenElse fc :: FC
fc t1 :: PTerm
t1 t2 :: PTerm
t2 t3 :: 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 f :: FC -> FC
f g :: FC -> FC
g (PCase fc :: FC
fc t :: PTerm
t cases :: [(PTerm, PTerm)]
cases)             = FC -> PTerm -> [(PTerm, PTerm)] -> PTerm
PCase (FC -> FC
f FC
fc) ((FC -> FC) -> (FC -> FC) -> PTerm -> PTerm
mapPTermFC FC -> FC
f FC -> FC
g PTerm
t) (((PTerm, PTerm) -> (PTerm, PTerm))
-> [(PTerm, PTerm)] -> [(PTerm, PTerm)]
forall a b. (a -> b) -> [a] -> [b]
map (\(l :: PTerm
l,r :: 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 f :: FC -> FC
f g :: FC -> FC
g (PTrue fc :: FC
fc info :: PunInfo
info)                = FC -> PunInfo -> PTerm
PTrue (FC -> FC
f FC
fc) PunInfo
info
mapPTermFC f :: FC -> FC
f g :: FC -> FC
g (PResolveTC fc :: FC
fc)                = FC -> PTerm
PResolveTC (FC -> FC
f FC
fc)
mapPTermFC f :: FC -> FC
f g :: FC -> FC
g (PRewrite fc :: FC
fc by :: Maybe Name
by t1 :: PTerm
t1 t2 :: PTerm
t2 t3 :: Maybe PTerm
t3)      = FC -> Maybe Name -> PTerm -> PTerm -> Maybe PTerm -> PTerm
PRewrite (FC -> FC
f FC
fc) Maybe Name
by ((FC -> FC) -> (FC -> FC) -> PTerm -> PTerm
mapPTermFC FC -> FC
f FC -> FC
g PTerm
t1) ((FC -> FC) -> (FC -> FC) -> PTerm -> PTerm
mapPTermFC FC -> FC
f FC -> FC
g PTerm
t2) ((PTerm -> PTerm) -> Maybe PTerm -> Maybe PTerm
forall (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 f :: FC -> FC
f g :: FC -> FC
g (PPair fc :: FC
fc hls :: [FC]
hls info :: PunInfo
info t1 :: PTerm
t1 t2 :: PTerm
t2)      = FC -> [FC] -> PunInfo -> PTerm -> PTerm -> PTerm
PPair (FC -> FC
f FC
fc) ((FC -> FC) -> [FC] -> [FC]
forall a b. (a -> b) -> [a] -> [b]
map FC -> FC
g [FC]
hls) PunInfo
info ((FC -> FC) -> (FC -> FC) -> PTerm -> PTerm
mapPTermFC FC -> FC
f FC -> FC
g PTerm
t1) ((FC -> FC) -> (FC -> FC) -> PTerm -> PTerm
mapPTermFC FC -> FC
f FC -> FC
g PTerm
t2)
mapPTermFC f :: FC -> FC
f g :: FC -> FC
g (PDPair fc :: FC
fc hls :: [FC]
hls info :: PunInfo
info t1 :: PTerm
t1 t2 :: PTerm
t2 t3 :: PTerm
t3)  = FC -> [FC] -> PunInfo -> PTerm -> PTerm -> PTerm -> PTerm
PDPair (FC -> FC
f FC
fc) ((FC -> FC) -> [FC] -> [FC]
forall a b. (a -> b) -> [a] -> [b]
map FC -> FC
g [FC]
hls) PunInfo
info ((FC -> FC) -> (FC -> FC) -> PTerm -> PTerm
mapPTermFC FC -> FC
f FC -> FC
g PTerm
t1) ((FC -> FC) -> (FC -> FC) -> PTerm -> PTerm
mapPTermFC FC -> FC
f FC -> FC
g PTerm
t2) ((FC -> FC) -> (FC -> FC) -> PTerm -> PTerm
mapPTermFC FC -> FC
f FC -> FC
g PTerm
t3)
mapPTermFC f :: FC -> FC
f g :: FC -> FC
g (PAs fc :: FC
fc n :: Name
n t :: 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 f :: FC -> FC
f g :: FC -> FC
g (PAlternative ns :: [(Name, Name)]
ns ty :: PAltType
ty ts :: [PTerm]
ts)        = [(Name, Name)] -> PAltType -> [PTerm] -> PTerm
PAlternative [(Name, Name)]
ns PAltType
ty ((PTerm -> PTerm) -> [PTerm] -> [PTerm]
forall a b. (a -> b) -> [a] -> [b]
map ((FC -> FC) -> (FC -> FC) -> PTerm -> PTerm
mapPTermFC FC -> FC
f FC -> FC
g) [PTerm]
ts)
mapPTermFC f :: FC -> FC
f g :: FC -> FC
g (PHidden t :: PTerm
t)                    = PTerm -> PTerm
PHidden ((FC -> FC) -> (FC -> FC) -> PTerm -> PTerm
mapPTermFC FC -> FC
f FC -> FC
g PTerm
t)
mapPTermFC f :: FC -> FC
f g :: FC -> FC
g (PType fc :: FC
fc)                     = FC -> PTerm
PType (FC -> FC
f FC
fc)
mapPTermFC f :: FC -> FC
f g :: FC -> FC
g (PUniverse fc :: FC
fc u :: Universe
u)               = FC -> Universe -> PTerm
PUniverse (FC -> FC
f FC
fc) Universe
u
mapPTermFC f :: FC -> FC
f g :: FC -> FC
g (PGoal fc :: FC
fc t1 :: PTerm
t1 n :: Name
n t2 :: 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 f :: FC -> FC
f g :: FC -> FC
g (PConstant fc :: FC
fc c :: Const
c)               = FC -> Const -> PTerm
PConstant (FC -> FC
f FC
fc) Const
c
mapPTermFC f :: FC -> FC
f g :: FC -> FC
g Placeholder                    = PTerm
Placeholder
mapPTermFC f :: FC -> FC
f g :: FC -> FC
g (PDoBlock dos :: [PDo]
dos) = [PDo] -> PTerm
PDoBlock ((PDo -> PDo) -> [PDo] -> [PDo]
forall a b. (a -> b) -> [a] -> [b]
map PDo -> PDo
mapPDoFC [PDo]
dos)
  where mapPDoFC :: PDo -> PDo
mapPDoFC (DoExp  fc :: FC
fc t :: PTerm
t) = FC -> PTerm -> PDo
forall t. FC -> t -> PDo' t
DoExp (FC -> FC
f FC
fc) ((FC -> FC) -> (FC -> FC) -> PTerm -> PTerm
mapPTermFC FC -> FC
f FC -> FC
g PTerm
t)
        mapPDoFC (DoBind fc :: FC
fc n :: Name
n nfc :: FC
nfc t :: PTerm
t) = FC -> Name -> FC -> PTerm -> PDo
forall t. FC -> Name -> FC -> t -> PDo' t
DoBind (FC -> FC
f FC
fc) Name
n (FC -> FC
g FC
nfc) ((FC -> FC) -> (FC -> FC) -> PTerm -> PTerm
mapPTermFC FC -> FC
f FC -> FC
g PTerm
t)
        mapPDoFC (DoBindP fc :: FC
fc t1 :: PTerm
t1 t2 :: PTerm
t2 alts :: [(PTerm, PTerm)]
alts) =
          FC -> PTerm -> PTerm -> [(PTerm, PTerm)] -> PDo
forall t. FC -> t -> t -> [(t, t)] -> PDo' t
DoBindP (FC -> FC
f FC
fc) ((FC -> FC) -> (FC -> FC) -> PTerm -> PTerm
mapPTermFC FC -> FC
f FC -> FC
g PTerm
t1) ((FC -> FC) -> (FC -> FC) -> PTerm -> PTerm
mapPTermFC FC -> FC
f FC -> FC
g PTerm
t2) (((PTerm, PTerm) -> (PTerm, PTerm))
-> [(PTerm, PTerm)] -> [(PTerm, PTerm)]
forall a b. (a -> b) -> [a] -> [b]
map (\(l :: PTerm
l,r :: 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
fc rc :: RigCount
rc n :: Name
n nfc :: FC
nfc t1 :: PTerm
t1 t2 :: PTerm
t2) = FC -> RigCount -> Name -> FC -> PTerm -> PTerm -> PDo
forall t. FC -> RigCount -> Name -> FC -> t -> t -> PDo' t
DoLet (FC -> FC
f FC
fc) RigCount
rc Name
n (FC -> FC
g FC
nfc) ((FC -> FC) -> (FC -> FC) -> PTerm -> PTerm
mapPTermFC FC -> FC
f FC -> FC
g PTerm
t1) ((FC -> FC) -> (FC -> FC) -> PTerm -> PTerm
mapPTermFC FC -> FC
f FC -> FC
g PTerm
t2)
        mapPDoFC (DoLetP fc :: FC
fc t1 :: PTerm
t1 t2 :: PTerm
t2 alts :: [(PTerm, PTerm)]
alts) =
          FC -> PTerm -> PTerm -> [(PTerm, PTerm)] -> PDo
forall t. FC -> t -> t -> [(t, t)] -> PDo' t
DoLetP (FC -> FC
f FC
fc) ((FC -> FC) -> (FC -> FC) -> PTerm -> PTerm
mapPTermFC FC -> FC
f FC -> FC
g PTerm
t1) ((FC -> FC) -> (FC -> FC) -> PTerm -> PTerm
mapPTermFC FC -> FC
f FC -> FC
g PTerm
t2) (((PTerm, PTerm) -> (PTerm, PTerm))
-> [(PTerm, PTerm)] -> [(PTerm, PTerm)]
forall a b. (a -> b) -> [a] -> [b]
map (\(l :: PTerm
l,r :: 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
fc h :: PTerm
h) = FC -> PTerm -> PDo
forall t. FC -> t -> PDo' t
DoRewrite (FC -> FC
f FC
fc) ((FC -> FC) -> (FC -> FC) -> PTerm -> PTerm
mapPTermFC FC -> FC
f FC -> FC
g PTerm
h)
mapPTermFC f :: FC -> FC
f g :: FC -> FC
g (PIdiom fc :: FC
fc t :: 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 f :: FC -> FC
f g :: FC -> FC
g (PMetavar fc :: FC
fc n :: Name
n)                = FC -> Name -> PTerm
PMetavar (FC -> FC
g FC
fc) Name
n
mapPTermFC f :: FC -> FC
f g :: FC -> FC
g (PProof tacs :: [PTactic]
tacs)                  = [PTactic] -> PTerm
PProof ((PTactic -> PTactic) -> [PTactic] -> [PTactic]
forall a b. (a -> b) -> [a] -> [b]
map ((PTerm -> PTerm) -> PTactic -> PTactic
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 f :: FC -> FC
f g :: FC -> FC
g (PTactics tacs :: [PTactic]
tacs)                = [PTactic] -> PTerm
PTactics ((PTactic -> PTactic) -> [PTactic] -> [PTactic]
forall a b. (a -> b) -> [a] -> [b]
map ((PTerm -> PTerm) -> PTactic -> PTactic
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 f :: FC -> FC
f g :: FC -> FC
g (PElabError err :: Err
err)               = Err -> PTerm
PElabError Err
err
mapPTermFC f :: FC -> FC
f g :: FC -> FC
g PImpossible                    = PTerm
PImpossible
mapPTermFC f :: FC -> FC
f g :: FC -> FC
g (PCoerced t :: PTerm
t)                   = PTerm -> PTerm
PCoerced ((FC -> FC) -> (FC -> FC) -> PTerm -> PTerm
mapPTermFC FC -> FC
f FC -> FC
g PTerm
t)
mapPTermFC f :: FC -> FC
f g :: FC -> FC
g (PDisamb msg :: [[Text]]
msg t :: PTerm
t)                = [[Text]] -> PTerm -> PTerm
PDisamb [[Text]]
msg ((FC -> FC) -> (FC -> FC) -> PTerm -> PTerm
mapPTermFC FC -> FC
f FC -> FC
g PTerm
t)
mapPTermFC f :: FC -> FC
f g :: FC -> FC
g (PUnifyLog t :: PTerm
t)                  = PTerm -> PTerm
PUnifyLog ((FC -> FC) -> (FC -> FC) -> PTerm -> PTerm
mapPTermFC FC -> FC
f FC -> FC
g PTerm
t)
mapPTermFC f :: FC -> FC
f g :: FC -> FC
g (PNoImplicits t :: PTerm
t)               = PTerm -> PTerm
PNoImplicits ((FC -> FC) -> (FC -> FC) -> PTerm -> PTerm
mapPTermFC FC -> FC
f FC -> FC
g PTerm
t)
mapPTermFC f :: FC -> FC
f g :: FC -> FC
g (PQuasiquote t1 :: PTerm
t1 t2 :: Maybe PTerm
t2)            = PTerm -> Maybe PTerm -> PTerm
PQuasiquote ((FC -> FC) -> (FC -> FC) -> PTerm -> PTerm
mapPTermFC FC -> FC
f FC -> FC
g PTerm
t1) ((PTerm -> PTerm) -> Maybe PTerm -> Maybe PTerm
forall (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 f :: FC -> FC
f g :: FC -> FC
g (PUnquote t :: PTerm
t)                   = PTerm -> PTerm
PUnquote ((FC -> FC) -> (FC -> FC) -> PTerm -> PTerm
mapPTermFC FC -> FC
f FC -> FC
g PTerm
t)
mapPTermFC f :: FC -> FC
f g :: FC -> FC
g (PRunElab fc :: FC
fc tm :: PTerm
tm ns :: [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 f :: FC -> FC
f g :: FC -> FC
g (PConstSugar fc :: FC
fc tm :: 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 f :: FC -> FC
f g :: FC -> FC
g (PQuoteName n :: Name
n x :: Bool
x fc :: 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 f :: PTerm -> PTerm
f t :: PTerm
t = PTerm -> PTerm
f (PTerm -> PTerm
mpt PTerm
t) where
  mpt :: PTerm -> PTerm
mpt (PLam fc :: FC
fc n :: Name
n nfc :: FC
nfc t :: PTerm
t s :: 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 p :: Plicity
p n :: Name
n nfc :: FC
nfc t :: PTerm
t s :: 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
fc rc :: RigCount
rc n :: Name
n nfc :: FC
nfc ty :: PTerm
ty v :: PTerm
v s :: 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
fc by :: Maybe Name
by t :: PTerm
t s :: PTerm
s g :: Maybe PTerm
g)  = FC -> Maybe Name -> PTerm -> PTerm -> Maybe PTerm -> PTerm
PRewrite FC
fc Maybe Name
by ((PTerm -> PTerm) -> PTerm -> PTerm
mapPT PTerm -> PTerm
f PTerm
t) ((PTerm -> PTerm) -> PTerm -> PTerm
mapPT PTerm -> PTerm
f PTerm
s) ((PTerm -> PTerm) -> Maybe PTerm -> Maybe PTerm
forall (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
fc t :: PTerm
t as :: [PArg]
as)          = FC -> PTerm -> [PArg] -> PTerm
PApp FC
fc ((PTerm -> PTerm) -> PTerm -> PTerm
mapPT PTerm -> PTerm
f PTerm
t) ((PArg -> PArg) -> [PArg] -> [PArg]
forall a b. (a -> b) -> [a] -> [b]
map ((PTerm -> PTerm) -> PArg -> PArg
forall (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
fc t :: PTerm
t a :: 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
fc t :: PTerm
t as :: [PArg]
as)      = FC -> PTerm -> [PArg] -> PTerm
PAppBind FC
fc ((PTerm -> PTerm) -> PTerm -> PTerm
mapPT PTerm -> PTerm
f PTerm
t) ((PArg -> PArg) -> [PArg] -> [PArg]
forall a b. (a -> b) -> [a] -> [b]
map ((PTerm -> PTerm) -> PArg -> PArg
forall (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
fc c :: PTerm
c os :: [(PTerm, PTerm)]
os)         = FC -> PTerm -> [(PTerm, PTerm)] -> PTerm
PCase FC
fc ((PTerm -> PTerm) -> PTerm -> PTerm
mapPT PTerm -> PTerm
f PTerm
c) (((PTerm, PTerm) -> (PTerm, PTerm))
-> [(PTerm, PTerm)] -> [(PTerm, PTerm)]
forall a b. (a -> b) -> [a] -> [b]
map ((PTerm -> PTerm) -> (PTerm, PTerm) -> (PTerm, PTerm)
forall t b. (t -> b) -> (t, t) -> (b, b)
pmap ((PTerm -> PTerm) -> PTerm -> PTerm
mapPT PTerm -> PTerm
f)) [(PTerm, PTerm)]
os)
  mpt (PIfThenElse fc :: FC
fc c :: PTerm
c t :: PTerm
t e :: 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 l :: PTerm
l r :: 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 :: [FC]
hls p :: PunInfo
p l :: PTerm
l r :: 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 :: [FC]
hls p :: PunInfo
p l :: PTerm
l t :: PTerm
t r :: 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 ns :: [(Name, Name)]
ns a :: PAltType
a as :: [PTerm]
as)  = [(Name, Name)] -> PAltType -> [PTerm] -> PTerm
PAlternative [(Name, Name)]
ns PAltType
a ((PTerm -> PTerm) -> [PTerm] -> [PTerm]
forall a b. (a -> b) -> [a] -> [b]
map ((PTerm -> PTerm) -> PTerm -> PTerm
mapPT PTerm -> PTerm
f) [PTerm]
as)
  mpt (PHidden t :: PTerm
t)             = PTerm -> PTerm
PHidden ((PTerm -> PTerm) -> PTerm -> PTerm
mapPT PTerm -> PTerm
f PTerm
t)
  mpt (PDoBlock ds :: [PDo]
ds)           = [PDo] -> PTerm
PDoBlock ((PDo -> PDo) -> [PDo] -> [PDo]
forall a b. (a -> b) -> [a] -> [b]
map ((PTerm -> PTerm) -> PDo -> PDo
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 ts :: [PTactic]
ts)             = [PTactic] -> PTerm
PProof ((PTactic -> PTactic) -> [PTactic] -> [PTactic]
forall a b. (a -> b) -> [a] -> [b]
map ((PTerm -> PTerm) -> PTactic -> PTactic
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 ts :: [PTactic]
ts)           = [PTactic] -> PTerm
PTactics ((PTactic -> PTactic) -> [PTactic] -> [PTactic]
forall a b. (a -> b) -> [a] -> [b]
map ((PTerm -> PTerm) -> PTactic -> PTactic
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 tm :: PTerm
tm)          = PTerm -> PTerm
PUnifyLog ((PTerm -> PTerm) -> PTerm -> PTerm
mapPT PTerm -> PTerm
f PTerm
tm)
  mpt (PDisamb ns :: [[Text]]
ns tm :: PTerm
tm)         = [[Text]] -> PTerm -> PTerm
PDisamb [[Text]]
ns ((PTerm -> PTerm) -> PTerm -> PTerm
mapPT PTerm -> PTerm
f PTerm
tm)
  mpt (PNoImplicits tm :: PTerm
tm)       = PTerm -> PTerm
PNoImplicits ((PTerm -> PTerm) -> PTerm -> PTerm
mapPT PTerm -> PTerm
f PTerm
tm)
  mpt (PGoal fc :: FC
fc r :: PTerm
r n :: Name
n sc :: 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 x :: PTerm
x                       = PTerm
x


data PTactic' t = Intro [Name] | Intros | Focus Name
                | Refine Name [Bool] | Rewrite t | DoUnify
                | Equiv t
                | Claim Name t
                | Unfocus
                | MatchRefine Name
                | LetTac Name t | LetTacTy Name t t
                | Exact t | Compute | Trivial | TCImplementation
                | ProofSearch Bool Bool Int (Maybe Name)
                              [Name] -- allowed local names
                              [Name] -- hints
                  -- ^ the bool is whether to search recursively
                | Solve
                | Attack
                | ProofState | ProofTerm | Undo
                | Try (PTactic' t) (PTactic' t)
                | TSeq (PTactic' t) (PTactic' t)
                | ApplyTactic t -- see Language.Reflection module
                | ByReflection t
                | Reflect t
                | Fill t
                | GoalType String (PTactic' t)
                | TCheck t
                | TEval t
                | TDocStr (Either Name Const)
                | TSearch t
                | Skip
                | TFail [ErrorReportPart]
                | Qed | Abandon
                | SourceFC
    deriving (Int -> PTactic' t -> ShowS
[PTactic' t] -> ShowS
PTactic' t -> String
(Int -> PTactic' t -> ShowS)
-> (PTactic' t -> String)
-> ([PTactic' t] -> ShowS)
-> Show (PTactic' t)
forall t. Show t => Int -> PTactic' t -> ShowS
forall t. Show t => [PTactic' t] -> ShowS
forall t. Show t => PTactic' t -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
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
(PTactic' t -> PTactic' t -> Bool)
-> (PTactic' t -> PTactic' t -> Bool) -> Eq (PTactic' t)
forall t. Eq t => PTactic' t -> PTactic' t -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: 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, Eq (PTactic' t)
Eq (PTactic' t) =>
(PTactic' t -> PTactic' t -> Ordering)
-> (PTactic' t -> PTactic' t -> Bool)
-> (PTactic' t -> PTactic' t -> Bool)
-> (PTactic' t -> PTactic' t -> Bool)
-> (PTactic' t -> PTactic' t -> Bool)
-> (PTactic' t -> PTactic' t -> PTactic' t)
-> (PTactic' t -> PTactic' t -> PTactic' t)
-> Ord (PTactic' t)
PTactic' t -> PTactic' t -> Bool
PTactic' t -> PTactic' t -> Ordering
PTactic' t -> PTactic' t -> PTactic' t
forall a.
Eq a =>
(a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
forall t. Ord t => Eq (PTactic' t)
forall t. Ord t => PTactic' t -> PTactic' t -> Bool
forall t. Ord t => PTactic' t -> PTactic' t -> Ordering
forall t. Ord t => PTactic' t -> PTactic' t -> PTactic' t
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
$cp1Ord :: forall t. Ord t => Eq (PTactic' t)
Ord, a -> PTactic' b -> PTactic' a
(a -> b) -> PTactic' a -> PTactic' b
(forall a b. (a -> b) -> PTactic' a -> PTactic' b)
-> (forall a b. a -> PTactic' b -> PTactic' a) -> Functor PTactic'
forall a b. a -> PTactic' b -> PTactic' a
forall a b. (a -> b) -> PTactic' a -> PTactic' b
forall (f :: * -> *).
(forall a b. (a -> b) -> f a -> f b)
-> (forall a b. a -> f b -> f a) -> Functor f
<$ :: a -> PTactic' b -> PTactic' a
$c<$ :: forall a b. a -> PTactic' b -> PTactic' a
fmap :: (a -> b) -> PTactic' a -> PTactic' b
$cfmap :: forall a b. (a -> b) -> PTactic' a -> PTactic' b
Functor, PTactic' a -> Bool
(a -> m) -> PTactic' a -> m
(a -> b -> b) -> b -> PTactic' a -> b
(forall m. Monoid m => PTactic' m -> m)
-> (forall m a. Monoid m => (a -> m) -> PTactic' a -> m)
-> (forall m a. Monoid m => (a -> m) -> PTactic' a -> m)
-> (forall a b. (a -> b -> b) -> b -> PTactic' a -> b)
-> (forall a b. (a -> b -> b) -> b -> PTactic' a -> b)
-> (forall b a. (b -> a -> b) -> b -> PTactic' a -> b)
-> (forall b a. (b -> a -> b) -> b -> PTactic' a -> b)
-> (forall a. (a -> a -> a) -> PTactic' a -> a)
-> (forall a. (a -> a -> a) -> PTactic' a -> a)
-> (forall a. PTactic' a -> [a])
-> (forall a. PTactic' a -> Bool)
-> (forall a. PTactic' a -> Int)
-> (forall a. Eq a => a -> PTactic' a -> Bool)
-> (forall a. Ord a => PTactic' a -> a)
-> (forall a. Ord a => PTactic' a -> a)
-> (forall a. Num a => PTactic' a -> a)
-> (forall a. Num a => PTactic' a -> a)
-> Foldable PTactic'
forall a. Eq a => a -> PTactic' a -> Bool
forall a. Num a => PTactic' a -> a
forall a. Ord a => PTactic' a -> a
forall m. Monoid m => PTactic' m -> m
forall a. PTactic' a -> Bool
forall a. PTactic' a -> Int
forall a. PTactic' a -> [a]
forall a. (a -> a -> a) -> PTactic' a -> a
forall m a. Monoid m => (a -> m) -> PTactic' a -> m
forall b a. (b -> a -> b) -> b -> PTactic' a -> b
forall a b. (a -> b -> b) -> b -> PTactic' a -> b
forall (t :: * -> *).
(forall m. Monoid m => t m -> m)
-> (forall m a. Monoid m => (a -> m) -> t a -> m)
-> (forall m a. Monoid m => (a -> m) -> t a -> m)
-> (forall a b. (a -> b -> b) -> b -> t a -> b)
-> (forall a b. (a -> b -> b) -> b -> t a -> b)
-> (forall b a. (b -> a -> b) -> b -> t a -> b)
-> (forall b a. (b -> a -> b) -> b -> t a -> b)
-> (forall a. (a -> a -> a) -> t a -> a)
-> (forall a. (a -> a -> a) -> t a -> a)
-> (forall a. t a -> [a])
-> (forall a. t a -> Bool)
-> (forall a. t a -> Int)
-> (forall a. Eq a => a -> t a -> Bool)
-> (forall a. Ord a => t a -> a)
-> (forall a. Ord a => t a -> a)
-> (forall a. Num a => t a -> a)
-> (forall a. Num a => t a -> a)
-> Foldable t
product :: PTactic' a -> a
$cproduct :: forall a. Num a => PTactic' a -> a
sum :: PTactic' a -> a
$csum :: forall a. Num a => PTactic' a -> a
minimum :: PTactic' a -> a
$cminimum :: forall a. Ord a => PTactic' a -> a
maximum :: PTactic' a -> a
$cmaximum :: forall a. Ord a => PTactic' a -> a
elem :: a -> PTactic' a -> Bool
$celem :: forall a. Eq a => a -> PTactic' a -> Bool
length :: PTactic' a -> Int
$clength :: forall a. PTactic' a -> Int
null :: PTactic' a -> Bool
$cnull :: forall a. PTactic' a -> Bool
toList :: PTactic' a -> [a]
$ctoList :: forall a. PTactic' a -> [a]
foldl1 :: (a -> a -> a) -> PTactic' a -> a
$cfoldl1 :: forall a. (a -> a -> a) -> PTactic' a -> a
foldr1 :: (a -> a -> a) -> PTactic' a -> a
$cfoldr1 :: forall a. (a -> a -> a) -> PTactic' a -> a
foldl' :: (b -> a -> b) -> b -> PTactic' a -> b
$cfoldl' :: forall b a. (b -> a -> b) -> b -> PTactic' a -> b
foldl :: (b -> a -> b) -> b -> PTactic' a -> b
$cfoldl :: forall b a. (b -> a -> b) -> b -> PTactic' a -> b
foldr' :: (a -> b -> b) -> b -> PTactic' a -> b
$cfoldr' :: forall a b. (a -> b -> b) -> b -> PTactic' a -> b
foldr :: (a -> b -> b) -> b -> PTactic' a -> b
$cfoldr :: forall a b. (a -> b -> b) -> b -> PTactic' a -> b
foldMap' :: (a -> m) -> PTactic' a -> m
$cfoldMap' :: forall m a. Monoid m => (a -> m) -> PTactic' a -> m
foldMap :: (a -> m) -> PTactic' a -> m
$cfoldMap :: forall m a. Monoid m => (a -> m) -> PTactic' a -> m
fold :: PTactic' m -> m
$cfold :: forall m. Monoid m => PTactic' m -> m
Foldable, Functor PTactic'
Foldable PTactic'
(Functor PTactic', Foldable PTactic') =>
(forall (f :: * -> *) a b.
 Applicative f =>
 (a -> f b) -> PTactic' a -> f (PTactic' b))
-> (forall (f :: * -> *) a.
    Applicative f =>
    PTactic' (f a) -> f (PTactic' a))
-> (forall (m :: * -> *) a b.
    Monad m =>
    (a -> m b) -> PTactic' a -> m (PTactic' b))
-> (forall (m :: * -> *) a.
    Monad m =>
    PTactic' (m a) -> m (PTactic' a))
-> Traversable PTactic'
(a -> f b) -> PTactic' a -> f (PTactic' b)
forall (t :: * -> *).
(Functor t, Foldable t) =>
(forall (f :: * -> *) a b.
 Applicative f =>
 (a -> f b) -> t a -> f (t b))
-> (forall (f :: * -> *) a. Applicative f => t (f a) -> f (t a))
-> (forall (m :: * -> *) a b.
    Monad m =>
    (a -> m b) -> t a -> m (t b))
-> (forall (m :: * -> *) a. Monad m => t (m a) -> m (t a))
-> Traversable t
forall (m :: * -> *) a. Monad m => 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 :: PTactic' (m a) -> m (PTactic' a)
$csequence :: forall (m :: * -> *) a. Monad m => PTactic' (m a) -> m (PTactic' a)
mapM :: (a -> m b) -> PTactic' a -> m (PTactic' b)
$cmapM :: forall (m :: * -> *) a b.
Monad m =>
(a -> m b) -> PTactic' a -> m (PTactic' b)
sequenceA :: PTactic' (f a) -> f (PTactic' a)
$csequenceA :: forall (f :: * -> *) a.
Applicative f =>
PTactic' (f a) -> f (PTactic' a)
traverse :: (a -> f b) -> PTactic' a -> f (PTactic' b)
$ctraverse :: forall (f :: * -> *) a b.
Applicative f =>
(a -> f b) -> PTactic' a -> f (PTactic' b)
$cp2Traversable :: Foldable PTactic'
$cp1Traversable :: Functor PTactic'
Traversable, Typeable (PTactic' t)
Constr
DataType
Typeable (PTactic' t) =>
(forall (c :: * -> *).
 (forall d b. Data d => c (d -> b) -> d -> c b)
 -> (forall g. g -> c g) -> PTactic' t -> c (PTactic' t))
-> (forall (c :: * -> *).
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c (PTactic' t))
-> (PTactic' t -> Constr)
-> (PTactic' t -> DataType)
-> (forall (t :: * -> *) (c :: * -> *).
    Typeable t =>
    (forall d. Data d => c (t d)) -> Maybe (c (PTactic' t)))
-> (forall (t :: * -> * -> *) (c :: * -> *).
    Typeable t =>
    (forall d e. (Data d, Data e) => c (t d e))
    -> Maybe (c (PTactic' t)))
-> ((forall b. Data b => b -> b) -> PTactic' t -> PTactic' t)
-> (forall r r'.
    (r -> r' -> r)
    -> r -> (forall d. Data d => d -> r') -> PTactic' t -> r)
-> (forall r r'.
    (r' -> r -> r)
    -> r -> (forall d. Data d => d -> r') -> PTactic' t -> r)
-> (forall u. (forall d. Data d => d -> u) -> PTactic' t -> [u])
-> (forall u.
    Int -> (forall d. Data d => d -> u) -> PTactic' t -> u)
-> (forall (m :: * -> *).
    Monad m =>
    (forall d. Data d => d -> m d) -> PTactic' t -> m (PTactic' t))
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> PTactic' t -> m (PTactic' t))
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> PTactic' t -> m (PTactic' t))
-> Data (PTactic' t)
PTactic' t -> Constr
PTactic' t -> DataType
(forall d. Data d => c (t d)) -> Maybe (c (PTactic' t))
(forall b. Data b => b -> b) -> PTactic' t -> PTactic' t
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> PTactic' t -> c (PTactic' t)
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c (PTactic' t)
forall t. Data t => Typeable (PTactic' t)
forall t. Data t => PTactic' t -> Constr
forall t. Data t => PTactic' t -> DataType
forall t.
Data t =>
(forall b. Data b => b -> b) -> PTactic' t -> PTactic' t
forall t u.
Data t =>
Int -> (forall d. Data d => d -> u) -> PTactic' t -> u
forall t u.
Data t =>
(forall d. Data d => d -> u) -> PTactic' t -> [u]
forall t r r'.
Data t =>
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> PTactic' t -> r
forall t r r'.
Data t =>
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> PTactic' t -> r
forall t (m :: * -> *).
(Data t, Monad m) =>
(forall d. Data d => d -> m d) -> PTactic' t -> m (PTactic' t)
forall t (m :: * -> *).
(Data t, MonadPlus m) =>
(forall d. Data d => d -> m d) -> PTactic' t -> m (PTactic' t)
forall t (c :: * -> *).
Data t =>
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c (PTactic' t)
forall t (c :: * -> *).
Data t =>
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> PTactic' t -> c (PTactic' t)
forall t (t :: * -> *) (c :: * -> *).
(Data t, Typeable t) =>
(forall d. Data d => c (t d)) -> Maybe (c (PTactic' t))
forall t (t :: * -> * -> *) (c :: * -> *).
(Data t, Typeable t) =>
(forall d e. (Data d, Data e) => c (t d e))
-> Maybe (c (PTactic' t))
forall a.
Typeable a =>
(forall (c :: * -> *).
 (forall d b. Data d => c (d -> b) -> d -> c b)
 -> (forall g. g -> c g) -> a -> c a)
-> (forall (c :: * -> *).
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c a)
-> (a -> Constr)
-> (a -> DataType)
-> (forall (t :: * -> *) (c :: * -> *).
    Typeable t =>
    (forall d. Data d => c (t d)) -> Maybe (c a))
-> (forall (t :: * -> * -> *) (c :: * -> *).
    Typeable t =>
    (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c a))
-> ((forall b. Data b => b -> b) -> a -> a)
-> (forall r r'.
    (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall r r'.
    (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall u. (forall d. Data d => d -> u) -> a -> [u])
-> (forall u. Int -> (forall d. Data d => d -> u) -> a -> u)
-> (forall (m :: * -> *).
    Monad m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> Data a
forall u. Int -> (forall d. Data d => d -> u) -> PTactic' t -> u
forall u. (forall d. Data d => d -> u) -> PTactic' t -> [u]
forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> PTactic' t -> r
forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> PTactic' t -> r
forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> PTactic' t -> m (PTactic' t)
forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> PTactic' t -> m (PTactic' t)
forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c (PTactic' t)
forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> PTactic' t -> c (PTactic' t)
forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c (PTactic' t))
forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e))
-> Maybe (c (PTactic' t))
$cSourceFC :: Constr
$cAbandon :: Constr
$cQed :: Constr
$cTFail :: Constr
$cSkip :: Constr
$cTSearch :: Constr
$cTDocStr :: Constr
$cTEval :: Constr
$cTCheck :: Constr
$cGoalType :: Constr
$cFill :: Constr
$cReflect :: Constr
$cByReflection :: Constr
$cApplyTactic :: Constr
$cTSeq :: Constr
$cTry :: Constr
$cUndo :: Constr
$cProofTerm :: Constr
$cProofState :: Constr
$cAttack :: Constr
$cSolve :: Constr
$cProofSearch :: Constr
$cTCImplementation :: Constr
$cTrivial :: Constr
$cCompute :: Constr
$cExact :: Constr
$cLetTacTy :: Constr
$cLetTac :: Constr
$cMatchRefine :: Constr
$cUnfocus :: Constr
$cClaim :: Constr
$cEquiv :: Constr
$cDoUnify :: Constr
$cRewrite :: Constr
$cRefine :: Constr
$cFocus :: Constr
$cIntros :: Constr
$cIntro :: Constr
$tPTactic' :: DataType
gmapMo :: (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 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 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 :: 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 d. Data d => d -> u) -> PTactic' t -> [u]
$cgmapQ :: forall t u.
Data t =>
(forall d. Data d => d -> u) -> PTactic' t -> [u]
gmapQr :: (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 :: (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 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 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 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 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)
$cp1Data :: forall t. Data t => Typeable (PTactic' t)
Data, (forall x. PTactic' t -> Rep (PTactic' t) x)
-> (forall x. Rep (PTactic' t) x -> PTactic' t)
-> Generic (PTactic' t)
forall x. Rep (PTactic' t) x -> PTactic' t
forall x. PTactic' t -> Rep (PTactic' t) x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
forall t x. Rep (PTactic' t) x -> PTactic' t
forall t x. PTactic' t -> Rep (PTactic' t) x
$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 nms :: [Name]
nms)      = 1 Int -> Int -> Int
forall a. Num a => a -> a -> a
+ [Name] -> Int
forall a. Sized a => a -> Int
size [Name]
nms
  size Intros           = 1
  size (Focus nm :: Name
nm)       = 1 Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Name -> Int
forall a. Sized a => a -> Int
size Name
nm
  size (Refine nm :: Name
nm bs :: [Bool]
bs)   = 1 Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Name -> Int
forall a. Sized a => a -> Int
size Name
nm Int -> Int -> Int
forall a. Num a => a -> a -> a
+ [Bool] -> Int
forall (t :: * -> *) a. Foldable t => t a -> Int
length [Bool]
bs
  size (Rewrite t :: a
t)      = 1 Int -> Int -> Int
forall a. Num a => a -> a -> a
+ a -> Int
forall a. Sized a => a -> Int
size a
t
  size (LetTac nm :: Name
nm t :: a
t)    = 1 Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Name -> Int
forall a. Sized a => a -> Int
size Name
nm Int -> Int -> Int
forall a. Num a => a -> a -> a
+ a -> Int
forall a. Sized a => a -> Int
size a
t
  size (Exact t :: a
t)        = 1 Int -> Int -> Int
forall a. Num a => a -> a -> a
+ a -> Int
forall a. Sized a => a -> Int
size a
t
  size Compute          = 1
  size Trivial          = 1
  size Solve            = 1
  size Attack           = 1
  size ProofState       = 1
  size ProofTerm        = 1
  size Undo             = 1
  size (Try l :: PTactic' a
l r :: PTactic' a
r)        = 1 Int -> Int -> Int
forall a. Num a => a -> a -> a
+ PTactic' a -> Int
forall a. Sized a => a -> Int
size PTactic' a
l Int -> Int -> Int
forall a. Num a => a -> a -> a
+ PTactic' a -> Int
forall a. Sized a => a -> Int
size PTactic' a
r
  size (TSeq l :: PTactic' a
l r :: PTactic' a
r)       = 1 Int -> Int -> Int
forall a. Num a => a -> a -> a
+ PTactic' a -> Int
forall a. Sized a => a -> Int
size PTactic' a
l Int -> Int -> Int
forall a. Num a => a -> a -> a
+ PTactic' a -> Int
forall a. Sized a => a -> Int
size PTactic' a
r
  size (ApplyTactic t :: a
t)  = 1 Int -> Int -> Int
forall a. Num a => a -> a -> a
+ a -> Int
forall a. Sized a => a -> Int
size a
t
  size (Reflect t :: a
t)      = 1 Int -> Int -> Int
forall a. Num a => a -> a -> a
+ a -> Int
forall a. Sized a => a -> Int
size a
t
  size (Fill t :: a
t)         = 1 Int -> Int -> Int
forall a. Num a => a -> a -> a
+ a -> Int
forall a. Sized a => a -> Int
size a
t
  size Qed              = 1
  size Abandon          = 1
  size Skip             = 1
  size (TFail ts :: [ErrorReportPart]
ts)       = 1 Int -> Int -> Int
forall a. Num a => a -> a -> a
+ [ErrorReportPart] -> Int
forall a. Sized a => a -> Int
size [ErrorReportPart]
ts
  size SourceFC         = 1
  size DoUnify          = 1
  size (Equiv t :: a
t)        = 1 Int -> Int -> Int
forall a. Num a => a -> a -> a
+ a -> Int
forall a. Sized a => a -> Int
size a
t
  size (Claim x :: Name
x y :: a
y)      = 1 Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Name -> Int
forall a. Sized a => a -> Int
size Name
x Int -> Int -> Int
forall a. Num a => a -> a -> a
+ a -> Int
forall a. Sized a => a -> Int
size a
y
  size Unfocus          = 1
  size (MatchRefine x :: Name
x)  = 1 Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Name -> Int
forall a. Sized a => a -> Int
size Name
x
  size (LetTacTy x :: Name
x y :: a
y z :: a
z) = 1 Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Name -> Int
forall a. Sized a => a -> Int
size Name
x Int -> Int -> Int
forall a. Num a => a -> a -> a
+ a -> Int
forall a. Sized a => a -> Int
size a
y Int -> Int -> Int
forall a. Num a => a -> a -> a
+ a -> Int
forall a. Sized a => a -> Int
size a
z
  size TCImplementation       = 1

type PTactic = PTactic' PTerm

data PDo' t = DoExp  FC t
            | DoBind FC Name FC t     -- ^ second FC is precise name location
            | DoBindP FC t t [(t,t)]
            | DoLet  FC RigCount Name FC t t   -- ^ second FC is precise name location
            | DoLetP FC t t [(t,t)]
            | DoRewrite FC t          -- rewrite in do block
    deriving (PDo' t -> PDo' t -> Bool
(PDo' t -> PDo' t -> Bool)
-> (PDo' t -> PDo' t -> Bool) -> Eq (PDo' t)
forall t. Eq t => PDo' t -> PDo' t -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: 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, Eq (PDo' t)
Eq (PDo' t) =>
(PDo' t -> PDo' t -> Ordering)
-> (PDo' t -> PDo' t -> Bool)
-> (PDo' t -> PDo' t -> Bool)
-> (PDo' t -> PDo' t -> Bool)
-> (PDo' t -> PDo' t -> Bool)
-> (PDo' t -> PDo' t -> PDo' t)
-> (PDo' t -> PDo' t -> PDo' t)
-> Ord (PDo' t)
PDo' t -> PDo' t -> Bool
PDo' t -> PDo' t -> Ordering
PDo' t -> PDo' t -> PDo' t
forall a.
Eq a =>
(a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
forall t. Ord t => Eq (PDo' t)
forall t. Ord t => PDo' t -> PDo' t -> Bool
forall t. Ord t => PDo' t -> PDo' t -> Ordering
forall t. Ord t => PDo' t -> PDo' t -> PDo' t
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
$cp1Ord :: forall t. Ord t => Eq (PDo' t)
Ord, a -> PDo' b -> PDo' a
(a -> b) -> PDo' a -> PDo' b
(forall a b. (a -> b) -> PDo' a -> PDo' b)
-> (forall a b. a -> PDo' b -> PDo' a) -> Functor PDo'
forall a b. a -> PDo' b -> PDo' a
forall a b. (a -> b) -> PDo' a -> PDo' b
forall (f :: * -> *).
(forall a b. (a -> b) -> f a -> f b)
-> (forall a b. a -> f b -> f a) -> Functor f
<$ :: a -> PDo' b -> PDo' a
$c<$ :: forall a b. a -> PDo' b -> PDo' a
fmap :: (a -> b) -> PDo' a -> PDo' b
$cfmap :: forall a b. (a -> b) -> PDo' a -> PDo' b
Functor, Typeable (PDo' t)
Constr
DataType
Typeable (PDo' t) =>
(forall (c :: * -> *).
 (forall d b. Data d => c (d -> b) -> d -> c b)
 -> (forall g. g -> c g) -> PDo' t -> c (PDo' t))
-> (forall (c :: * -> *).
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c (PDo' t))
-> (PDo' t -> Constr)
-> (PDo' t -> DataType)
-> (forall (t :: * -> *) (c :: * -> *).
    Typeable t =>
    (forall d. Data d => c (t d)) -> Maybe (c (PDo' t)))
-> (forall (t :: * -> * -> *) (c :: * -> *).
    Typeable t =>
    (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c (PDo' t)))
-> ((forall b. Data b => b -> b) -> PDo' t -> PDo' t)
-> (forall r r'.
    (r -> r' -> r)
    -> r -> (forall d. Data d => d -> r') -> PDo' t -> r)
-> (forall r r'.
    (r' -> r -> r)
    -> r -> (forall d. Data d => d -> r') -> PDo' t -> r)
-> (forall u. (forall d. Data d => d -> u) -> PDo' t -> [u])
-> (forall u. Int -> (forall d. Data d => d -> u) -> PDo' t -> u)
-> (forall (m :: * -> *).
    Monad m =>
    (forall d. Data d => d -> m d) -> PDo' t -> m (PDo' t))
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> PDo' t -> m (PDo' t))
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> PDo' t -> m (PDo' t))
-> Data (PDo' t)
PDo' t -> Constr
PDo' t -> DataType
(forall d. Data d => c (t d)) -> Maybe (c (PDo' t))
(forall b. Data b => b -> b) -> PDo' t -> PDo' t
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> PDo' t -> c (PDo' t)
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c (PDo' t)
forall t. Data t => Typeable (PDo' t)
forall t. Data t => PDo' t -> Constr
forall t. Data t => PDo' t -> DataType
forall t.
Data t =>
(forall b. Data b => b -> b) -> PDo' t -> PDo' t
forall t u.
Data t =>
Int -> (forall d. Data d => d -> u) -> PDo' t -> u
forall t u. Data t => (forall d. Data d => d -> u) -> PDo' t -> [u]
forall t r r'.
Data t =>
(r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> PDo' t -> r
forall t r r'.
Data t =>
(r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> PDo' t -> r
forall t (m :: * -> *).
(Data t, Monad m) =>
(forall d. Data d => d -> m d) -> PDo' t -> m (PDo' t)
forall t (m :: * -> *).
(Data t, MonadPlus m) =>
(forall d. Data d => d -> m d) -> PDo' t -> m (PDo' t)
forall t (c :: * -> *).
Data t =>
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c (PDo' t)
forall t (c :: * -> *).
Data t =>
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> PDo' t -> c (PDo' t)
forall t (t :: * -> *) (c :: * -> *).
(Data t, Typeable t) =>
(forall d. Data d => c (t d)) -> Maybe (c (PDo' t))
forall t (t :: * -> * -> *) (c :: * -> *).
(Data t, Typeable t) =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c (PDo' t))
forall a.
Typeable a =>
(forall (c :: * -> *).
 (forall d b. Data d => c (d -> b) -> d -> c b)
 -> (forall g. g -> c g) -> a -> c a)
-> (forall (c :: * -> *).
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c a)
-> (a -> Constr)
-> (a -> DataType)
-> (forall (t :: * -> *) (c :: * -> *).
    Typeable t =>
    (forall d. Data d => c (t d)) -> Maybe (c a))
-> (forall (t :: * -> * -> *) (c :: * -> *).
    Typeable t =>
    (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c a))
-> ((forall b. Data b => b -> b) -> a -> a)
-> (forall r r'.
    (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall r r'.
    (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall u. (forall d. Data d => d -> u) -> a -> [u])
-> (forall u. Int -> (forall d. Data d => d -> u) -> a -> u)
-> (forall (m :: * -> *).
    Monad m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> Data a
forall u. Int -> (forall d. Data d => d -> u) -> PDo' t -> u
forall u. (forall d. Data d => d -> u) -> PDo' t -> [u]
forall r r'.
(r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> PDo' t -> r
forall r r'.
(r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> PDo' t -> r
forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> PDo' t -> m (PDo' t)
forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> PDo' t -> m (PDo' t)
forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c (PDo' t)
forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> PDo' t -> c (PDo' t)
forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c (PDo' t))
forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c (PDo' t))
$cDoRewrite :: Constr
$cDoLetP :: Constr
$cDoLet :: Constr
$cDoBindP :: Constr
$cDoBind :: Constr
$cDoExp :: Constr
$tPDo' :: DataType
gmapMo :: (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 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 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 :: 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 d. Data d => d -> u) -> PDo' t -> [u]
$cgmapQ :: forall t u. Data t => (forall d. Data d => d -> u) -> PDo' t -> [u]
gmapQr :: (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 :: (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 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 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 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 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)
$cp1Data :: forall t. Data t => Typeable (PDo' t)
Data, (forall x. PDo' t -> Rep (PDo' t) x)
-> (forall x. Rep (PDo' t) x -> PDo' t) -> Generic (PDo' t)
forall x. Rep (PDo' t) x -> PDo' t
forall x. PDo' t -> Rep (PDo' t) x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
forall t x. Rep (PDo' t) x -> PDo' t
forall t x. PDo' t -> Rep (PDo' t) x
$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
fc t :: a
t)           = 1 Int -> Int -> Int
forall a. Num a => a -> a -> a
+ FC -> Int
forall a. Sized a => a -> Int
size FC
fc Int -> Int -> Int
forall a. Num a => a -> a -> a
+ a -> Int
forall a. Sized a => a -> Int
size a
t
  size (DoBind fc :: FC
fc nm :: Name
nm nfc :: FC
nfc t :: a
t)   = 1 Int -> Int -> Int
forall a. Num a => a -> a -> a
+ FC -> Int
forall a. Sized a => a -> Int
size FC
fc Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Name -> Int
forall a. Sized a => a -> Int
size Name
nm Int -> Int -> Int
forall a. Num a => a -> a -> a
+ FC -> Int
forall a. Sized a => a -> Int
size FC
nfc Int -> Int -> Int
forall a. Num a => a -> a -> a
+ a -> Int
forall a. Sized a => a -> Int
size a
t
  size (DoBindP fc :: FC
fc l :: a
l r :: a
r alts :: [(a, a)]
alts)  = 1 Int -> Int -> Int
forall a. Num a => a -> a -> a
+ FC -> Int
forall a. Sized a => a -> Int
size FC
fc Int -> Int -> Int
forall a. Num a => a -> a -> a
+ a -> Int
forall a. Sized a => a -> Int
size a
l  Int -> Int -> Int
forall a. Num a => a -> a -> a
+ a -> Int
forall a. Sized a => a -> Int
size a
r   Int -> Int -> Int
forall a. Num a => a -> a -> a
+ [(a, a)] -> Int
forall a. Sized a => a -> Int
size [(a, a)]
alts
  size (DoLet fc :: FC
fc rc :: RigCount
rc nm :: Name
nm nfc :: FC
nfc l :: a
l r :: a
r)  = 1 Int -> Int -> Int
forall a. Num a => a -> a -> a
+ FC -> Int
forall a. Sized a => a -> Int
size FC
fc Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Name -> Int
forall a. Sized a => a -> Int
size Name
nm Int -> Int -> Int
forall a. Num a => a -> a -> a
+ a -> Int
forall a. Sized a => a -> Int
size a
l   Int -> Int -> Int
forall a. Num a => a -> a -> a
+ a -> Int
forall a. Sized a => a -> Int
size a
r
  size (DoLetP fc :: FC
fc l :: a
l r :: a
r alts :: [(a, a)]
alts)   = 1 Int -> Int -> Int
forall a. Num a => a -> a -> a
+ FC -> Int
forall a. Sized a => a -> Int
size FC
fc Int -> Int -> Int
forall a. Num a => a -> a -> a
+ a -> Int
forall a. Sized a => a -> Int
size a
l  Int -> Int -> Int
forall a. Num a => a -> a -> a
+ a -> Int
forall a. Sized a => a -> Int
size a
r Int -> Int -> Int
forall a. Num a => a -> a -> a
+ [(a, a)] -> Int
forall a. Sized a => a -> Int
size [(a, a)]
alts
  size (DoRewrite fc :: FC
fc h :: a
h)       = 1 Int -> Int -> Int
forall a. Num a => a -> a -> a
+ FC -> Int
forall a. Sized a => a -> Int
size FC
fc Int -> Int -> Int
forall a. Num a => a -> a -> a
+ a -> Int
forall a. Sized a => a -> Int
size a
h

type PDo = PDo' PTerm

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

data PArg' t = PImp { PArg' t -> Int
priority    :: Int
                    , PArg' t -> Bool
machine_inf :: Bool -- ^ true if the machine inferred it
                    , PArg' t -> [ArgOpt]
argopts     :: [ArgOpt]
                    , PArg' t -> Name
pname       :: Name
                    , 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
                            , PArg' t -> t
getScript :: t
                            , getTm     :: t
                            }
             deriving (Int -> PArg' t -> ShowS
[PArg' t] -> ShowS
PArg' t -> String
(Int -> PArg' t -> ShowS)
-> (PArg' t -> String) -> ([PArg' t] -> ShowS) -> Show (PArg' t)
forall t. Show t => Int -> PArg' t -> ShowS
forall t. Show t => [PArg' t] -> ShowS
forall t. Show t => PArg' t -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
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
(PArg' t -> PArg' t -> Bool)
-> (PArg' t -> PArg' t -> Bool) -> Eq (PArg' t)
forall t. Eq t => PArg' t -> PArg' t -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: 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, Eq (PArg' t)
Eq (PArg' t) =>
(PArg' t -> PArg' t -> Ordering)
-> (PArg' t -> PArg' t -> Bool)
-> (PArg' t -> PArg' t -> Bool)
-> (PArg' t -> PArg' t -> Bool)
-> (PArg' t -> PArg' t -> Bool)
-> (PArg' t -> PArg' t -> PArg' t)
-> (PArg' t -> PArg' t -> PArg' t)
-> Ord (PArg' t)
PArg' t -> PArg' t -> Bool
PArg' t -> PArg' t -> Ordering
PArg' t -> PArg' t -> PArg' t
forall a.
Eq a =>
(a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
forall t. Ord t => Eq (PArg' t)
forall t. Ord t => PArg' t -> PArg' t -> Bool
forall t. Ord t => PArg' t -> PArg' t -> Ordering
forall t. Ord t => PArg' t -> PArg' t -> PArg' t
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
$cp1Ord :: forall t. Ord t => Eq (PArg' t)
Ord, a -> PArg' b -> PArg' a
(a -> b) -> PArg' a -> PArg' b
(forall a b. (a -> b) -> PArg' a -> PArg' b)
-> (forall a b. a -> PArg' b -> PArg' a) -> Functor PArg'
forall a b. a -> PArg' b -> PArg' a
forall a b. (a -> b) -> PArg' a -> PArg' b
forall (f :: * -> *).
(forall a b. (a -> b) -> f a -> f b)
-> (forall a b. a -> f b -> f a) -> Functor f
<$ :: a -> PArg' b -> PArg' a
$c<$ :: forall a b. a -> PArg' b -> PArg' a
fmap :: (a -> b) -> PArg' a -> PArg' b
$cfmap :: forall a b. (a -> b) -> PArg' a -> PArg' b
Functor, Typeable (PArg' t)
Constr
DataType
Typeable (PArg' t) =>
(forall (c :: * -> *).
 (forall d b. Data d => c (d -> b) -> d -> c b)
 -> (forall g. g -> c g) -> PArg' t -> c (PArg' t))
-> (forall (c :: * -> *).
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c (PArg' t))
-> (PArg' t -> Constr)
-> (PArg' t -> DataType)
-> (forall (t :: * -> *) (c :: * -> *).
    Typeable t =>
    (forall d. Data d => c (t d)) -> Maybe (c (PArg' t)))
-> (forall (t :: * -> * -> *) (c :: * -> *).
    Typeable t =>
    (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c (PArg' t)))
-> ((forall b. Data b => b -> b) -> PArg' t -> PArg' t)
-> (forall r r'.
    (r -> r' -> r)
    -> r -> (forall d. Data d => d -> r') -> PArg' t -> r)
-> (forall r r'.
    (r' -> r -> r)
    -> r -> (forall d. Data d => d -> r') -> PArg' t -> r)
-> (forall u. (forall d. Data d => d -> u) -> PArg' t -> [u])
-> (forall u. Int -> (forall d. Data d => d -> u) -> PArg' t -> u)
-> (forall (m :: * -> *).
    Monad m =>
    (forall d. Data d => d -> m d) -> PArg' t -> m (PArg' t))
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> PArg' t -> m (PArg' t))
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> PArg' t -> m (PArg' t))
-> Data (PArg' t)
PArg' t -> Constr
PArg' t -> DataType
(forall d. Data d => c (t d)) -> Maybe (c (PArg' t))
(forall b. Data b => b -> b) -> PArg' t -> PArg' t
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> PArg' t -> c (PArg' t)
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c (PArg' t)
forall t. Data t => Typeable (PArg' t)
forall t. Data t => PArg' t -> Constr
forall t. Data t => PArg' t -> DataType
forall t.
Data t =>
(forall b. Data b => b -> b) -> PArg' t -> PArg' t
forall t u.
Data t =>
Int -> (forall d. Data d => d -> u) -> PArg' t -> u
forall t u.
Data t =>
(forall d. Data d => d -> u) -> PArg' t -> [u]
forall t r r'.
Data t =>
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> PArg' t -> r
forall t r r'.
Data t =>
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> PArg' t -> r
forall t (m :: * -> *).
(Data t, Monad m) =>
(forall d. Data d => d -> m d) -> PArg' t -> m (PArg' t)
forall t (m :: * -> *).
(Data t, MonadPlus m) =>
(forall d. Data d => d -> m d) -> PArg' t -> m (PArg' t)
forall t (c :: * -> *).
Data t =>
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c (PArg' t)
forall t (c :: * -> *).
Data t =>
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> PArg' t -> c (PArg' t)
forall t (t :: * -> *) (c :: * -> *).
(Data t, Typeable t) =>
(forall d. Data d => c (t d)) -> Maybe (c (PArg' t))
forall t (t :: * -> * -> *) (c :: * -> *).
(Data t, Typeable t) =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c (PArg' t))
forall a.
Typeable a =>
(forall (c :: * -> *).
 (forall d b. Data d => c (d -> b) -> d -> c b)
 -> (forall g. g -> c g) -> a -> c a)
-> (forall (c :: * -> *).
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c a)
-> (a -> Constr)
-> (a -> DataType)
-> (forall (t :: * -> *) (c :: * -> *).
    Typeable t =>
    (forall d. Data d => c (t d)) -> Maybe (c a))
-> (forall (t :: * -> * -> *) (c :: * -> *).
    Typeable t =>
    (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c a))
-> ((forall b. Data b => b -> b) -> a -> a)
-> (forall r r'.
    (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall r r'.
    (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall u. (forall d. Data d => d -> u) -> a -> [u])
-> (forall u. Int -> (forall d. Data d => d -> u) -> a -> u)
-> (forall (m :: * -> *).
    Monad m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> Data a
forall u. Int -> (forall d. Data d => d -> u) -> PArg' t -> u
forall u. (forall d. Data d => d -> u) -> PArg' t -> [u]
forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> PArg' t -> r
forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> PArg' t -> r
forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> PArg' t -> m (PArg' t)
forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> PArg' t -> m (PArg' t)
forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c (PArg' t)
forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> PArg' t -> c (PArg' t)
forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c (PArg' t))
forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c (PArg' t))
$cPTacImplicit :: Constr
$cPConstraint :: Constr
$cPExp :: Constr
$cPImp :: Constr
$tPArg' :: DataType
gmapMo :: (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 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 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 :: 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 d. Data d => d -> u) -> PArg' t -> [u]
$cgmapQ :: forall t u.
Data t =>
(forall d. Data d => d -> u) -> PArg' t -> [u]
gmapQr :: (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 :: (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 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 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 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 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)
$cp1Data :: forall t. Data t => Typeable (PArg' t)
Data, (forall x. PArg' t -> Rep (PArg' t) x)
-> (forall x. Rep (PArg' t) x -> PArg' t) -> Generic (PArg' t)
forall x. Rep (PArg' t) x -> PArg' t
forall x. PArg' t -> Rep (PArg' t) x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
forall t x. Rep (PArg' t) x -> PArg' t
forall t x. PArg' t -> Rep (PArg' t) x
$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
(Int -> ArgOpt -> ShowS)
-> (ArgOpt -> String) -> ([ArgOpt] -> ShowS) -> Show ArgOpt
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
(ArgOpt -> ArgOpt -> Bool)
-> (ArgOpt -> ArgOpt -> Bool) -> Eq ArgOpt
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
Eq ArgOpt =>
(ArgOpt -> ArgOpt -> Ordering)
-> (ArgOpt -> ArgOpt -> Bool)
-> (ArgOpt -> ArgOpt -> Bool)
-> (ArgOpt -> ArgOpt -> Bool)
-> (ArgOpt -> ArgOpt -> Bool)
-> (ArgOpt -> ArgOpt -> ArgOpt)
-> (ArgOpt -> ArgOpt -> ArgOpt)
-> Ord ArgOpt
ArgOpt -> ArgOpt -> Bool
ArgOpt -> ArgOpt -> Ordering
ArgOpt -> ArgOpt -> ArgOpt
forall a.
Eq a =>
(a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
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
$cp1Ord :: Eq ArgOpt
Ord, Typeable ArgOpt
Constr
DataType
Typeable ArgOpt =>
(forall (c :: * -> *).
 (forall d b. Data d => c (d -> b) -> d -> c b)
 -> (forall g. g -> c g) -> ArgOpt -> c ArgOpt)
-> (forall (c :: * -> *).
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c ArgOpt)
-> (ArgOpt -> Constr)
-> (ArgOpt -> DataType)
-> (forall (t :: * -> *) (c :: * -> *).
    Typeable t =>
    (forall d. Data d => c (t d)) -> Maybe (c ArgOpt))
-> (forall (t :: * -> * -> *) (c :: * -> *).
    Typeable t =>
    (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c ArgOpt))
-> ((forall b. Data b => b -> b) -> ArgOpt -> ArgOpt)
-> (forall r r'.
    (r -> r' -> r)
    -> r -> (forall d. Data d => d -> r') -> ArgOpt -> r)
-> (forall r r'.
    (r' -> r -> r)
    -> r -> (forall d. Data d => d -> r') -> ArgOpt -> r)
-> (forall u. (forall d. Data d => d -> u) -> ArgOpt -> [u])
-> (forall u. Int -> (forall d. Data d => d -> u) -> ArgOpt -> u)
-> (forall (m :: * -> *).
    Monad m =>
    (forall d. Data d => d -> m d) -> ArgOpt -> m ArgOpt)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> ArgOpt -> m ArgOpt)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> ArgOpt -> m ArgOpt)
-> Data ArgOpt
ArgOpt -> Constr
ArgOpt -> DataType
(forall b. Data b => b -> b) -> ArgOpt -> ArgOpt
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> ArgOpt -> c ArgOpt
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c 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)
$cUnknownImp :: Constr
$cInaccessibleArg :: Constr
$cHideDisplay :: Constr
$cAlwaysShow :: Constr
$tArgOpt :: DataType
gmapMo :: (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 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 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 :: Int -> (forall d. Data d => d -> u) -> ArgOpt -> u
$cgmapQi :: forall u. Int -> (forall d. Data d => d -> u) -> ArgOpt -> u
gmapQ :: (forall d. Data d => d -> u) -> ArgOpt -> [u]
$cgmapQ :: forall u. (forall d. Data d => d -> u) -> ArgOpt -> [u]
gmapQr :: (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 :: (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 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 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 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 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
$cp1Data :: Typeable ArgOpt
Data, (forall x. ArgOpt -> Rep ArgOpt x)
-> (forall x. Rep ArgOpt x -> ArgOpt) -> Generic ArgOpt
forall x. Rep ArgOpt x -> ArgOpt
forall x. ArgOpt -> Rep ArgOpt x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$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 p :: Int
p _ l :: [ArgOpt]
l nm :: Name
nm trm :: a
trm)            = 1 Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Name -> Int
forall a. Sized a => a -> Int
size Name
nm Int -> Int -> Int
forall a. Num a => a -> a -> a
+ a -> Int
forall a. Sized a => a -> Int
size a
trm
  size (PExp p :: Int
p l :: [ArgOpt]
l nm :: Name
nm trm :: a
trm)              = 1 Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Name -> Int
forall a. Sized a => a -> Int
size Name
nm Int -> Int -> Int
forall a. Num a => a -> a -> a
+ a -> Int
forall a. Sized a => a -> Int
size a
trm
  size (PConstraint p :: Int
p l :: [ArgOpt]
l nm :: Name
nm trm :: a
trm)       = 1 Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Name -> Int
forall a. Sized a => a -> Int
size Name
nm Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Name -> Int
forall a. Sized a => a -> Int
size Name
nm  Int -> Int -> Int
forall a. Num a => a -> a -> a
+  a -> Int
forall a. Sized a => a -> Int
size a
trm
  size (PTacImplicit p :: Int
p l :: [ArgOpt]
l nm :: Name
nm scr :: a
scr trm :: a
trm)  = 1 Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Name -> Int
forall a. Sized a => a -> Int
size Name
nm Int -> Int -> Int
forall a. Num a => a -> a -> a
+ a -> Int
forall a. Sized a => a -> Int
size a
scr Int -> Int -> Int
forall a. Num a => a -> a -> a
+ a -> Int
forall a. Sized a => a -> Int
size a
trm

{-!
deriving instance Binary PArg'
!-}

pimp :: Name -> t -> Bool -> PArg' t
pimp n :: Name
n t :: t
t mach :: Bool
mach = Int -> Bool -> [ArgOpt] -> Name -> t -> PArg' t
forall t. Int -> Bool -> [ArgOpt] -> Name -> t -> PArg' t
PImp 1 Bool
mach [] Name
n t
t
pexp :: t -> PArg' t
pexp t :: t
t        = Int -> [ArgOpt] -> Name -> t -> PArg' t
forall t. Int -> [ArgOpt] -> Name -> t -> PArg' t
PExp 1 [] (Int -> String -> Name
sMN 0 "arg") t
t
pconst :: t -> PArg' t
pconst t :: t
t      = Int -> [ArgOpt] -> Name -> t -> PArg' t
forall t. Int -> [ArgOpt] -> Name -> t -> PArg' t
PConstraint 1 [] (Int -> String -> Name
sMN 0 "carg") t
t
ptacimp :: Name -> t -> t -> PArg' t
ptacimp n :: Name
n s :: t
s t :: t
t = Int -> [ArgOpt] -> Name -> t -> t -> PArg' t
forall t. Int -> [ArgOpt] -> Name -> t -> t -> PArg' t
PTacImplicit 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 _)              = Maybe FC
forall a. Maybe a
Nothing
highestFC (PRef fc :: FC
fc _ _)           = FC -> Maybe FC
forall a. a -> Maybe a
Just FC
fc
highestFC (PInferRef fc :: FC
fc _ _)      = FC -> Maybe FC
forall a. a -> Maybe a
Just FC
fc
highestFC (PPatvar fc :: FC
fc _)          = FC -> Maybe FC
forall a. a -> Maybe a
Just FC
fc
highestFC (PLam fc :: FC
fc _ _ _ _)       = FC -> Maybe FC
forall a. a -> Maybe a
Just FC
fc
highestFC (PPi _ _ _ _ _)         = Maybe FC
forall a. Maybe a
Nothing
highestFC (PLet fc :: FC
fc _ _ _ _ _ _)   = FC -> Maybe FC
forall a. a -> Maybe a
Just FC
fc
highestFC (PTyped tm :: PTerm
tm ty :: PTerm
ty)          = PTerm -> Maybe FC
highestFC PTerm
tm Maybe FC -> Maybe FC -> Maybe FC
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> PTerm -> Maybe FC
highestFC PTerm
ty
highestFC (PApp fc :: FC
fc _ _)           = FC -> Maybe FC
forall a. a -> Maybe a
Just FC
fc
highestFC (PAppBind fc :: FC
fc _ _)       = FC -> Maybe FC
forall a. a -> Maybe a
Just FC
fc
highestFC (PMatchApp fc :: FC
fc _)        = FC -> Maybe FC
forall a. a -> Maybe a
Just FC
fc
highestFC (PCase fc :: FC
fc _ _)          = FC -> Maybe FC
forall a. a -> Maybe a
Just FC
fc
highestFC (PIfThenElse fc :: FC
fc _ _ _)  = FC -> Maybe FC
forall a. a -> Maybe a
Just FC
fc
highestFC (PTrue fc :: FC
fc _)            = FC -> Maybe FC
forall a. a -> Maybe a
Just FC
fc
highestFC (PResolveTC fc :: FC
fc)         = FC -> Maybe FC
forall a. a -> Maybe a
Just FC
fc
highestFC (PRewrite fc :: FC
fc _ _ _ _)   = FC -> Maybe FC
forall a. a -> Maybe a
Just FC
fc
highestFC (PPair fc :: FC
fc _ _ _ _)      = FC -> Maybe FC
forall a. a -> Maybe a
Just FC
fc
highestFC (PDPair fc :: FC
fc _ _ _ _ _)   = FC -> Maybe FC
forall a. a -> Maybe a
Just FC
fc
highestFC (PAs fc :: FC
fc _ _)            = FC -> Maybe FC
forall a. a -> Maybe a
Just FC
fc
highestFC (PAlternative _ _ args :: [PTerm]
args) =
  case (PTerm -> Maybe FC) -> [PTerm] -> [FC]
forall a b. (a -> Maybe b) -> [a] -> [b]
mapMaybe PTerm -> Maybe FC
highestFC [PTerm]
args of
    [] -> Maybe FC
forall a. Maybe a
Nothing
    (fc :: FC
fc:_) -> FC -> Maybe FC
forall a. a -> Maybe a
Just FC
fc
highestFC (PHidden _)             = Maybe FC
forall a. Maybe a
Nothing
highestFC (PType fc :: FC
fc)              = FC -> Maybe FC
forall a. a -> Maybe a
Just FC
fc
highestFC (PUniverse _ _)         = Maybe FC
forall a. Maybe a
Nothing
highestFC (PGoal fc :: FC
fc _ _ _)        = FC -> Maybe FC
forall a. a -> Maybe a
Just FC
fc
highestFC (PConstant fc :: FC
fc _)        = FC -> Maybe FC
forall a. a -> Maybe a
Just FC
fc
highestFC Placeholder             = Maybe FC
forall a. Maybe a
Nothing
highestFC (PDoBlock lines :: [PDo]
lines) =
  case (PDo -> FC) -> [PDo] -> [FC]
forall a b. (a -> b) -> [a] -> [b]
map PDo -> FC
forall t. PDo' t -> FC
getDoFC [PDo]
lines of
    [] -> Maybe FC
forall a. Maybe a
Nothing
    (fc :: FC
fc:_) -> FC -> Maybe FC
forall a. a -> Maybe a
Just FC
fc
  where
    getDoFC :: PDo' t -> FC
getDoFC (DoExp fc :: FC
fc t :: t
t)          = FC
fc
    getDoFC (DoBind fc :: FC
fc nm :: Name
nm nfc :: FC
nfc t :: t
t)  = FC
fc
    getDoFC (DoBindP fc :: FC
fc l :: t
l r :: t
r alts :: [(t, t)]
alts) = FC
fc
    getDoFC (DoLet fc :: FC
fc rc :: RigCount
rc nm :: Name
nm nfc :: FC
nfc l :: t
l r :: t
r) = FC
fc
    getDoFC (DoLetP fc :: FC
fc l :: t
l r :: t
r alts :: [(t, t)]
alts)  = FC
fc
    getDoFC (DoRewrite fc :: FC
fc h :: t
h)      = FC
fc

highestFC (PIdiom fc :: FC
fc _)           = FC -> Maybe FC
forall a. a -> Maybe a
Just FC
fc
highestFC (PMetavar fc :: FC
fc _)         = FC -> Maybe FC
forall a. a -> Maybe a
Just FC
fc
highestFC (PProof _)              = Maybe FC
forall a. Maybe a
Nothing
highestFC (PTactics _)            = Maybe FC
forall a. Maybe a
Nothing
highestFC (PElabError _)          = Maybe FC
forall a. Maybe a
Nothing
highestFC PImpossible             = Maybe FC
forall a. Maybe a
Nothing
highestFC (PCoerced tm :: PTerm
tm)           = PTerm -> Maybe FC
highestFC PTerm
tm
highestFC (PDisamb _ opts :: PTerm
opts)        = PTerm -> Maybe FC
highestFC PTerm
opts
highestFC (PUnifyLog tm :: PTerm
tm)          = PTerm -> Maybe FC
highestFC PTerm
tm
highestFC (PNoImplicits tm :: PTerm
tm)       = PTerm -> Maybe FC
highestFC PTerm
tm
highestFC (PQuasiquote _ _)       = Maybe FC
forall a. Maybe a
Nothing
highestFC (PUnquote tm :: PTerm
tm)           = PTerm -> Maybe FC
highestFC PTerm
tm
highestFC (PQuoteName _ _ fc :: FC
fc)     = FC -> Maybe FC
forall a. a -> Maybe a
Just FC
fc
highestFC (PRunElab fc :: FC
fc _ _)       = FC -> Maybe FC
forall a. a -> Maybe a
Just FC
fc
highestFC (PConstSugar fc :: FC
fc _)      = FC -> Maybe FC
forall a. a -> Maybe a
Just FC
fc
highestFC (PAppImpl t :: PTerm
t _)          = 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
(Int -> InterfaceInfo -> ShowS)
-> (InterfaceInfo -> String)
-> ([InterfaceInfo] -> ShowS)
-> Show InterfaceInfo
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. InterfaceInfo -> Rep InterfaceInfo x)
-> (forall x. Rep InterfaceInfo x -> InterfaceInfo)
-> Generic InterfaceInfo
forall x. Rep InterfaceInfo x -> InterfaceInfo
forall x. InterfaceInfo -> Rep InterfaceInfo x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$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
(Int -> RecordInfo -> ShowS)
-> (RecordInfo -> String)
-> ([RecordInfo] -> ShowS)
-> Show RecordInfo
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. RecordInfo -> Rep RecordInfo x)
-> (forall x. Rep RecordInfo x -> RecordInfo) -> Generic RecordInfo
forall x. Rep RecordInfo x -> RecordInfo
forall x. RecordInfo -> Rep RecordInfo x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$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
(Int -> TIData -> ShowS)
-> (TIData -> String) -> ([TIData] -> ShowS) -> Show TIData
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. TIData -> Rep TIData x)
-> (forall x. Rep TIData x -> TIData) -> Generic TIData
forall x. Rep TIData x -> TIData
forall x. TIData -> Rep TIData x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$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
(Int -> FnInfo -> ShowS)
-> (FnInfo -> String) -> ([FnInfo] -> ShowS) -> Show FnInfo
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. FnInfo -> Rep FnInfo x)
-> (forall x. Rep FnInfo x -> FnInfo) -> Generic FnInfo
forall x. Rep FnInfo x -> FnInfo
forall x. FnInfo -> Rep FnInfo x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$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
(Int -> OptInfo -> ShowS)
-> (OptInfo -> String) -> ([OptInfo] -> ShowS) -> Show OptInfo
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. OptInfo -> Rep OptInfo x)
-> (forall x. Rep OptInfo x -> OptInfo) -> Generic OptInfo
forall x. Rep OptInfo x -> OptInfo
forall x. OptInfo -> Rep OptInfo x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$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 {
    DSL' t -> t
dsl_bind    :: t
  , DSL' t -> t
dsl_apply   :: t
  , DSL' t -> t
dsl_pure    :: t
  , DSL' t -> Maybe t
dsl_var     :: Maybe t
  , DSL' t -> Maybe t
index_first :: Maybe t
  , DSL' t -> Maybe t
index_next  :: Maybe t
  , DSL' t -> Maybe t
dsl_lambda  :: Maybe t
  , DSL' t -> Maybe t
dsl_let     :: Maybe t
  , DSL' t -> Maybe t
dsl_pi      :: Maybe t
  } deriving (Int -> DSL' t -> ShowS
[DSL' t] -> ShowS
DSL' t -> String
(Int -> DSL' t -> ShowS)
-> (DSL' t -> String) -> ([DSL' t] -> ShowS) -> Show (DSL' t)
forall t. Show t => Int -> DSL' t -> ShowS
forall t. Show t => [DSL' t] -> ShowS
forall t. Show t => DSL' t -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
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, a -> DSL' b -> DSL' a
(a -> b) -> DSL' a -> DSL' b
(forall a b. (a -> b) -> DSL' a -> DSL' b)
-> (forall a b. a -> DSL' b -> DSL' a) -> Functor DSL'
forall a b. a -> DSL' b -> DSL' a
forall a b. (a -> b) -> DSL' a -> DSL' b
forall (f :: * -> *).
(forall a b. (a -> b) -> f a -> f b)
-> (forall a b. a -> f b -> f a) -> Functor f
<$ :: a -> DSL' b -> DSL' a
$c<$ :: forall a b. a -> DSL' b -> DSL' a
fmap :: (a -> b) -> DSL' a -> DSL' b
$cfmap :: forall a b. (a -> b) -> DSL' a -> DSL' b
Functor, (forall x. DSL' t -> Rep (DSL' t) x)
-> (forall x. Rep (DSL' t) x -> DSL' t) -> Generic (DSL' t)
forall x. Rep (DSL' t) x -> DSL' t
forall x. DSL' t -> Rep (DSL' t) x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
forall t x. Rep (DSL' t) x -> DSL' t
forall t x. DSL' t -> Rep (DSL' t) x
$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
(Int -> SynContext -> ShowS)
-> (SynContext -> String)
-> ([SynContext] -> ShowS)
-> Show SynContext
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. SynContext -> Rep SynContext x)
-> (forall x. Rep SynContext x -> SynContext) -> Generic SynContext
forall x. Rep SynContext x -> SynContext
forall x. SynContext -> Rep SynContext x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$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
(Int -> Syntax -> ShowS)
-> (Syntax -> String) -> ([Syntax] -> ShowS) -> Show Syntax
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. Syntax -> Rep Syntax x)
-> (forall x. Rep Syntax x -> Syntax) -> Generic Syntax
forall x. Rep Syntax x -> Syntax
forall x. Syntax -> Rep Syntax x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep Syntax x -> Syntax
$cfrom :: forall x. Syntax -> Rep Syntax x
Generic)

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

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

data SSymbol = Keyword Name
             | Symbol String
             | Binding Name
             | Expr Name
             | SimpleExpr Name
    deriving (Int -> SSymbol -> ShowS
[SSymbol] -> ShowS
SSymbol -> String
(Int -> SSymbol -> ShowS)
-> (SSymbol -> String) -> ([SSymbol] -> ShowS) -> Show SSymbol
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [SSymbol] -> ShowS
$cshowList :: [SSymbol] -> ShowS
show :: SSymbol -> String
$cshow :: SSymbol -> String
showsPrec :: Int -> SSymbol -> ShowS
$cshowsPrec :: Int -> SSymbol -> ShowS
Show, SSymbol -> SSymbol -> Bool
(SSymbol -> SSymbol -> Bool)
-> (SSymbol -> SSymbol -> Bool) -> Eq SSymbol
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. SSymbol -> Rep SSymbol x)
-> (forall x. Rep SSymbol x -> SSymbol) -> Generic SSymbol
forall x. Rep SSymbol x -> SSymbol
forall x. SSymbol -> Rep SSymbol x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$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. SyntaxRules -> Rep SyntaxRules x)
-> (forall x. Rep SyntaxRules x -> SyntaxRules)
-> Generic SyntaxRules
forall x. Rep SyntaxRules x -> SyntaxRules
forall x. SyntaxRules -> Rep SyntaxRules x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$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 rules :: [Syntax]
rules (SyntaxRules sr :: [Syntax]
sr) = [Syntax] -> SyntaxRules
SyntaxRules [Syntax]
newRules
  where
    newRules :: [Syntax]
newRules = (Syntax -> Syntax -> Ordering) -> [Syntax] -> [Syntax]
forall a. (a -> a -> Ordering) -> [a] -> [a]
sortBy ([SSymbol] -> [SSymbol] -> Ordering
ruleSort ([SSymbol] -> [SSymbol] -> Ordering)
-> (Syntax -> [SSymbol]) -> Syntax -> Syntax -> Ordering
forall b c a. (b -> b -> c) -> (a -> b) -> a -> a -> c
`on` Syntax -> [SSymbol]
syntaxSymbols) ([Syntax]
rules [Syntax] -> [Syntax] -> [Syntax]
forall a. [a] -> [a] -> [a]
++ [Syntax]
sr)

    ruleSort :: [SSymbol] -> [SSymbol] -> Ordering
ruleSort [] []  = Ordering
EQ
    ruleSort [] _   = Ordering
LT
    ruleSort _ []   = Ordering
GT
    ruleSort (s1 :: SSymbol
s1:ss1 :: [SSymbol]
ss1) (s2 :: SSymbol
s2:ss2 :: [SSymbol]
ss2) =
      case SSymbol -> SSymbol -> Ordering
symCompare SSymbol
s1 SSymbol
s2 of
        EQ -> [SSymbol] -> [SSymbol] -> Ordering
ruleSort [SSymbol]
ss1 [SSymbol]
ss2
        r :: 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 n1 :: Name
n1) (Keyword n2 :: Name
n2)        = Name -> Name -> Ordering
forall a. Ord a => a -> a -> Ordering
compare Name
n1 Name
n2
    symCompare (Keyword _) _                    = Ordering
LT
    symCompare (Symbol _) (Keyword _)           = Ordering
GT
    symCompare (Symbol s1 :: String
s1) (Symbol s2 :: String
s2)          = String -> String -> Ordering
forall a. Ord a => a -> a -> Ordering
compare String
s1 String
s2
    symCompare (Symbol _) _                     = Ordering
LT
    symCompare (Binding _) (Keyword _)          = Ordering
GT
    symCompare (Binding _) (Symbol _)           = Ordering
GT
    symCompare (Binding b1 :: Name
b1) (Binding b2 :: Name
b2)        = Name -> Name -> Ordering
forall a. Ord a => a -> a -> Ordering
compare Name
b1 Name
b2
    symCompare (Binding _) _                    = Ordering
LT
    symCompare (Expr _) (Keyword _)             = Ordering
GT
    symCompare (Expr _) (Symbol _)              = Ordering
GT
    symCompare (Expr _) (Binding _)             = Ordering
GT
    symCompare (Expr e1 :: Name
e1) (Expr e2 :: Name
e2)              = Name -> Name -> Ordering
forall a. Ord a => a -> a -> Ordering
compare Name
e1 Name
e2
    symCompare (Expr _) _                       = Ordering
LT
    symCompare (SimpleExpr _) (Keyword _)       = Ordering
GT
    symCompare (SimpleExpr _) (Symbol _)        = Ordering
GT
    symCompare (SimpleExpr _) (Binding _)       = Ordering
GT
    symCompare (SimpleExpr _) (Expr _)          = Ordering
GT
    symCompare (SimpleExpr e1 :: Name
e1) (SimpleExpr e2 :: Name
e2)  = Name -> Name -> Ordering
forall a. Ord a => a -> a -> Ordering
compare Name
e1 Name
e2

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

data Using = UImplicit Name PTerm
           | UConstraint Name [Name]
    deriving (Int -> Using -> ShowS
[Using] -> ShowS
Using -> String
(Int -> Using -> ShowS)
-> (Using -> String) -> ([Using] -> ShowS) -> Show Using
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Using] -> ShowS
$cshowList :: [Using] -> ShowS
show :: Using -> String
$cshow :: Using -> String
showsPrec :: Int -> Using -> ShowS
$cshowsPrec :: Int -> Using -> ShowS
Show, Using -> Using -> Bool
(Using -> Using -> Bool) -> (Using -> Using -> Bool) -> Eq Using
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
Constr
DataType
Typeable Using =>
(forall (c :: * -> *).
 (forall d b. Data d => c (d -> b) -> d -> c b)
 -> (forall g. g -> c g) -> Using -> c Using)
-> (forall (c :: * -> *).
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c Using)
-> (Using -> Constr)
-> (Using -> DataType)
-> (forall (t :: * -> *) (c :: * -> *).
    Typeable t =>
    (forall d. Data d => c (t d)) -> Maybe (c Using))
-> (forall (t :: * -> * -> *) (c :: * -> *).
    Typeable t =>
    (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c Using))
-> ((forall b. Data b => b -> b) -> Using -> Using)
-> (forall r r'.
    (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> Using -> r)
-> (forall r r'.
    (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> Using -> r)
-> (forall u. (forall d. Data d => d -> u) -> Using -> [u])
-> (forall u. Int -> (forall d. Data d => d -> u) -> Using -> u)
-> (forall (m :: * -> *).
    Monad m =>
    (forall d. Data d => d -> m d) -> Using -> m Using)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> Using -> m Using)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> Using -> m Using)
-> Data Using
Using -> Constr
Using -> DataType
(forall b. Data b => b -> b) -> Using -> Using
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> Using -> c Using
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c 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)
$cUConstraint :: Constr
$cUImplicit :: Constr
$tUsing :: DataType
gmapMo :: (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 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 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 :: Int -> (forall d. Data d => d -> u) -> Using -> u
$cgmapQi :: forall u. Int -> (forall d. Data d => d -> u) -> Using -> u
gmapQ :: (forall d. Data d => d -> u) -> Using -> [u]
$cgmapQ :: forall u. (forall d. Data d => d -> u) -> Using -> [u]
gmapQr :: (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 :: (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 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 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 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 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
$cp1Data :: Typeable Using
Data, (forall x. Using -> Rep Using x)
-> (forall x. Rep Using x -> Using) -> Generic Using
forall x. Rep Using x -> Using
forall x. Using -> Rep Using x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$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
(Int -> SyntaxInfo -> ShowS)
-> (SyntaxInfo -> String)
-> ([SyntaxInfo] -> ShowS)
-> Show SyntaxInfo
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. SyntaxInfo -> Rep SyntaxInfo x)
-> (forall x. Rep SyntaxInfo x -> SyntaxInfo) -> Generic SyntaxInfo
forall x. Rep SyntaxInfo x -> SyntaxInfo
forall x. SyntaxInfo -> Rep SyntaxInfo x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$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 [] [] [] [] [] Name -> Name
forall a. a -> a
id Bool
False Bool
False Bool
False Maybe Int
forall a. Maybe a
Nothing 0 DSL
initDSL 0 Bool
True Bool
True

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


-- For inferring types of things

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

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

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

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

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



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

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

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

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

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

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

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

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

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

-- Defined in builtins.idr
sigmaTy :: Name
sigmaTy   = Name -> [String] -> Name
sNS (String -> Name
sUN "DPair") ["Builtins"]
sigmaCon :: Name
sigmaCon = Name -> [String] -> Name
sNS (String -> Name
sUN "MkDPair") ["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 p :: Plicity
p [] t :: PTerm
t = PTerm
t
piBindp p :: Plicity
p ((n :: Name
n, ty :: PTerm
ty):ns :: [(Name, PTerm)]
ns) t :: 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 _ tm :: PTerm
tm = (SimpleDoc OutputAnnotation -> ShowS
forall a. SimpleDoc a -> ShowS
displayS (SimpleDoc OutputAnnotation -> ShowS)
-> (PTerm -> SimpleDoc OutputAnnotation) -> PTerm -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Float -> Int -> Doc OutputAnnotation -> SimpleDoc OutputAnnotation
forall a. Float -> Int -> Doc a -> SimpleDoc a
renderPretty 1.0 10000000 (Doc OutputAnnotation -> SimpleDoc OutputAnnotation)
-> (PTerm -> Doc OutputAnnotation)
-> PTerm
-> SimpleDoc OutputAnnotation
forall b c a. (b -> c) -> (a -> b) -> a -> c
. PPOption -> PTerm -> Doc OutputAnnotation
prettyImp PPOption
defaultPPOption) PTerm
tm

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

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

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

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


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

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

-- | Pretty-print a high-level closed Idris term with no information
-- about precedence/associativity
prettyImp :: PPOption -- ^ pretty printing options
          -> PTerm    -- ^ the term to pretty-print
          -> Doc OutputAnnotation
prettyImp :: PPOption -> PTerm -> Doc OutputAnnotation
prettyImp impl :: 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 ist :: IState
ist = PPOption
-> [(Name, Bool)]
-> [Name]
-> [FixDecl]
-> PTerm
-> Doc OutputAnnotation
pprintPTerm PPOption
opt [] [] (IState -> [FixDecl]
idris_infixes IState
ist)
  where
    opt :: PPOption
opt = if LanguageExt
LinearTypes LanguageExt -> [LanguageExt] -> Bool
forall (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 ppo :: PPOption
ppo bnd :: [(Name, Bool)]
bnd docArgs :: [Name]
docArgs infixes :: [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 = 0
    funcAppPrec :: Int
funcAppPrec = 10
    lbrace :: Doc OutputAnnotation
lbrace = OutputAnnotation -> Doc OutputAnnotation -> Doc OutputAnnotation
forall a. a -> Doc a -> Doc a
annotate (String -> OutputAnnotation
AnnSyntax "{") (String -> Doc OutputAnnotation
forall a. String -> Doc a
text "{")
    rbrace :: Doc OutputAnnotation
rbrace = OutputAnnotation -> Doc OutputAnnotation -> Doc OutputAnnotation
forall a. a -> Doc a -> Doc a
annotate (String -> OutputAnnotation
AnnSyntax "}") (String -> Doc OutputAnnotation
forall a. String -> Doc a
text "}")
    percent :: Doc OutputAnnotation
percent = OutputAnnotation -> Doc OutputAnnotation -> Doc OutputAnnotation
forall a. a -> Doc a -> Doc a
annotate (String -> OutputAnnotation
AnnSyntax "%") (String -> Doc OutputAnnotation
forall a. String -> Doc a
text "%")

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

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

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

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

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

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

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

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

    prettyBindingOf :: Name -> Bool -> Doc OutputAnnotation
    prettyBindingOf :: Name -> Bool -> Doc OutputAnnotation
prettyBindingOf n :: Name
n imp :: Bool
imp = OutputAnnotation -> Doc OutputAnnotation -> Doc OutputAnnotation
forall a. a -> Doc a -> Doc a
annotate (Name -> Bool -> OutputAnnotation
AnnBoundName Name
n Bool
imp) (String -> Doc OutputAnnotation
forall a. String -> Doc a
text (Name -> String
display Name
n))
      where display :: Name -> String
display (UN n :: Text
n)    = Text -> String
T.unpack Text
n
            display (MN _ n :: 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 n :: Name
n ns :: [Text]
ns) = (String -> [String] -> String
forall a. [a] -> [[a]] -> [a]
intercalate "." ([String] -> String) -> ([Text] -> [String]) -> [Text] -> String
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Text -> String) -> [Text] -> [String]
forall a b. (a -> b) -> [a] -> [b]
map Text -> String
T.unpack ([Text] -> [String]) -> ([Text] -> [Text]) -> [Text] -> [String]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [Text] -> [Text]
forall a. [a] -> [a]
reverse) [Text]
ns String -> ShowS
forall a. [a] -> [a] -> [a]
++ "." String -> ShowS
forall a. [a] -> [a] -> [a]
++ Name -> String
display Name
n
            display n :: Name
n         = Name -> String
forall a. Show a => a -> String
show Name
n

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

-- | Strip away namespace information
basename :: Name -> Name
basename :: Name -> Name
basename (NS n :: Name
n _) = Name -> Name
basename Name
n
basename n :: 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 n :: Text
n) = Text
n Text -> Text -> Bool
forall a. Eq a => a -> a -> Bool
== String -> Text
T.pack "[__]"
isHoleName _      = 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
pterm = [Bool] -> Bool
forall (t :: * -> *). Foldable t => t Bool -> Bool
or [Name -> Bool
isHoleName Name
n | PRef _ _ n :: Name
n <- Int -> [PTerm] -> [PTerm]
forall a. Int -> [a] -> [a]
take 1000 ([PTerm] -> [PTerm]) -> [PTerm] -> [PTerm]
forall a b. (a -> b) -> a -> b
$ PTerm -> [PTerm]
forall on. Uniplate on => on -> [on]
universe PTerm
pterm]

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


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


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

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

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

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

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

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

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

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


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

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

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

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


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

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

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

allNamesIn :: PTerm -> [Name]
allNamesIn :: PTerm -> [Name]
allNamesIn tm :: PTerm
tm = [Name] -> [Name]
forall a. Eq a => [a] -> [a]
nub ([Name] -> [Name]) -> [Name] -> [Name]
forall a b. (a -> b) -> a -> b
$ Integer -> [Name] -> PTerm -> [Name]
forall a. (Eq a, Num a) => a -> [Name] -> PTerm -> [Name]
ni 0 [] PTerm
tm
  where -- TODO THINK added niTacImp, but is it right?
    ni :: a -> [Name] -> PTerm -> [Name]
ni 0 env :: [Name]
env (PRef _ _ n :: Name
n)
        | Bool -> Bool
not (Name
n Name -> [Name] -> Bool
forall (t :: * -> *) a. (Foldable t, Eq a) => a -> t a -> Bool
`elem` [Name]
env)          = [Name
n]
    ni 0 env :: [Name]
env (PPatvar _ n :: Name
n)            = [Name
n]
    ni 0 env :: [Name]
env (PApp _ f :: PTerm
f as :: [PArg]
as)            = a -> [Name] -> PTerm -> [Name]
ni 0 [Name]
env PTerm
f [Name] -> [Name] -> [Name]
forall a. [a] -> [a] -> [a]
++ (PArg -> [Name]) -> [PArg] -> [Name]
forall (t :: * -> *) a b. Foldable t => (a -> [b]) -> t a -> [b]
concatMap (a -> [Name] -> PTerm -> [Name]
ni 0 [Name]
env (PTerm -> [Name]) -> (PArg -> PTerm) -> PArg -> [Name]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. PArg -> PTerm
forall t. PArg' t -> t
getTm) [PArg]
as
    ni 0 env :: [Name]
env (PAppBind _ f :: PTerm
f as :: [PArg]
as)        = a -> [Name] -> PTerm -> [Name]
ni 0 [Name]
env PTerm
f [Name] -> [Name] -> [Name]
forall a. [a] -> [a] -> [a]
++ (PArg -> [Name]) -> [PArg] -> [Name]
forall (t :: * -> *) a b. Foldable t => (a -> [b]) -> t a -> [b]
concatMap (a -> [Name] -> PTerm -> [Name]
ni 0 [Name]
env (PTerm -> [Name]) -> (PArg -> PTerm) -> PArg -> [Name]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. PArg -> PTerm
forall t. PArg' t -> t
getTm) [PArg]
as
    ni 0 env :: [Name]
env (PWithApp _ f :: PTerm
f a :: PTerm
a)         = a -> [Name] -> PTerm -> [Name]
ni 0 [Name]
env PTerm
f [Name] -> [Name] -> [Name]
forall a. [a] -> [a] -> [a]
++ a -> [Name] -> PTerm -> [Name]
ni 0 [Name]
env PTerm
a
    ni 0 env :: [Name]
env (PAppImpl t :: PTerm
t _)           = a -> [Name] -> PTerm -> [Name]
ni 0 [Name]
env PTerm
t
    ni 0 env :: [Name]
env (PCase _ c :: PTerm
c os :: [(PTerm, PTerm)]
os)           = a -> [Name] -> PTerm -> [Name]
ni 0 [Name]
env PTerm
c [Name] -> [Name] -> [Name]
forall a. [a] -> [a] -> [a]
++ ((PTerm, PTerm) -> [Name]) -> [(PTerm, PTerm)] -> [Name]
forall (t :: * -> *) a b. Foldable t => (a -> [b]) -> t a -> [b]
concatMap (a -> [Name] -> PTerm -> [Name]
ni 0 [Name]
env (PTerm -> [Name])
-> ((PTerm, PTerm) -> PTerm) -> (PTerm, PTerm) -> [Name]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (PTerm, PTerm) -> PTerm
forall a b. (a, b) -> b
snd) [(PTerm, PTerm)]
os
    ni 0 env :: [Name]
env (PIfThenElse _ c :: PTerm
c t :: PTerm
t f :: PTerm
f)    = a -> [Name] -> PTerm -> [Name]
ni 0 [Name]
env PTerm
c [Name] -> [Name] -> [Name]
forall a. [a] -> [a] -> [a]
++ a -> [Name] -> PTerm -> [Name]
ni 0 [Name]
env PTerm
t [Name] -> [Name] -> [Name]
forall a. [a] -> [a] -> [a]
++ a -> [Name] -> PTerm -> [Name]
ni 0 [Name]
env PTerm
f
    ni 0 env :: [Name]
env (PLam fc :: FC
fc n :: Name
n _ ty :: PTerm
ty sc :: PTerm
sc)      = a -> [Name] -> PTerm -> [Name]
ni 0 [Name]
env PTerm
ty [Name] -> [Name] -> [Name]
forall a. [a] -> [a] -> [a]
++ a -> [Name] -> PTerm -> [Name]
ni 0 (Name
nName -> [Name] -> [Name]
forall a. a -> [a] -> [a]
:[Name]
env) PTerm
sc
    ni 0 env :: [Name]
env (PPi p :: Plicity
p n :: Name
n _ ty :: PTerm
ty sc :: PTerm
sc)        = a -> [Name] -> Plicity -> [Name]
niTacImp 0 [Name]
env Plicity
p [Name] -> [Name] -> [Name]
forall a. [a] -> [a] -> [a]
++ a -> [Name] -> PTerm -> [Name]
ni 0 [Name]
env PTerm
ty [Name] -> [Name] -> [Name]
forall a. [a] -> [a] -> [a]
++ a -> [Name] -> PTerm -> [Name]
ni 0 (Name
nName -> [Name] -> [Name]
forall a. a -> [a] -> [a]
:[Name]
env) PTerm
sc
    ni 0 env :: [Name]
env (PLet _ _ n :: Name
n _ ty :: PTerm
ty val :: PTerm
val sc :: PTerm
sc) = a -> [Name] -> PTerm -> [Name]
ni 0 [Name]
env PTerm
ty [Name] -> [Name] -> [Name]
forall a. [a] -> [a] -> [a]
++ a -> [Name] -> PTerm -> [Name]
ni 0 [Name]
env PTerm
val [Name] -> [Name] -> [Name]
forall a. [a] -> [a] -> [a]
++ a -> [Name] -> PTerm -> [Name]
ni 0 (Name
nName -> [Name] -> [Name]
forall a. a -> [a] -> [a]
:[Name]
env) PTerm
sc
    ni 0 env :: [Name]
env (PHidden tm :: PTerm
tm)             = a -> [Name] -> PTerm -> [Name]
ni 0 [Name]
env PTerm
tm
    ni 0 env :: [Name]
env (PGoal _ t :: PTerm
t _ sc :: PTerm
sc)         = a -> [Name] -> PTerm -> [Name]
ni 0 [Name]
env PTerm
t [Name] -> [Name] -> [Name]
forall a. [a] -> [a] -> [a]
++ a -> [Name] -> PTerm -> [Name]
ni 0 [Name]
env PTerm
sc
    ni 0 env :: [Name]
env (PIdiom _ tm :: PTerm
tm)            = a -> [Name] -> PTerm -> [Name]
ni 0 [Name]
env PTerm
tm
    ni 0 env :: [Name]
env (PRewrite _ _ l :: PTerm
l r :: PTerm
r _)     = a -> [Name] -> PTerm -> [Name]
ni 0 [Name]
env PTerm
l [Name] -> [Name] -> [Name]
forall a. [a] -> [a] -> [a]
++ a -> [Name] -> PTerm -> [Name]
ni 0 [Name]
env PTerm
r
    ni 0 env :: [Name]
env (PTyped l :: PTerm
l r :: PTerm
r)             = a -> [Name] -> PTerm -> [Name]
ni 0 [Name]
env PTerm
l [Name] -> [Name] -> [Name]
forall a. [a] -> [a] -> [a]
++ a -> [Name] -> PTerm -> [Name]
ni 0 [Name]
env PTerm
r
    ni 0 env :: [Name]
env (PPair _ _ _ l :: PTerm
l r :: PTerm
r)        = a -> [Name] -> PTerm -> [Name]
ni 0 [Name]
env PTerm
l [Name] -> [Name] -> [Name]
forall a. [a] -> [a] -> [a]
++ a -> [Name] -> PTerm -> [Name]
ni 0 [Name]
env PTerm
r
    ni 0 env :: [Name]
env (PDPair _ _ _ (PRef _ _ n :: Name
n) Placeholder r :: PTerm
r) = Name
n Name -> [Name] -> [Name]
forall a. a -> [a] -> [a]
: a -> [Name] -> PTerm -> [Name]
ni 0 [Name]
env PTerm
r
    ni 0 env :: [Name]
env (PDPair _ _ _ (PRef _ _ n :: Name
n) t :: PTerm
t r :: PTerm
r) = a -> [Name] -> PTerm -> [Name]
ni 0 [Name]
env PTerm
t [Name] -> [Name] -> [Name]
forall a. [a] -> [a] -> [a]
++ a -> [Name] -> PTerm -> [Name]
ni 0 (Name
nName -> [Name] -> [Name]
forall a. a -> [a] -> [a]
:[Name]
env) PTerm
r
    ni 0 env :: [Name]
env (PDPair _ _ _ l :: PTerm
l t :: PTerm
t r :: PTerm
r)     = a -> [Name] -> PTerm -> [Name]
ni 0 [Name]
env PTerm
l [Name] -> [Name] -> [Name]
forall a. [a] -> [a] -> [a]
++ a -> [Name] -> PTerm -> [Name]
ni 0 [Name]
env PTerm
t [Name] -> [Name] -> [Name]
forall a. [a] -> [a] -> [a]
++ a -> [Name] -> PTerm -> [Name]
ni 0 [Name]
env PTerm
r
    ni 0 env :: [Name]
env (PAs _ _ tm :: PTerm
tm)             = a -> [Name] -> PTerm -> [Name]
ni 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 0 env :: [Name]
env (PAlternative ns :: [(Name, Name)]
ns (ExactlyOne _) (a :: PTerm
a : as :: [PTerm]
as))
            = ((Name, Name) -> Name) -> [(Name, Name)] -> [Name]
forall a b. (a -> b) -> [a] -> [b]
map (Name, Name) -> Name
forall a b. (a, b) -> b
snd [(Name, Name)]
ns [Name] -> [Name] -> [Name]
forall a. [a] -> [a] -> [a]
++ a -> [Name] -> PTerm -> [Name]
ni 0 [Name]
env PTerm
a
    ni 0 env :: [Name]
env (PAlternative ns :: [(Name, Name)]
ns a :: PAltType
a ls :: [PTerm]
ls)   = ((Name, Name) -> Name) -> [(Name, Name)] -> [Name]
forall a b. (a -> b) -> [a] -> [b]
map (Name, Name) -> Name
forall a b. (a, b) -> b
snd [(Name, Name)]
ns [Name] -> [Name] -> [Name]
forall a. [a] -> [a] -> [a]
++ (PTerm -> [Name]) -> [PTerm] -> [Name]
forall (t :: * -> *) a b. Foldable t => (a -> [b]) -> t a -> [b]
concatMap (a -> [Name] -> PTerm -> [Name]
ni 0 [Name]
env) [PTerm]
ls
    ni 0 env :: [Name]
env (PUnifyLog tm :: PTerm
tm)           = a -> [Name] -> PTerm -> [Name]
ni 0 [Name]
env PTerm
tm
    ni 0 env :: [Name]
env (PDisamb _ tm :: PTerm
tm)           = a -> [Name] -> PTerm -> [Name]
ni 0 [Name]
env PTerm
tm
    ni 0 env :: [Name]
env (PNoImplicits tm :: PTerm
tm)        = a -> [Name] -> PTerm -> [Name]
ni 0 [Name]
env PTerm
tm
    ni 0 env :: [Name]
env (PCoerced tm :: PTerm
tm)            = a -> [Name] -> PTerm -> [Name]
ni 0 [Name]
env PTerm
tm
    ni 0 env :: [Name]
env (PRunElab _ tm :: PTerm
tm _)        = a -> [Name] -> PTerm -> [Name]
ni 0 [Name]
env PTerm
tm
    ni 0 env :: [Name]
env (PConstSugar _ tm :: PTerm
tm)       = a -> [Name] -> PTerm -> [Name]
ni 0 [Name]
env PTerm
tm
    ni 0 env :: [Name]
env tm :: PTerm
tm@(PDoBlock _)      = (PTerm -> [Name]) -> [PTerm] -> [Name]
forall (t :: * -> *) a b. Foldable t => (a -> [b]) -> t a -> [b]
concatMap (a -> [Name] -> PTerm -> [Name]
ni 0 [Name]
env) (PTerm -> [PTerm]
forall on. Uniplate on => on -> [on]
children PTerm
tm)
    ni 0 env :: [Name]
env tm :: PTerm
tm@(PProof _)        = (PTerm -> [Name]) -> [PTerm] -> [Name]
forall (t :: * -> *) a b. Foldable t => (a -> [b]) -> t a -> [b]
concatMap (a -> [Name] -> PTerm -> [Name]
ni 0 [Name]
env) (PTerm -> [PTerm]
forall on. Uniplate on => on -> [on]
children PTerm
tm)
    ni 0 env :: [Name]
env tm :: PTerm
tm@(PTactics _)      = (PTerm -> [Name]) -> [PTerm] -> [Name]
forall (t :: * -> *) a b. Foldable t => (a -> [b]) -> t a -> [b]
concatMap (a -> [Name] -> PTerm -> [Name]
ni 0 [Name]
env) (PTerm -> [PTerm]
forall on. Uniplate on => on -> [on]
children PTerm
tm)

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

    niTacImp :: a -> [Name] -> Plicity -> [Name]
niTacImp i :: a
i env :: [Name]
env (TacImp _ _ scr :: PTerm
scr _) = a -> [Name] -> PTerm -> [Name]
ni a
i [Name]
env PTerm
scr
    niTacImp _ _ _                  = []


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

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

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

    niTms :: Int -> S.Set Name -> [PTerm] -> S.Set Name
    niTms :: Int -> Set Name -> [PTerm] -> Set Name
niTms i :: Int
i set :: Set Name
set []        = Set Name
set
    niTms i :: Int
i set :: Set Name
set (x :: PTerm
x : xs :: [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 i :: Int
i set :: Set Name
set (TacImp _ _ scr :: PTerm
scr _) = Int -> Set Name -> PTerm -> Set Name
ni Int
i Set Name
set PTerm
scr
    niTacImp i :: Int
i set :: Set Name
set _                = 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 uvars :: [Name]
uvars ist :: IState
ist tm :: PTerm
tm
      = let (imps :: [Name]
imps, fns :: [Name]
fns) = State ([Name], [Name]) () -> ([Name], [Name]) -> ([Name], [Name])
forall s a. State s a -> s -> s
execState (Integer -> [Name] -> PTerm -> State ([Name], [Name]) ()
forall a (m :: * -> *).
(Eq a, Num a, Monad m) =>
a -> [Name] -> PTerm -> StateT ([Name], [Name]) m ()
ni 0 [] PTerm
tm) ([], []) in
            [Name] -> [Name]
forall a. Eq a => [a] -> [a]
nub [Name]
imps [Name] -> [Name] -> [Name]
forall a. Eq a => [a] -> [a] -> [a]
\\ [Name] -> [Name]
forall a. Eq a => [a] -> [a]
nub [Name]
fns
  where
    addImp :: a -> StateT ([a], b) m ()
addImp n :: a
n = do (imps :: [a]
imps, fns :: b
fns) <- StateT ([a], b) m ([a], b)
forall (m :: * -> *) s. Monad m => StateT s m s
get
                  ([a], b) -> StateT ([a], b) m ()
forall (m :: * -> *) s. Monad m => s -> StateT s m ()
put (a
n a -> [a] -> [a]
forall a. a -> [a] -> [a]
: [a]
imps, b
fns)
    addFn :: a -> StateT (a, [a]) m ()
addFn n :: a
n = do (imps :: a
imps, fns :: [a]
fns) <- StateT (a, [a]) m (a, [a])
forall (m :: * -> *) s. Monad m => StateT s m s
get
                 (a, [a]) -> StateT (a, [a]) m ()
forall (m :: * -> *) s. Monad m => s -> StateT s m ()
put (a
imps, a
na -> [a] -> [a]
forall a. a -> [a] -> [a]
: [a]
fns)

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

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

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

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

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

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

    niTacImp :: a -> [Name] -> Plicity -> [Name]
niTacImp i :: a
i env :: [Name]
env (TacImp _ _ scr :: PTerm
scr _) = a -> [Name] -> PTerm -> [Name]
ni a
i [Name]
env PTerm
scr
    niTacImp _ _ _                  = []

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

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

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

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

    niTacImp :: a -> [Name] -> Plicity -> [Name]
niTacImp i :: a
i env :: [Name]
env (TacImp _ _ scr :: PTerm
scr _) = a -> [Name] -> PTerm -> [Name]
ni a
i [Name]
env PTerm
scr
    niTacImp _ _ _                = []

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