1{-# LANGUAGE MultiParamTypeClasses, FlexibleInstances, DeriveFunctor,
2 TypeSynonymInstances, PatternGuards #-}
4module Idris.AbsSyntaxTree where
7import Idris.Core.Evaluate
8import Idris.Core.Elaborate hiding (Tactic(..))
9import Idris.Core.Typecheck
11import IRTS.CodegenCommon
13import Util.DynamicLinker
19import System.Console.Haskeline
22import Control.Monad.Trans.State.Strict
23import Control.Monad.Trans.Error
27import qualified Data.Text as T
28import qualified Data.Map as M
30import Data.Word (Word)
34import Text.PrettyPrint.Annotated.Leijen
36data IOption = IOption { opt_logLevel :: Int,
38 opt_typeintype :: Bool,
40 opt_showimp :: Bool, -- ^^ show implicits
41 opt_errContext :: Bool,
46 opt_codegen :: Codegen,
47 opt_outputTy :: OutputType,
48 opt_ibcsubdir :: FilePath,
49 opt_importdirs :: [FilePath],
53 opt_cmdline :: [Opt] -- remember whole command line
57defaultOpts = IOption { opt_logLevel = 0
58 , opt_typecase = False
59 , opt_typeintype = False
62 , opt_errContext = False
65 , opt_nobanner = False
68 , opt_outputTy = Executable
77data LanguageExt = TypeProviders | ErrorReflection deriving (Show, Eq, Read, Ord)
79-- | The output mode in use
80data OutputMode = RawOutput | IdeSlave Integer deriving Show
82-- TODO: Add 'module data' to IState, which can be saved out and reloaded quickly (i.e
83-- without typechecking).
84-- This will include all the functions and data declarations, plus fixity declarations
87-- | The global state used in the Idris monad
89 tt_ctxt :: Context, -- ^ All the currently defined names and their terms
90 idris_constraints :: [(UConstraint, FC)],
91 -- ^ A list of universe constraints and their corresponding source locations
92 idris_infixes :: [FixDecl], -- ^ Currently defined infix operators
93 idris_implicits :: Ctxt [PArg],
94 idris_statics :: Ctxt [Bool],
95 idris_classes :: Ctxt ClassInfo,
96 idris_dsls :: Ctxt DSL,
97 idris_optimisation :: Ctxt OptInfo,
98 idris_datatypes :: Ctxt TypeInfo,
99 idris_namehints :: Ctxt [Name],
100 idris_patdefs :: Ctxt ([([Name], Term, Term)], [PTerm]), -- not exported
101 -- ^ list of lhs/rhs, and a list of missing clauses
102 idris_flags :: Ctxt [FnOpt],
103 idris_callgraph :: Ctxt CGInfo, -- name, args used in each pos
104 idris_calledgraph :: Ctxt [Name],
105 idris_docstrings :: Ctxt String,
106 idris_totcheck :: [(FC, Name)], -- names to check totality on
107 idris_defertotcheck :: [(FC, Name)], -- names to check at the end
108 idris_options :: IOption,
110 idris_lineapps :: [((FilePath, Int), PTerm)],
111 -- ^ Full application LHS on source line
112 idris_metavars :: [(Name, (Maybe Name, Int, Bool))], -- ^ The currently defined but not proven metavariables
113 idris_coercions :: [Name],
114 idris_transforms :: [(Term, Term)],
115 idris_errRev :: [(Term, Term)],
116 syntax_rules :: [Syntax],
117 syntax_keywords :: [String],
118 imported :: [FilePath], -- ^ The imported modules
119 idris_scprims :: [(Name, (Int, PrimFn))],
120 idris_objs :: [(Codegen, FilePath)],
121 idris_libs :: [(Codegen, String)],
122 idris_cgflags :: [(Codegen, String)],
123 idris_hdrs :: [(Codegen, String)],
124 proof_list :: [(Name, [String])],
125 errLine :: Maybe Int,
126 lastParse :: Maybe Name,
127 indent_stack :: [Int],
128 brace_stack :: [Maybe Int],
129 hide_list :: [(Name, Maybe Accessibility)],
130 default_access :: Accessibility,
131 default_total :: Bool,
132 ibc_write :: [IBCWrite],
133 compiled_so :: Maybe String,
134 idris_dynamic_libs :: [DynamicLib],
135 idris_language_extensions :: [LanguageExt],
136 idris_outputmode :: OutputMode,
137 idris_colourRepl :: Bool,
138 idris_colourTheme :: ColourTheme,
139 idris_outh :: Handle,
140 idris_errorhandlers :: [Name],
141 idris_nameIdx :: (Int, Ctxt (Int, Name)),
142 module_aliases :: M.Map [T.Text] [T.Text]
145data SizeChange = Smaller | Same | Bigger | Unknown
148deriving instance Binary SizeChange
149deriving instance NFData SizeChange
152type SCGEntry = (Name, [Maybe (Int, SizeChange)])
154data CGInfo = CGInfo { argsdef :: [Name],
155 calls :: [(Name, [[Name]])],
161deriving instance Binary CGInfo
162deriving instance NFData CGInfo
165primDefs = [sUN "unsafePerformPrimIO",
166 sUN "mkLazyForeignPrim",
170-- information that needs writing for the current module's .ibc file
171data IBCWrite = IBCFix FixDecl
175 | IBCInstance Bool Name Name
182 | IBCObj Codegen FilePath
183 | IBCLib Codegen String
184 | IBCCGFlag Codegen String
186 | IBCHeader Codegen String
187 | IBCAccess Name Accessibility
188 | IBCMetaInformation Name MetaInformation
189 | IBCTotal Name Totality
190 | IBCFlags Name [FnOpt]
191 | IBCTrans (Term, Term)
192 | IBCErrRev (Term, Term)
196 | IBCDef Name -- i.e. main context
197 | IBCNameHint (Name, Name)
198 | IBCLineApp FilePath Int PTerm
201-- | The initial state for the compiler
203idrisInit = IState initContext [] [] emptyContext emptyContext emptyContext
204 emptyContext emptyContext emptyContext emptyContext
205 emptyContext emptyContext emptyContext emptyContext
207 [] [] defaultOpts 6 [] [] [] [] [] [] [] [] [] [] [] [] []
208 [] Nothing Nothing [] [] [] Hidden False [] Nothing [] [] RawOutput
209 True defaultTheme stdout [] (0, emptyContext) M.empty
211-- | The monad for the main REPL - reading and processing files and updating
212-- global state (hence the IO inner monad).
213--type Idris = WriterT [Either String (IO ())] (State IState a))
214type Idris = StateT IState (ErrorT Err IO)
216-- Commands in the REPL
235 | ChangeDirectory FilePath
238 | Compile Codegen String
243 | AddProof (Maybe Name)
255 | DynamicLink FilePath
260 | CaseSplitAt Bool Int Name
261 | AddClauseFrom Bool Int Name
262 | AddProofClauseFrom Bool Int Name
263 | AddMissing Bool Int Name
264 | MakeWith Bool Int Name
265 | DoProofSearch Bool Int Name [Name]
269 | SetColour ColourType IdrisColour
274data Opt = Filename String
286 | NoBuiltins -- only for the really primitive stuff!
311 | OutputTy OutputType
312 | Extension LanguageExt
313 | InterpretScript String
314 | TargetTriple String
320-- Parsed declarations
322data Fixity = Infixl { prec :: Int }
323 | Infixr { prec :: Int }
324 | InfixN { prec :: Int }
325 | PrefixN { prec :: Int }
328deriving instance Binary Fixity
329deriving instance NFData Fixity
332instance Show Fixity where
333 show (Infixl i) = "infixl " ++ show i
334 show (Infixr i) = "infixr " ++ show i
335 show (InfixN i) = "infix " ++ show i
336 show (PrefixN i) = "prefix " ++ show i
338data FixDecl = Fix Fixity String
341instance Show FixDecl where
342 show (Fix f s) = show f ++ " " ++ s
345deriving instance Binary FixDecl
346deriving instance NFData FixDecl
349instance Ord FixDecl where
350 compare (Fix x _) (Fix y _) = compare (prec x) (prec y)
353data Static = Static | Dynamic
356deriving instance Binary Static
357deriving instance NFData Static
360-- Mark bindings with their explicitness, and laziness
361data Plicity = Imp { pargopts :: [ArgOpt],
365 | Exp { pargopts :: [ArgOpt],
369 | Constraint { pargopts :: [ArgOpt],
372 | TacImp { pargopts :: [ArgOpt],
378plazy :: Plicity -> Bool
379plazy tm = Lazy `elem` pargopts tm
382deriving instance Binary Plicity
383deriving instance NFData Plicity
386impl = Imp [Lazy] Dynamic "" False
387expl = Exp [] Dynamic "" False
388expl_param = Exp [] Dynamic "" True
389constraint = Constraint [] Dynamic ""
390tacimpl t = TacImp [] Dynamic t ""
392data FnOpt = Inlinable -- always evaluate when simplifying
393 | TotalFn | PartialFn
394 | Coinductive | AssertTotal
395 | Dictionary -- type class dictionary, eval only when
396 -- a function argument, and further evaluation resutls
397 | Implicit -- implicit coercion
398 | CExport String -- export, with a C name
399 | ErrorHandler -- ^^ an error handler for use with the ErrorReflection extension
400 | ErrorReverse -- ^^ attempt to reverse normalise before showing in error
401 | Reflection -- a reflecting function, compile-time only
402 | Specialise [(Name, Maybe Int)] -- specialise it, freeze these names
405deriving instance Binary FnOpt
406deriving instance NFData FnOpt
411inlinable :: FnOpts -> Bool
412inlinable = elem Inlinable
414dictionary :: FnOpts -> Bool
415dictionary = elem Dictionary
418-- | Data declaration options
419data DataOpt = Codata -- Set if the the data-type is coinductive
420 | DefaultEliminator -- Set if an eliminator should be generated for data type
424type DataOpts = [DataOpt]
426-- | Top-level declarations such as compiler directives, definitions,
427-- datatypes and typeclasses.
429 = PFix FC Fixity [String] -- ^ Fixity declaration
430 | PTy String SyntaxInfo FC FnOpts Name t -- ^ Type declaration
431 | PPostulate String SyntaxInfo FC FnOpts Name t -- ^ Postulate
432 | PClauses FC FnOpts Name [PClause' t] -- ^ Pattern clause
433 | PCAF FC Name t -- ^ Top level constant
434 | PData String SyntaxInfo FC DataOpts (PData' t) -- ^ Data declaration.
435 | PParams FC [(Name, t)] [PDecl' t] -- ^ Params block
436 | PNamespace String [PDecl' t] -- ^ New namespace
437 | PRecord String SyntaxInfo FC Name t String Name t -- ^ Record declaration
438 | PClass String SyntaxInfo FC
441 [(Name, t)] -- parameters
442 [PDecl' t] -- declarations
443 -- ^ Type class: arguments are documentation, syntax info, source location, constraints,
444 -- class name, parameters, method declarations
445 | PInstance SyntaxInfo FC [t] -- constraints
448 t -- full instance type
449 (Maybe Name) -- explicit name
451 -- ^ Instance declaration: arguments are syntax info, source location, constraints,
452 -- class name, parameters, full instance type, optional explicit name, and definitions
453 | PDSL Name (DSL' t) -- ^ DSL declaration
454 | PSyntax FC Syntax -- ^ Syntax definition
455 | PMutual FC [PDecl' t] -- ^ Mutual block
456 | PDirective (Idris ()) -- ^ Compiler directive. The parser inserts the corresponding action in the Idris monad.
457 | PProvider SyntaxInfo FC Name t t -- ^ Type provider. The first t is the type, the second is the term
458 | PTransform FC Bool t t -- ^ Source-to-source transformation rule. If
459 -- bool is True, lhs and rhs must be convertible
462deriving instance Binary PDecl'
463deriving instance NFData PDecl'
466-- For elaborator state
467type ElabD a = Elab' [PDecl] a
469-- | One clause of a top-level definition. Term arguments to constructors are:
471-- 1. The whole application (missing for PClauseR and PWithR because they're within a "with" clause)
473-- 2. The list of extra 'with' patterns
475-- 3. The right-hand side
477-- 4. The where block (PDecl' t)
479data PClause' t = PClause FC Name t [t] t [PDecl' t] -- ^ A normal top-level definition.
480 | PWith FC Name t [t] t [PDecl' t]
481 | PClauseR FC [t] t [PDecl' t]
482 | PWithR FC [t] t [PDecl' t]
485deriving instance Binary PClause'
486deriving instance NFData PClause'
490data PData' t = PDatadecl { d_name :: Name, -- ^ The name of the datatype
491 d_tcon :: t, -- ^ Type constructor
492 d_cons :: [(String, Name, t, FC, [Name])] -- ^ Constructors
494 -- ^ Data declaration
495 | PLaterdecl { d_name :: Name, d_tcon :: t }
496 -- ^ "Placeholder" for data whose constructors are defined later
499deriving instance Binary PData'
500deriving instance NFData PData'
503-- Handy to get a free function for applying PTerm -> PTerm functions
504-- across a program, by deriving Functor
506type PDecl = PDecl' PTerm
507type PData = PData' PTerm
508type PClause = PClause' PTerm
510-- get all the names declared in a decl
512declared :: PDecl -> [Name]
513declared (PFix _ _ _) = []
514declared (PTy _ _ _ _ n t) = [n]
515declared (PPostulate _ _ _ _ n t) = [n]
516declared (PClauses _ _ n _) = [] -- not a declaration
517declared (PCAF _ n _) = [n]
518declared (PData _ _ _ _ (PDatadecl n _ ts)) = n : map fstt ts
519 where fstt (_, a, _, _, _) = a
520declared (PData _ _ _ _ (PLaterdecl n _)) = [n]
521declared (PParams _ _ ds) = concatMap declared ds
522declared (PNamespace _ ds) = concatMap declared ds
523declared (PRecord _ _ _ n _ _ c _) = [n, c]
524declared (PClass _ _ _ _ n _ ms) = n : concatMap declared ms
525declared (PInstance _ _ _ _ _ _ _ _) = []
526declared (PDSL n _) = [n]
527declared (PSyntax _ _) = []
528declared (PMutual _ ds) = concatMap declared ds
529declared (PDirective _) = []
531-- get the names declared, not counting nested parameter blocks
532tldeclared :: PDecl -> [Name]
533tldeclared (PFix _ _ _) = []
534tldeclared (PTy _ _ _ _ n t) = [n]
535tldeclared (PPostulate _ _ _ _ n t) = [n]
536tldeclared (PClauses _ _ n _) = [] -- not a declaration
537tldeclared (PRecord _ _ _ n _ _ c _) = [n, c]
538tldeclared (PData _ _ _ _ (PDatadecl n _ ts)) = n : map fstt ts
539 where fstt (_, a, _, _, _) = a
540tldeclared (PParams _ _ ds) = []
541tldeclared (PMutual _ ds) = concatMap tldeclared ds
542tldeclared (PNamespace _ ds) = concatMap tldeclared ds
543tldeclared (PClass _ _ _ _ n _ ms) = concatMap tldeclared ms
544tldeclared (PInstance _ _ _ _ _ _ _ _) = []
547defined :: PDecl -> [Name]
548defined (PFix _ _ _) = []
549defined (PTy _ _ _ _ n t) = []
550defined (PPostulate _ _ _ _ n t) = []
551defined (PClauses _ _ n _) = [n] -- not a declaration
552defined (PCAF _ n _) = [n]
553defined (PData _ _ _ _ (PDatadecl n _ ts)) = n : map fstt ts
554 where fstt (_, a, _, _, _) = a
555defined (PData _ _ _ _ (PLaterdecl n _)) = []
556defined (PParams _ _ ds) = concatMap defined ds
557defined (PNamespace _ ds) = concatMap defined ds
558defined (PRecord _ _ _ n _ _ c _) = [n, c]
559defined (PClass _ _ _ _ n _ ms) = n : concatMap defined ms
560defined (PInstance _ _ _ _ _ _ _ _) = []
561defined (PDSL n _) = [n]
562defined (PSyntax _ _) = []
563defined (PMutual _ ds) = concatMap defined ds
564defined (PDirective _) = []
567updateN :: [(Name, Name)] -> Name -> Name
568updateN ns n | Just n' <- lookup n ns = n'
571updateNs :: [(Name, Name)] -> PTerm -> PTerm
573updateNs ns t = mapPT updateRef t
574 where updateRef (PRef fc f) = PRef fc (updateN ns f)
577-- updateDNs :: [(Name, Name)] -> PDecl -> PDecl
579-- updateDNs ns (PTy s f n t) | Just n' <- lookup n ns = PTy s f n' t
580-- updateDNs ns (PClauses f n c) | Just n' <- lookup n ns = PClauses f n' (map updateCNs c)
581-- where updateCNs ns (PClause n l ts r ds)
582-- = PClause (updateN ns n) (fmap (updateNs ns) l)
583-- (map (fmap (updateNs ns)) ts)
584-- (fmap (updateNs ns) r)
585-- (map (updateDNs ns) ds)
588-- | High level language terms
589data PTerm = PQuote Raw
591 | PInferRef FC Name -- ^ A name to be defined later
593 | PLam Name PTerm PTerm
594 | PPi Plicity Name PTerm PTerm
595 | PLet Name PTerm PTerm PTerm
596 | PTyped PTerm PTerm -- ^ Term with explicit type
597 | PApp FC PTerm [PArg]
598 | PAppBind FC PTerm [PArg] -- ^ implicitly bound application
599 | PMatchApp FC Name -- ^ Make an application by type matching
600 | PCase FC PTerm [(PTerm, PTerm)]
606 | PRewrite FC PTerm PTerm (Maybe PTerm)
607 | PPair FC PTerm PTerm
608 | PDPair FC PTerm PTerm PTerm
609 | PAlternative Bool [PTerm] -- True if only one may work
610 | PHidden PTerm -- ^ Irrelevant or hidden pattern
612 | PGoal FC PTerm Name PTerm
619 | PProof [PTactic] -- ^ Proof script
620 | PTactics [PTactic] -- ^ As PProof, but no auto solving
621 | PElabError Err -- ^ Error to report on elaboration
622 | PImpossible -- ^ Special case for declaring when an LHS can't typecheck
623 | PCoerced PTerm -- ^ To mark a coerced argument, so as not to coerce twice
624 | PDisamb [[T.Text]] PTerm -- ^ Preferences for explicit namespaces
625 | PUnifyLog PTerm -- ^ dump a trace of unifications when building term
626 | PNoImplicits PTerm -- ^ never run implicit converions on the term
631deriving instance Binary PTerm
632deriving instance NFData PTerm
635mapPT :: (PTerm -> PTerm) -> PTerm -> PTerm
636mapPT f t = f (mpt t) where
637 mpt (PLam n t s) = PLam n (mapPT f t) (mapPT f s)
638 mpt (PPi p n t s) = PPi p n (mapPT f t) (mapPT f s)
639 mpt (PLet n ty v s) = PLet n (mapPT f ty) (mapPT f v) (mapPT f s)
640 mpt (PRewrite fc t s g) = PRewrite fc (mapPT f t) (mapPT f s)
642 mpt (PApp fc t as) = PApp fc (mapPT f t) (map (fmap (mapPT f)) as)
643 mpt (PAppBind fc t as) = PAppBind fc (mapPT f t) (map (fmap (mapPT f)) as)
644 mpt (PCase fc c os) = PCase fc (mapPT f c) (map (pmap (mapPT f)) os)
645 mpt (PEq fc l r) = PEq fc (mapPT f l) (mapPT f r)
646 mpt (PTyped l r) = PTyped (mapPT f l) (mapPT f r)
647 mpt (PPair fc l r) = PPair fc (mapPT f l) (mapPT f r)
648 mpt (PDPair fc l t r) = PDPair fc (mapPT f l) (mapPT f t) (mapPT f r)
649 mpt (PAlternative a as) = PAlternative a (map (mapPT f) as)
650 mpt (PHidden t) = PHidden (mapPT f t)
651 mpt (PDoBlock ds) = PDoBlock (map (fmap (mapPT f)) ds)
652 mpt (PProof ts) = PProof (map (fmap (mapPT f)) ts)
653 mpt (PTactics ts) = PTactics (map (fmap (mapPT f)) ts)
654 mpt (PUnifyLog tm) = PUnifyLog (mapPT f tm)
655 mpt (PDisamb ns tm) = PDisamb ns (mapPT f tm)
656 mpt (PNoImplicits tm) = PNoImplicits (mapPT f tm)
657 mpt (PGoal fc r n sc) = PGoal fc (mapPT f r) n (mapPT f sc)
661data PTactic' t = Intro [Name] | Intros | Focus Name
662 | Refine Name [Bool] | Rewrite t
666 | LetTac Name t | LetTacTy Name t t
667 | Exact t | Compute | Trivial
668 | ProofSearch (Maybe Name) Name [Name]
671 | ProofState | ProofTerm | Undo
672 | Try (PTactic' t) (PTactic' t)
673 | TSeq (PTactic' t) (PTactic' t)
674 | ApplyTactic t -- see Language.Reflection module
678 | GoalType String (PTactic' t)
680 deriving (Show, Eq, Functor)
682deriving instance Binary PTactic'
683deriving instance NFData PTactic'
686instance Sized a => Sized (PTactic' a) where
687 size (Intro nms) = 1 + size nms
689 size (Focus nm) = 1 + size nm
690 size (Refine nm bs) = 1 + size nm + length bs
691 size (Rewrite t) = 1 + size t
692 size (Induction t) = 1 + size t
693 size (LetTac nm t) = 1 + size nm + size t
694 size (Exact t) = 1 + size t
702 size (Try l r) = 1 + size l + size r
703 size (TSeq l r) = 1 + size l + size r
704 size (ApplyTactic t) = 1 + size t
705 size (Reflect t) = 1 + size t
706 size (Fill t) = 1 + size t
710type PTactic = PTactic' PTerm
712data PDo' t = DoExp FC t
717 deriving (Eq, Functor)
719deriving instance Binary PDo'
720deriving instance NFData PDo'
723instance Sized a => Sized (PDo' a) where
724 size (DoExp fc t) = 1 + size fc + size t
725 size (DoBind fc nm t) = 1 + size fc + size nm + size t
726 size (DoBindP fc l r) = 1 + size fc + size l + size r
727 size (DoLet fc nm l r) = 1 + size fc + size nm + size l + size r
728 size (DoLetP fc l r) = 1 + size fc + size l + size r
732-- The priority gives a hint as to elaboration order. Best to elaborate
733-- things early which will help give a more concrete type to other
734-- variables, e.g. a before (interpTy a).
736data PArg' t = PImp { priority :: Int,
737 machine_inf :: Bool, -- true if the machine inferred it
739 pname :: Name, getTm :: t,
741 | PExp { priority :: Int,
745 | PConstraint { priority :: Int,
749 | PTacImplicit { priority :: Int,
755 deriving (Show, Eq, Functor)
757data ArgOpt = Lazy | HideDisplay
760lazyarg :: PArg' t -> Bool
761lazyarg tm = Lazy `elem` argopts tm
763instance Sized a => Sized (PArg' a) where
764 size (PImp p _ l nm trm _) = 1 + size nm + size trm
765 size (PExp p l trm _) = 1 + size trm
766 size (PConstraint p l trm _) = 1 + size trm
767 size (PTacImplicit p l nm scr trm _) = 1 + size nm + size scr + size trm
770deriving instance Binary PArg'
771deriving instance NFData PArg'
774pimp n t mach = PImp 1 mach [Lazy] n t ""
775pexp t = PExp 1 [] t ""
776pconst t = PConstraint 1 [] t ""
777ptacimp n s t = PTacImplicit 2 [Lazy] n s t ""
779type PArg = PArg' PTerm
783data ClassInfo = CI { instanceName :: Name,
784 class_methods :: [(Name, (FnOpts, PTerm))],
785 class_defaults :: [(Name, (Name, PDecl))], -- method name -> default impl
786 class_default_superclasses :: [PDecl],
787 class_params :: [Name],
788 class_instances :: [Name] }
791deriving instance Binary ClassInfo
792deriving instance NFData ClassInfo
795-- An argument is conditionally forceable iff its forceability
796-- depends on the collapsibility of the whole type.
797data Forceability = Conditional | Unconditional deriving (Show, Enum, Bounded, Eq, Ord)
800deriving instance Binary Forceability
801deriving instance NFData Forceability
804data OptInfo = Optimise { collapsible :: Bool,
806 -- The following should actually be (IntMap Forceability)
807 -- but the corresponding Binary instance seems to be broken.
808 -- Let's store a list and convert it to IntMap whenever needed.
809 forceable :: [(Int, Forceability)],
813deriving instance Binary OptInfo
814deriving instance NFData OptInfo
818data TypeInfo = TI { con_names :: [Name],
820 data_opts :: DataOpts,
824deriving instance Binary TypeInfo
825deriving instance NFData TypeInfo
828-- Syntactic sugar info
830data DSL' t = DSL { dsl_bind :: t,
835 index_first :: Maybe t,
836 index_next :: Maybe t,
837 dsl_lambda :: Maybe t,
840 deriving (Show, Functor)
842deriving instance Binary DSL'
843deriving instance NFData DSL'
848data SynContext = PatternSyntax | TermSyntax | AnySyntax
851deriving instance Binary SynContext
852deriving instance NFData SynContext
855data Syntax = Rule [SSymbol] PTerm SynContext
858deriving instance Binary Syntax
859deriving instance NFData Syntax
862data SSymbol = Keyword Name
869deriving instance Binary SSymbol
870deriving instance NFData SSymbol
873initDSL = DSL (PRef f (sUN ">>="))
874 (PRef f (sUN "return"))
876 (PRef f (sUN "pure"))
882 where f = fileFC "(builtin)"
884data Using = UImplicit Name PTerm
885 | UConstraint Name [Name]
888deriving instance Binary Using
889deriving instance NFData Using
892data SyntaxInfo = Syn { using :: [Using],
893 syn_params :: [(Name, PTerm)],
894 syn_namespace :: [String],
896 decoration :: Name -> Name,
898 implicitAllowed :: Bool,
902deriving instance NFData SyntaxInfo
903deriving instance Binary SyntaxInfo
906defaultSyntax = Syn [] [] [] [] id False False initDSL
908expandNS :: SyntaxInfo -> Name -> Name
909expandNS syn n@(NS _ _) = n
910expandNS syn n = case syn_namespace syn of
915-- For inferring types of things
919inferTy = sMN 0 "__Infer"
920inferCon = sMN 0 "__infer"
921inferDecl = PDatadecl inferTy
923 [("", inferCon, PPi impl (sMN 0 "iType") PType (
924 PPi expl (sMN 0 "ival") (PRef bi (sMN 0 "iType"))
925 (PRef bi inferTy)), bi, [])]
928infTerm t = PApp bi (PRef bi inferCon) [pimp (sMN 0 "iType") Placeholder True, pexp t]
929infP = P (TCon 6 0) inferTy (TType (UVal 0))
931getInferTerm, getInferType :: Term -> Term
932getInferTerm (Bind n b sc) = Bind n b $ getInferTerm sc
933getInferTerm (App (App _ _) tm) = tm
934getInferTerm tm = tm -- error ("getInferTerm " ++ show tm)
936getInferType (Bind n b sc) = Bind n b $ getInferType sc
937getInferType (App (App _ ty) _) = ty
941-- Handy primitives: Unit, False, Pair, MkPair, =, mkForeign, Elim type class
943primNames = [unitTy, unitCon,
944 falseTy, pairTy, pairCon,
945 eqTy, eqCon, inferTy, inferCon]
947unitTy = sMN 0 "__Unit"
948unitCon = sMN 0 "__II"
949unitDecl = PDatadecl unitTy PType
950 [("", unitCon, PRef bi unitTy, bi, [])]
951unitOpts = [DefaultEliminator]
953falseTy = sMN 0 "__False"
954falseDecl = PDatadecl falseTy PType []
957pairTy = sMN 0 "__Pair"
958pairCon = sMN 0 "__MkPair"
959pairDecl = PDatadecl pairTy (piBind [(n "A", PType), (n "B", PType)] PType)
960 [("", pairCon, PPi impl (n "A") PType (
961 PPi impl (n "B") PType (
962 PPi expl (n "a") (PRef bi (n "A")) (
963 PPi expl (n "b") (PRef bi (n "B"))
964 (PApp bi (PRef bi pairTy) [pexp (PRef bi (n "A")),
965 pexp (PRef bi (n "B"))])))), bi, [])]
971eqDecl = PDatadecl eqTy (piBind [(n "A", PType), (n "B", PType),
972 (n "x", PRef bi (n "A")), (n "y", PRef bi (n "B"))]
974 [("", eqCon, PPi impl (n "A") PType (
975 PPi impl (n "x") (PRef bi (n "A"))
976 (PApp bi (PRef bi eqTy) [pimp (n "A") Placeholder False,
977 pimp (n "B") Placeholder False,
978 pexp (PRef bi (n "x")),
979 pexp (PRef bi (n "x"))])), bi, [])]
983elimName = sUN "__Elim"
984elimMethElimTy = sUN "__elimTy"
985elimMethElim = sUN "elim"
986elimDecl = PClass "Type class for eliminators" defaultSyntax bi [] elimName [(sUN "scrutineeType", PType)]
987 [PTy "" defaultSyntax bi [TotalFn] elimMethElimTy PType,
988 PTy "" defaultSyntax bi [TotalFn] elimMethElim (PRef bi elimMethElimTy)]
990-- Defined in builtins.idr
991sigmaTy = sUN "Exists"
992existsCon = sUN "Ex_intro"
994piBind :: [(Name, PTerm)] -> PTerm -> PTerm
997piBindp :: Plicity -> [(Name, PTerm)] -> PTerm -> PTerm
999piBindp p ((n, ty):ns) t = PPi p n ty (piBindp p ns t)
1002-- Pretty-printing declarations and terms
1004instance Show PTerm where
1005 showsPrec _ tm = (displayS . renderCompact . prettyImp False) tm
1007instance Show PDecl where
1008 showsPrec _ d = (displayS . renderCompact . showDeclImp False) d
1010instance Show PClause where
1011 showsPrec _ c = (displayS . renderCompact . showCImp True) c
1013instance Show PData where
1014 showsPrec _ d = (displayS . renderCompact . showDImp False) d
1016instance Pretty PTerm OutputAnnotation where
1017 pretty = prettyImp False
1019-- | Colourise annotations according to an Idris state. It ignores the names
1020-- in the annotation, as there's no good way to show extended information on a
1022consoleDecorate :: IState -> OutputAnnotation -> String -> String
1023consoleDecorate ist _ | not (idris_colourRepl ist) = id
1024consoleDecorate ist AnnConstData = let theme = idris_colourTheme ist
1025 in colouriseData theme
1026consoleDecorate ist AnnConstType = let theme = idris_colourTheme ist
1027 in colouriseType theme
1028consoleDecorate ist (AnnBoundName _ True) = colouriseImplicit (idris_colourTheme ist)
1029consoleDecorate ist (AnnBoundName _ False) = colouriseBound (idris_colourTheme ist)
1030consoleDecorate ist (AnnName n _ _) = let ctxt = tt_ctxt ist
1031 theme = idris_colourTheme ist
1033 _ | isDConName n ctxt -> colouriseData theme
1034 _ | isFnName n ctxt -> colouriseFun theme
1035 _ | isTConName n ctxt -> colouriseType theme
1036 _ | otherwise -> id -- don't colourise unknown names
1037consoleDecorate ist (AnnFC _) = id
1039-- | Pretty-print a high-level closed Idris term
1040prettyImp :: Bool -- ^^ whether to show implicits
1041 -> PTerm -- ^^ the term to pretty-print
1042 -> Doc OutputAnnotation
1043prettyImp impl = pprintPTerm impl []
1045-- | Pretty-print a high-level Idris term in some bindings context
1046pprintPTerm :: Bool -- ^^ whether to show implicits
1047 -> [(Name, Bool)] -- ^^ the currently-bound names and whether they are implicit
1048 -> PTerm -- ^^ the term to pretty-print
1049 -> Doc OutputAnnotation
1050pprintPTerm impl bnd = prettySe 10 bnd
1052 prettySe :: Int -> [(Name, Bool)] -> PTerm -> Doc OutputAnnotation
1053 prettySe p bnd (PQuote r) =
1054 if size r > breakingSize then
1055 text "![" <> line <> pretty r <> text "]"
1057 text "![" <> pretty r <> text "]"
1058 prettySe p bnd (PPatvar fc n) = pretty n
1060 | Just str <- slist p bnd e = str
1061 | Just n <- snat p e = annotate AnnConstData (text (show n))
1062 prettySe p bnd (PRef fc n) = prettyName impl bnd n
1063 prettySe p bnd (PLam n ty sc) =
1065 if size sc > breakingSize then
1066 text "\\" <> bindingOf n False <+> text "=>" <> line <> prettySe 10 ((n, False):bnd) sc
1068 text "\\" <> bindingOf n False <+> text "=>" <+> prettySe 10 ((n, False):bnd) sc
1069 prettySe p bnd (PLet n ty v sc) =
1071 if size sc > breakingSize then
1072 text "let" <+> bindingOf n False <+> text "=" <+> prettySe 10 bnd v <+> text "in" <>
1073 nest nestingSize (prettySe 10 ((n, False):bnd) sc)
1075 text "let" <+> bindingOf n False <+> text "=" <+> prettySe 10 bnd v <+> text "in" <+>
1076 prettySe 10 ((n, False):bnd) sc
1077 prettySe p bnd (PPi (Exp l s _ _) n ty sc)
1078 | n `elem` allNamesIn sc || impl =
1079 let open = if Lazy `elem` l then text "|" <> lparen else lparen in
1081 if size sc > breakingSize then
1082 enclose open rparen (bindingOf n False <+> colon <+> prettySe 10 bnd ty) <+>
1083 st <> text "->" <> line <> prettySe 10 ((n, False):bnd) sc
1085 enclose open rparen (bindingOf n False <+> colon <+> prettySe 10 bnd ty) <+>
1086 st <> text "->" <+> prettySe 10 ((n, False):bnd) sc
1089 if size sc > breakingSize then
1090 prettySe 0 bnd ty <+> st <> text "->" <> line <> prettySe 10 ((n, False):bnd) sc
1092 prettySe 0 bnd ty <+> st <> text "->" <+> prettySe 10 ((n, False):bnd) sc
1096 Static -> text "[static]" <> space
1098 prettySe p bnd (PPi (Imp l s _ _) n ty sc)
1100 let open = if Lazy `elem` l then text "|" <> lbrace else lbrace in
1102 if size sc > breakingSize then
1103 open <> bindingOf n True <+> colon <+> prettySe 10 bnd ty <> rbrace <+>
1104 st <> text "->" <+> prettySe 10 ((n, True):bnd) sc
1106 open <> bindingOf n True <+> colon <+> prettySe 10 bnd ty <> rbrace <+>
1107 st <> text "->" <+> prettySe 10 ((n, True):bnd) sc
1108 | otherwise = prettySe 10 ((n, True):bnd) sc
1112 Static -> text "[static]" <> space
1114 prettySe p bnd (PPi (Constraint _ _ _) n ty sc) =
1116 if size sc > breakingSize then
1117 prettySe 10 bnd ty <+> text "=>" <+> prettySe 10 ((n, True):bnd) sc
1119 prettySe 10 bnd ty <+> text "=>" <> line <> prettySe 10 ((n, True):bnd) sc
1120 prettySe p bnd (PPi (TacImp _ _ s _) n ty sc) =
1122 if size sc > breakingSize then
1123 lbrace <> text "tacimp" <+> bindingOf n True <+> colon <+> prettySe 10 bnd ty <>
1124 rbrace <+> text "->" <> line <> prettySe 10 ((n, True):bnd) sc
1126 lbrace <> text "tacimp" <+> pretty n <+> colon <+> prettySe 10 bnd ty <>
1127 rbrace <+> text "->" <+> prettySe 10 ((n, True):bnd) sc
1128 prettySe p bnd (PApp _ (PRef _ f) [])
1129 | not impl = prettyName impl bnd f
1130 prettySe p bnd (PAppBind _ (PRef _ f) [])
1131 | not impl = text "!" <> prettyName impl bnd f
1132 prettySe p bnd (PApp _ (PRef _ op) args)
1133 | UN nm <- basename op
1135 length (getExps args) == 2 && (not impl) && (not $ isAlpha (thead nm)) =
1136 let [l, r] = getExps args in
1138 if size r > breakingSize then
1139 prettySe 1 bnd l <+> prettyName impl bnd op <> line <> prettySe 0 bnd r
1141 prettySe 1 bnd l <+> prettyName impl bnd op <+> prettySe 0 bnd r
1142 prettySe p bnd (PApp _ hd@(PRef fc f) [tm])
1143 | PConstant (Idris.Core.TT.Str str) <- getTm tm,
1144 f == sUN "Symbol_" = char '\'' <> prettySe 10 bnd (PRef fc (sUN str))
1145 prettySe p bnd (PApp _ f as) =
1146 let args = getExps as
1147 fp = prettySe 1 bnd f
1151 then fp : map (prettyArgS bnd) as
1152 else fp : map (prettyArgSe bnd) args)
1153 prettySe p bnd (PCase _ scr opts) =
1154 text "case" <+> prettySe 10 bnd scr <+> text "of" <> prettyBody
1156 prettyBody = foldr (<>) empty $ intersperse (text "|") $ map sc opts
1158 sc (l, r) = nest nestingSize $ prettySe 10 bnd l <+> text "=>" <+> prettySe 10 bnd r
1159 prettySe p bnd (PHidden tm) = text "." <> prettySe 0 bnd tm
1160 prettySe p bnd (PRefl _ _) = annotate (AnnName eqCon Nothing Nothing) $ text "refl"
1161 prettySe p bnd (PResolveTC _) = text "resolvetc"
1162 prettySe p bnd (PTrue _) = annotate (AnnName unitTy Nothing Nothing) $ text "()"
1163 prettySe p bnd (PFalse _) = annotate (AnnName falseTy Nothing Nothing) $ text "_|_"
1164 prettySe p bnd (PEq _ l r) =
1166 if size r > breakingSize then
1167 prettySe 10 bnd l <+> eq <$> nest nestingSize (prettySe 10 bnd r)
1169 prettySe 10 bnd l <+> eq <+> prettySe 10 bnd r
1170 where eq = annotate (AnnName eqTy Nothing Nothing) (text "=")
1171 prettySe p bnd (PRewrite _ l r _) =
1173 if size r > breakingSize then
1174 text "rewrite" <+> prettySe 10 bnd l <+> text "in" <> nest nestingSize (prettySe 10 bnd r)
1176 text "rewrite" <+> prettySe 10 bnd l <+> text "in" <+> prettySe 10 bnd r
1177 prettySe p bnd (PTyped l r) =
1178 lparen <> prettySe 10 bnd l <+> colon <+> prettySe 10 bnd r <> rparen
1179 prettySe p bnd (PPair _ l r) =
1180 if size r > breakingSize then
1181 lparen <> prettySe 10 bnd l <> text "," <>
1182 line <> prettySe 10 bnd r <> rparen
1184 lparen <> prettySe 10 bnd l <> text "," <+> prettySe 10 bnd r <> rparen
1185 prettySe p bnd (PDPair _ l t r) =
1186 if size r > breakingSize then
1187 lparen <> prettySe 10 bnd l <+> text "**" <>
1188 line <> prettySe 10 bnd r <> rparen
1190 lparen <> prettySe 10 bnd l <+> text "**" <+> prettySe 10 bnd r <> rparen
1191 prettySe p bnd (PAlternative a as) =
1192 lparen <> text "|" <> prettyAs <> text "|" <> rparen
1195 foldr (\l -> \r -> l <+> text "," <+> r) empty $ map (prettySe 10 bnd) as
1196 prettySe p bnd PType = annotate AnnConstType $ text "Type"
1197 prettySe p bnd (PConstant c) = annotate (annot c) (text (show c))
1198 where annot (AType _) = AnnConstType
1199 annot StrType = AnnConstType
1200 annot PtrType = AnnConstType
1201 annot VoidType = AnnConstType
1202 annot _ = AnnConstData
1203 -- XXX: add pretty for tactics
1204 prettySe p bnd (PProof ts) =
1205 text "proof" <+> lbrace <> nest nestingSize (text . show $ ts) <> rbrace
1206 prettySe p bnd (PTactics ts) =
1207 text "tactics" <+> lbrace <> nest nestingSize (text . show $ ts) <> rbrace
1208 prettySe p bnd (PMetavar n) = text "?" <> pretty n
1209 prettySe p bnd (PReturn f) = text "return"
1210 prettySe p bnd PImpossible = text "impossible"
1211 prettySe p bnd Placeholder = text "_"
1212 prettySe p bnd (PDoBlock _) = text "do block pretty not implemented"
1213 prettySe p bnd (PElabError s) = pretty s
1215 prettySe p bnd _ = text "test"
1217 prettyArgS bnd (PImp _ _ _ n tm _) = prettyArgSi bnd (n, tm)
1218 prettyArgS bnd (PExp _ _ tm _) = prettyArgSe bnd tm
1219 prettyArgS bnd (PConstraint _ _ tm _) = prettyArgSc bnd tm
1220 prettyArgS bnd (PTacImplicit _ _ n _ tm _) = prettyArgSti bnd (n, tm)
1222 prettyArgSe bnd arg = prettySe 0 bnd arg
1223 prettyArgSi bnd (n, val) = lbrace <> pretty n <+> text "=" <+> prettySe 10 bnd val <> rbrace
1224 prettyArgSc bnd val = lbrace <> lbrace <> prettySe 10 bnd val <> rbrace <> rbrace
1225 prettyArgSti bnd (n, val) = lbrace <> text "auto" <+> pretty n <+> text "=" <+> prettySe 10 bnd val <> rbrace
1227 basename :: Name -> Name
1228 basename (NS n _) = basename n
1231 slist' p bnd (PApp _ (PRef _ nil) _)
1232 | not impl && nsroot nil == sUN "Nil" = Just []
1233 slist' p bnd (PApp _ (PRef _ cons) args)
1234 | nsroot cons == sUN "::",
1235 (PExp {getTm=tl}):(PExp {getTm=hd}):imps <- reverse args,
1237 Just tl' <- slist' p bnd tl
1240 isImp (PImp {}) = True
1242 slist' _ _ _ = Nothing
1244 slist p bnd e | Just es <- slist' p bnd e = Just $
1245 case es of [] -> annotate AnnConstData $ text "[]"
1249 xs -> (enclose left right . hsep . punctuate comma . map (prettySe p bnd)) xs
1250 where left = (annotate AnnConstData (text "["))
1251 right = (annotate AnnConstData (text "]"))
1252 comma = (annotate AnnConstData (text ","))
1253 slist _ _ _ = Nothing
1255 natns = "Prelude.Nat."
1258 | show z == (natns++"Z") || show z == "Z" = Just 0
1259 snat p (PApp _ s [PExp {getTm=n}])
1260 | show s == (natns++"S") || show s == "S",
1265 bracket outer inner doc
1266 | inner > outer = lparen <> doc <> rparen
1269-- | Pretty-printer helper for the binding site of a name
1270bindingOf :: Name -- ^^ the bound name
1271 -> Bool -- ^^ whether the name is implicit
1272 -> Doc OutputAnnotation
1273bindingOf n imp = annotate (AnnBoundName n imp) (text (show n))
1275-- | Pretty-printer helper for names that attaches the correct annotations
1276prettyName :: Bool -- ^^ whether to show namespaces
1277 -> [(Name, Bool)] -- ^^ the current bound variables and whether they are implicit
1278 -> Name -- ^^ the name to pprint
1279 -> Doc OutputAnnotation
1280prettyName showNS bnd n | Just imp <- lookup n bnd = annotate (AnnBoundName n imp) (text (strName n))
1281 | otherwise = annotate (AnnName n Nothing Nothing) (text (strName n))
1282 where strName (UN n) = T.unpack n
1283 strName (NS n ns) | showNS = (concatMap (++ ".") . map T.unpack . reverse) ns ++ strName n
1284 | otherwise = strName n
1285 strName (MN i s) = T.unpack s
1286 strName other = show other
1289showCImp :: Bool -> PClause -> Doc OutputAnnotation
1290showCImp impl (PClause _ n l ws r w)
1291 = prettyImp impl l <+> showWs ws <+> text "=" <+> prettyImp impl r
1292 <+> text "where" <+> text (show w)
1295 showWs (x : xs) = text "|" <+> prettyImp impl x <+> showWs xs
1296showCImp impl (PWith _ n l ws r w)
1297 = prettyImp impl l <+> showWs ws <+> text "with" <+> prettyImp impl r
1298 <+> braces (text (show w))
1301 showWs (x : xs) = text "|" <+> prettyImp impl x <+> showWs xs
1304showDImp :: Bool -> PData -> Doc OutputAnnotation
1305showDImp impl (PDatadecl n ty cons)
1306 = text "data" <+> text (show n) <+> colon <+> prettyImp impl ty <+> text "where" <$>
1307 (indent 2 $ vsep (map (\ (_, n, t, _, _) -> pipe <+> prettyName False [] n <+> colon <+> prettyImp impl t) cons))
1309showDecls :: Bool -> [PDecl] -> Doc OutputAnnotation
1310showDecls i ds = vsep (map (showDeclImp i) ds)
1312showDeclImp _ (PFix _ f ops) = text (show f) <+> cat (punctuate (text ",") (map text ops))
1313showDeclImp i (PTy _ _ _ _ n t) = text "tydecl" <+> text (showCG n) <+> colon <+> prettyImp i t
1314showDeclImp i (PClauses _ _ n cs) = text "pat" <+> text (showCG n) <+> text "\t" <+>
1315 indent 2 (vsep (map (showCImp i) cs))
1316showDeclImp _ (PData _ _ _ _ d) = showDImp True d
1317showDeclImp i (PParams _ ns ps) = text "params" <+> braces (text (show ns) <> line <> showDecls i ps <> line)
1318showDeclImp i (PNamespace n ps) = text "namespace" <+> text n <> braces (line <> showDecls i ps <> line)
1319showDeclImp _ (PSyntax _ syn) = text "syntax" <+> text (show syn)
1320showDeclImp i (PClass _ _ _ cs n ps ds)
1321 = text "class" <+> text (show cs) <+> text (show n) <+> text (show ps) <> line <> showDecls i ds
1322showDeclImp i (PInstance _ _ cs n _ t _ ds)
1323 = text "instance" <+> text (show cs) <+> text (show n) <+> prettyImp i t <> line <> showDecls i ds
1324showDeclImp _ _ = text "..."
1325-- showDeclImp (PImport i) = "import " ++ i
1327instance Show (Doc OutputAnnotation) where
1328 show = flip (displayS . renderCompact) ""
1330getImps :: [PArg] -> [(Name, PTerm)]
1332getImps (PImp _ _ _ n tm _ : xs) = (n, tm) : getImps xs
1333getImps (_ : xs) = getImps xs
1335getExps :: [PArg] -> [PTerm]
1337getExps (PExp _ _ tm _ : xs) = tm : getExps xs
1338getExps (_ : xs) = getExps xs
1340getConsts :: [PArg] -> [PTerm]
1342getConsts (PConstraint _ _ tm _ : xs) = tm : getConsts xs
1343getConsts (_ : xs) = getConsts xs
1345getAll :: [PArg] -> [PTerm]
1350showName :: Maybe IState -- ^^ the Idris state, for information about names and colours
1351 -> [(Name, Bool)] -- ^^ the bound variables and whether they're implicit
1352 -> Bool -- ^^ whether to show implicits
1353 -> Bool -- ^^ whether to colourise
1354 -> Name -- ^^ the term to show
1356showName ist bnd impl colour n = case ist of
1357 Just i -> if colour then colourise n (idris_colourTheme i) else showbasic n
1358 Nothing -> showbasic n
1359 where name = if impl then show n else showbasic n
1360 showbasic n@(UN _) = showCG n
1361 showbasic (MN _ s) = str s
1362 showbasic (NS n s) = showSep "." (map str (reverse s)) ++ "." ++ showbasic n
1363 showbasic (SN s) = show s
1365 colourise n t = let ctxt' = fmap tt_ctxt ist in
1368 Just ctxt | Just impl <- lookup n bnd -> if impl then colouriseImplicit t name
1369 else colouriseBound t name
1370 | isDConName n ctxt -> colouriseData t name
1371 | isFnName n ctxt -> colouriseFun t name
1372 | isTConName n ctxt -> colouriseType t name
1373 -- The assumption is that if a name is not bound and does not exist in the
1374 -- global context, then we're somewhere in which implicit info has been lost
1375 -- (like error messages). Thus, unknown vars are colourised as implicits.
1376 | otherwise -> colouriseImplicit t name
1378showTm :: IState -- ^^ the Idris state, for information about identifiers and colours
1379 -> PTerm -- ^^ the term to show
1381showTm ist = displayDecorated (consoleDecorate ist) . renderCompact . prettyImp (opt_showimp (idris_options ist))
1383-- | Show a term with implicits, no colours
1384showTmImpls :: PTerm -> String
1385showTmImpls = flip (displayS . renderCompact . prettyImp True) ""
1388instance Sized PTerm where
1389 size (PQuote rawTerm) = size rawTerm
1390 size (PRef fc name) = size name
1391 size (PLam name ty bdy) = 1 + size ty + size bdy
1392 size (PPi plicity name ty bdy) = 1 + size ty + size bdy
1393 size (PLet name ty def bdy) = 1 + size ty + size def + size bdy
1394 size (PTyped trm ty) = 1 + size trm + size ty
1395 size (PApp fc name args) = 1 + size args
1396 size (PAppBind fc name args) = 1 + size args
1397 size (PCase fc trm bdy) = 1 + size trm + size bdy
1399 size (PFalse fc) = 1
1400 size (PRefl fc _) = 1
1401 size (PResolveTC fc) = 1
1402 size (PEq fc left right) = 1 + size left + size right
1403 size (PRewrite fc left right _) = 1 + size left + size right
1404 size (PPair fc left right) = 1 + size left + size right
1405 size (PDPair fs left ty right) = 1 + size left + size ty + size right
1406 size (PAlternative a alts) = 1 + size alts
1407 size (PHidden hidden) = size hidden
1408 size (PUnifyLog tm) = size tm
1409 size (PDisamb _ tm) = size tm
1410 size (PNoImplicits tm) = size tm
1412 size (PConstant const) = 1 + size const
1413 size Placeholder = 1
1414 size (PDoBlock dos) = 1 + size dos
1415 size (PIdiom fc term) = 1 + size term
1416 size (PReturn fc) = 1
1417 size (PMetavar name) = 1
1418 size (PProof tactics) = size tactics
1419 size (PElabError err) = size err
1420 size PImpossible = 1
1422getPArity :: PTerm -> Int
1423getPArity (PPi _ _ _ sc) = 1 + getPArity sc
1426-- Return all names, free or globally bound, in the given term.
1428allNamesIn :: PTerm -> [Name]
1429allNamesIn tm = nub $ ni [] tm
1432 | not (n `elem` env) = [n]
1433 ni env (PPatvar _ n) = [n]
1434 ni env (PApp _ f as) = ni env f ++ concatMap (ni env) (map getTm as)
1435 ni env (PAppBind _ f as) = ni env f ++ concatMap (ni env) (map getTm as)
1436 ni env (PCase _ c os) = ni env c ++ concatMap (ni env) (map snd os)
1437 ni env (PLam n ty sc) = ni env ty ++ ni (n:env) sc
1438 ni env (PPi _ n ty sc) = ni env ty ++ ni (n:env) sc
1439 ni env (PHidden tm) = ni env tm
1440 ni env (PEq _ l r) = ni env l ++ ni env r
1441 ni env (PRewrite _ l r _) = ni env l ++ ni env r
1442 ni env (PTyped l r) = ni env l ++ ni env r
1443 ni env (PPair _ l r) = ni env l ++ ni env r
1444 ni env (PDPair _ (PRef _ n) t r) = ni env t ++ ni (n:env) r
1445 ni env (PDPair _ l t r) = ni env l ++ ni env t ++ ni env r
1446 ni env (PAlternative a ls) = concatMap (ni env) ls
1447 ni env (PUnifyLog tm) = ni env tm
1448 ni env (PDisamb _ tm) = ni env tm
1449 ni env (PNoImplicits tm) = ni env tm
1452-- Return all names defined in binders in the given term
1453boundNamesIn :: PTerm -> [Name]
1454boundNamesIn tm = nub $ ni tm
1456 ni (PApp _ f as) = ni f ++ concatMap (ni) (map getTm as)
1457 ni (PAppBind _ f as) = ni f ++ concatMap (ni) (map getTm as)
1458 ni (PCase _ c os) = ni c ++ concatMap (ni) (map snd os)
1459 ni (PLam n ty sc) = n : (ni ty ++ ni sc)
1460 ni (PLet n ty val sc) = n : (ni ty ++ ni val ++ ni sc)
1461 ni (PPi _ n ty sc) = n : (ni ty ++ ni sc)
1462 ni (PEq _ l r) = ni l ++ ni r
1463 ni (PRewrite _ l r _) = ni l ++ ni r
1464 ni (PTyped l r) = ni l ++ ni r
1465 ni (PPair _ l r) = ni l ++ ni r
1466 ni (PDPair _ (PRef _ n) t r) = ni t ++ ni r
1467 ni (PDPair _ l t r) = ni l ++ ni t ++ ni r
1468 ni (PAlternative a as) = concatMap (ni) as
1469 ni (PHidden tm) = ni tm
1470 ni (PUnifyLog tm) = ni tm
1471 ni (PDisamb _ tm) = ni tm
1472 ni (PNoImplicits tm) = ni tm
1475-- Return names which are free in the given term.
1476namesIn :: [(Name, PTerm)] -> IState -> PTerm -> [Name]
1477namesIn uvars ist tm = nub $ ni [] tm
1480 | not (n `elem` env)
1481 = case lookupTy n (tt_ctxt ist) of
1483 _ -> if n `elem` (map fst uvars) then [n] else []
1484 ni env (PApp _ f as) = ni env f ++ concatMap (ni env) (map getTm as)
1485 ni env (PAppBind _ f as) = ni env f ++ concatMap (ni env) (map getTm as)
1486 ni env (PCase _ c os) = ni env c ++ concatMap (ni env) (map snd os)
1487 ni env (PLam n ty sc) = ni env ty ++ ni (n:env) sc
1488 ni env (PPi _ n ty sc) = ni env ty ++ ni (n:env) sc
1489 ni env (PEq _ l r) = ni env l ++ ni env r
1490 ni env (PRewrite _ l r _) = ni env l ++ ni env r
1491 ni env (PTyped l r) = ni env l ++ ni env r
1492 ni env (PPair _ l r) = ni env l ++ ni env r
1493 ni env (PDPair _ (PRef _ n) t r) = ni env t ++ ni (n:env) r
1494 ni env (PDPair _ l t r) = ni env l ++ ni env t ++ ni env r
1495 ni env (PAlternative a as) = concatMap (ni env) as
1496 ni env (PHidden tm) = ni env tm
1497 ni env (PUnifyLog tm) = ni env tm
1498 ni env (PDisamb _ tm) = ni env tm
1499 ni env (PNoImplicits tm) = ni env tm
1502-- Return which of the given names are used in the given term.
1504usedNamesIn :: [Name] -> IState -> PTerm -> [Name]
1505usedNamesIn vars ist tm = nub $ ni [] tm
1508 | n `elem` vars && not (n `elem` env)
1509 = case lookupTy n (tt_ctxt ist) of
1512 ni env (PApp _ f as) = ni env f ++ concatMap (ni env) (map getTm as)
1513 ni env (PAppBind _ f as) = ni env f ++ concatMap (ni env) (map getTm as)
1514 ni env (PCase _ c os) = ni env c ++ concatMap (ni env) (map snd os)
1515 ni env (PLam n ty sc) = ni env ty ++ ni (n:env) sc
1516 ni env (PPi _ n ty sc) = ni env ty ++ ni (n:env) sc
1517 ni env (PEq _ l r) = ni env l ++ ni env r
1518 ni env (PRewrite _ l r _) = ni env l ++ ni env r
1519 ni env (PTyped l r) = ni env l ++ ni env r
1520 ni env (PPair _ l r) = ni env l ++ ni env r
1521 ni env (PDPair _ (PRef _ n) t r) = ni env t ++ ni (n:env) r
1522 ni env (PDPair _ l t r) = ni env l ++ ni env t ++ ni env r
1523 ni env (PAlternative a as) = concatMap (ni env) as
1524 ni env (PHidden tm) = ni env tm
1525 ni env (PUnifyLog tm) = ni env tm
1526 ni env (PDisamb _ tm) = ni env tm
1527 ni env (PNoImplicits tm) = ni env tm
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list