1{-# LANGUAGE MultiParamTypeClasses, FlexibleInstances, DeriveFunctor,
2 TypeSynonymInstances, PatternGuards #-}
4module Idris.AbsSyntaxTree where
8import Core.Elaborate hiding (Tactic(..))
11import IRTS.CodegenCommon
13import Util.DynamicLinker
19import System.Console.Haskeline
22import Control.Monad.Trans.State.Strict
23import Control.Monad.Trans.Error
28import Data.Word (Word)
32data IOption = IOption { opt_logLevel :: Int,
34 opt_typeintype :: Bool,
36 opt_showimp :: Bool, -- ^^ show implicits
37 opt_errContext :: Bool,
42 opt_codegen :: Codegen,
43 opt_outputTy :: OutputType,
44 opt_ibcsubdir :: FilePath,
45 opt_importdirs :: [FilePath],
49 opt_cmdline :: [Opt] -- remember whole command line
53defaultOpts = IOption { opt_logLevel = 0
54 , opt_typecase = False
55 , opt_typeintype = False
58 , opt_errContext = False
61 , opt_nobanner = False
64 , opt_outputTy = Executable
73data LanguageExt = TypeProviders | ErrorReflection deriving (Show, Eq, Read, Ord)
75-- | The output mode in use
76data OutputMode = RawOutput | IdeSlave Integer deriving Show
78-- TODO: Add 'module data' to IState, which can be saved out and reloaded quickly (i.e
79-- without typechecking).
80-- This will include all the functions and data declarations, plus fixity declarations
83-- | The global state used in the Idris monad
85 tt_ctxt :: Context, -- ^ All the currently defined names and their terms
86 idris_constraints :: [(UConstraint, FC)],
87 -- ^ A list of universe constraints and their corresponding source locations
88 idris_infixes :: [FixDecl], -- ^ Currently defined infix operators
89 idris_implicits :: Ctxt [PArg],
90 idris_statics :: Ctxt [Bool],
91 idris_classes :: Ctxt ClassInfo,
92 idris_dsls :: Ctxt DSL,
93 idris_optimisation :: Ctxt OptInfo,
94 idris_datatypes :: Ctxt TypeInfo,
95 idris_namehints :: Ctxt [Name],
96 idris_patdefs :: Ctxt ([([Name], Term, Term)], [PTerm]), -- not exported
97 -- ^ list of lhs/rhs, and a list of missing clauses
98 idris_flags :: Ctxt [FnOpt],
99 idris_callgraph :: Ctxt CGInfo, -- name, args used in each pos
100 idris_calledgraph :: Ctxt [Name],
101 idris_docstrings :: Ctxt String,
102 idris_totcheck :: [(FC, Name)], -- names to check totality on
103 idris_defertotcheck :: [(FC, Name)], -- names to check at the end
104 idris_options :: IOption,
106 idris_lineapps :: [((FilePath, Int), PTerm)],
107 -- ^ Full application LHS on source line
108 idris_metavars :: [(Name, (Maybe Name, Int, Bool))], -- ^ The currently defined but not proven metavariables
109 idris_coercions :: [Name],
110 idris_transforms :: [(Term, Term)],
111 syntax_rules :: [Syntax],
112 syntax_keywords :: [String],
113 imported :: [FilePath], -- ^ The imported modules
114 idris_scprims :: [(Name, (Int, PrimFn))],
115 idris_objs :: [(Codegen, FilePath)],
116 idris_libs :: [(Codegen, String)],
117 idris_cgflags :: [(Codegen, String)],
118 idris_hdrs :: [(Codegen, String)],
119 proof_list :: [(Name, [String])],
120 errLine :: Maybe Int,
121 lastParse :: Maybe Name,
122 indent_stack :: [Int],
123 brace_stack :: [Maybe Int],
124 hide_list :: [(Name, Maybe Accessibility)],
125 default_access :: Accessibility,
126 default_total :: Bool,
127 ibc_write :: [IBCWrite],
128 compiled_so :: Maybe String,
129 idris_dynamic_libs :: [DynamicLib],
130 idris_language_extensions :: [LanguageExt],
131 idris_outputmode :: OutputMode,
132 idris_colourRepl :: Bool,
133 idris_colourTheme :: ColourTheme,
134 idris_outh :: Handle,
135 idris_errorhandlers :: [Name]
138data SizeChange = Smaller | Same | Bigger | Unknown
141deriving instance Binary SizeChange
142deriving instance NFData SizeChange
145type SCGEntry = (Name, [Maybe (Int, SizeChange)])
147data CGInfo = CGInfo { argsdef :: [Name],
148 calls :: [(Name, [[Name]])],
154deriving instance Binary CGInfo
155deriving instance NFData CGInfo
158primDefs = [UN "unsafePerformPrimIO",
159 UN "mkLazyForeignPrim",
163-- information that needs writing for the current module's .ibc file
164data IBCWrite = IBCFix FixDecl
168 | IBCInstance Bool Name Name
175 | IBCObj Codegen FilePath
176 | IBCLib Codegen String
177 | IBCCGFlag Codegen String
179 | IBCHeader Codegen String
180 | IBCAccess Name Accessibility
181 | IBCTotal Name Totality
182 | IBCFlags Name [FnOpt]
183 | IBCTrans (Term, Term)
187 | IBCDef Name -- i.e. main context
188 | IBCNameHint (Name, Name)
189 | IBCLineApp FilePath Int PTerm
192-- | The initial state for the compiler
194idrisInit = IState initContext [] [] emptyContext emptyContext emptyContext
195 emptyContext emptyContext emptyContext emptyContext
196 emptyContext emptyContext emptyContext emptyContext
198 [] [] defaultOpts 6 [] [] [] [] [] [] [] [] [] [] [] []
199 [] Nothing Nothing [] [] [] Hidden False [] Nothing [] [] RawOutput
200 True defaultTheme stdout []
202-- | The monad for the main REPL - reading and processing files and updating
203-- global state (hence the IO inner monad).
204--type Idris = WriterT [Either String (IO ())] (State IState a))
205type Idris = StateT IState (ErrorT Err IO)
207-- Commands in the REPL
226 | ChangeDirectory FilePath
229 | Compile Codegen String
234 | AddProof (Maybe Name)
246 | DynamicLink FilePath
251 | CaseSplitAt Bool Int Name
252 | AddClauseFrom Bool Int Name
253 | AddProofClauseFrom Bool Int Name
254 | AddMissing Bool Int Name
255 | MakeWith Bool Int Name
256 | DoProofSearch Bool Int Name [Name]
260 | SetColour ColourType IdrisColour
265data Opt = Filename String
277 | NoBuiltins -- only for the really primitive stuff!
301 | OutputTy OutputType
302 | Extension LanguageExt
303 | InterpretScript String
304 | TargetTriple String
310-- Parsed declarations
312data Fixity = Infixl { prec :: Int }
313 | Infixr { prec :: Int }
314 | InfixN { prec :: Int }
315 | PrefixN { prec :: Int }
318deriving instance Binary Fixity
319deriving instance NFData Fixity
322instance Show Fixity where
323 show (Infixl i) = "infixl " ++ show i
324 show (Infixr i) = "infixr " ++ show i
325 show (InfixN i) = "infix " ++ show i
326 show (PrefixN i) = "prefix " ++ show i
328data FixDecl = Fix Fixity String
331instance Show FixDecl where
332 show (Fix f s) = show f ++ " " ++ s
335deriving instance Binary FixDecl
336deriving instance NFData FixDecl
339instance Ord FixDecl where
340 compare (Fix x _) (Fix y _) = compare (prec x) (prec y)
343data Static = Static | Dynamic
346deriving instance Binary Static
347deriving instance NFData Static
350-- Mark bindings with their explicitness, and laziness
351data Plicity = Imp { plazy :: Bool,
355 | Exp { plazy :: Bool,
359 | Constraint { plazy :: Bool,
362 | TacImp { plazy :: Bool,
369deriving instance Binary Plicity
370deriving instance NFData Plicity
373impl = Imp False Dynamic "" False
374expl = Exp False Dynamic "" False
375expl_param = Exp False Dynamic "" True
376constraint = Constraint False Dynamic ""
377tacimpl t = TacImp False Dynamic t ""
379data FnOpt = Inlinable -- always evaluate when simplifying
380 | TotalFn | PartialFn
381 | Coinductive | AssertTotal
382 | Dictionary -- type class dictionary, eval only when
383 -- a function argument, and further evaluation resutls
384 | Implicit -- implicit coercion
385 | CExport String -- export, with a C name
386 | ErrorHandler -- ^^ an error handler for use with the ErrorReflection extension
387 | Reflection -- a reflecting function, compile-time only
388 | Specialise [(Name, Maybe Int)] -- specialise it, freeze these names
391deriving instance Binary FnOpt
392deriving instance NFData FnOpt
397inlinable :: FnOpts -> Bool
398inlinable = elem Inlinable
400dictionary :: FnOpts -> Bool
401dictionary = elem Dictionary
404-- | Data declaration options
405data DataOpt = Codata -- Set if the the data-type is coinductive
406 | DefaultEliminator -- Set if an eliminator should be generated for data type
409type DataOpts = [DataOpt]
411-- | Top-level declarations such as compiler directives, definitions,
412-- datatypes and typeclasses.
414 = PFix FC Fixity [String] -- ^ Fixity declaration
415 | PTy String SyntaxInfo FC FnOpts Name t -- ^ Type declaration
416 | PPostulate String SyntaxInfo FC FnOpts Name t -- ^ Postulate
417 | PClauses FC FnOpts Name [PClause' t] -- ^ Pattern clause
418 | PCAF FC Name t -- ^ Top level constant
419 | PData String SyntaxInfo FC DataOpts (PData' t) -- ^ Data declaration.
420 | PParams FC [(Name, t)] [PDecl' t] -- ^ Params block
421 | PNamespace String [PDecl' t] -- ^ New namespace
422 | PRecord String SyntaxInfo FC Name t String Name t -- ^ Record declaration
423 | PClass String SyntaxInfo FC
426 [(Name, t)] -- parameters
427 [PDecl' t] -- declarations
428 -- ^ Type class: arguments are documentation, syntax info, source location, constraints,
429 -- class name, parameters, method declarations
430 | PInstance SyntaxInfo FC [t] -- constraints
433 t -- full instance type
434 (Maybe Name) -- explicit name
436 -- ^ Instance declaration: arguments are syntax info, source location, constraints,
437 -- class name, parameters, full instance type, optional explicit name, and definitions
438 | PDSL Name (DSL' t) -- ^ DSL declaration
439 | PSyntax FC Syntax -- ^ Syntax definition
440 | PMutual FC [PDecl' t] -- ^ Mutual block
441 | PDirective (Idris ()) -- ^ Compiler directive. The parser inserts the corresponding action in the Idris monad.
442 | PProvider SyntaxInfo FC Name t t -- ^ Type provider. The first t is the type, the second is the term
443 | PTransform FC Bool t t -- ^ Source-to-source transformation rule. If
444 -- bool is True, lhs and rhs must be convertible
447deriving instance Binary PDecl'
448deriving instance NFData PDecl'
451-- For elaborator state
452type ElabD a = Elab' [PDecl] a
454-- | One clause of a top-level definition. Term arguments to constructors are:
456-- 1. The whole application (missing for PClauseR and PWithR because they're within a "with" clause)
458-- 2. The list of extra 'with' patterns
460-- 3. The right-hand side
462-- 4. The where block (PDecl' t)
464data PClause' t = PClause FC Name t [t] t [PDecl' t] -- ^ A normal top-level definition.
465 | PWith FC Name t [t] t [PDecl' t]
466 | PClauseR FC [t] t [PDecl' t]
467 | PWithR FC [t] t [PDecl' t]
470deriving instance Binary PClause'
471deriving instance NFData PClause'
475data PData' t = PDatadecl { d_name :: Name, -- ^ The name of the datatype
476 d_tcon :: t, -- ^ Type constructor
477 d_cons :: [(String, Name, t, FC)] -- ^ Constructors
479 -- ^ Data declaration
480 | PLaterdecl { d_name :: Name, d_tcon :: t }
481 -- ^ "Placeholder" for data whose constructors are defined later
484deriving instance Binary PData'
485deriving instance NFData PData'
488-- Handy to get a free function for applying PTerm -> PTerm functions
489-- across a program, by deriving Functor
491type PDecl = PDecl' PTerm
492type PData = PData' PTerm
493type PClause = PClause' PTerm
495-- get all the names declared in a decl
497declared :: PDecl -> [Name]
498declared (PFix _ _ _) = []
499declared (PTy _ _ _ _ n t) = [n]
500declared (PPostulate _ _ _ _ n t) = [n]
501declared (PClauses _ _ n _) = [] -- not a declaration
502declared (PCAF _ n _) = [n]
503declared (PData _ _ _ _ (PDatadecl n _ ts)) = n : map fstt ts
504 where fstt (_, a, _, _) = a
505declared (PData _ _ _ _ (PLaterdecl n _)) = [n]
506declared (PParams _ _ ds) = concatMap declared ds
507declared (PNamespace _ ds) = concatMap declared ds
508declared (PRecord _ _ _ n _ _ c _) = [n, c]
509declared (PClass _ _ _ _ n _ ms) = n : concatMap declared ms
510declared (PInstance _ _ _ _ _ _ _ _) = []
511declared (PDSL n _) = [n]
512declared (PSyntax _ _) = []
513declared (PMutual _ ds) = concatMap declared ds
514declared (PDirective _) = []
516-- get the names declared, not counting nested parameter blocks
517tldeclared :: PDecl -> [Name]
518tldeclared (PFix _ _ _) = []
519tldeclared (PTy _ _ _ _ n t) = [n]
520tldeclared (PPostulate _ _ _ _ n t) = [n]
521tldeclared (PClauses _ _ n _) = [] -- not a declaration
522tldeclared (PRecord _ _ _ n _ _ c _) = [n, c]
523tldeclared (PData _ _ _ _ (PDatadecl n _ ts)) = n : map fstt ts
524 where fstt (_, a, _, _) = a
525tldeclared (PParams _ _ ds) = []
526tldeclared (PMutual _ ds) = concatMap tldeclared ds
527tldeclared (PNamespace _ ds) = concatMap tldeclared ds
528tldeclared (PClass _ _ _ _ n _ ms) = concatMap tldeclared ms
529tldeclared (PInstance _ _ _ _ _ _ _ _) = []
532defined :: PDecl -> [Name]
533defined (PFix _ _ _) = []
534defined (PTy _ _ _ _ n t) = []
535defined (PPostulate _ _ _ _ n t) = []
536defined (PClauses _ _ n _) = [n] -- not a declaration
537defined (PCAF _ n _) = [n]
538defined (PData _ _ _ _ (PDatadecl n _ ts)) = n : map fstt ts
539 where fstt (_, a, _, _) = a
540defined (PData _ _ _ _ (PLaterdecl n _)) = []
541defined (PParams _ _ ds) = concatMap defined ds
542defined (PNamespace _ ds) = concatMap defined ds
543defined (PRecord _ _ _ n _ _ c _) = [n, c]
544defined (PClass _ _ _ _ n _ ms) = n : concatMap defined ms
545defined (PInstance _ _ _ _ _ _ _ _) = []
546defined (PDSL n _) = [n]
547defined (PSyntax _ _) = []
548defined (PMutual _ ds) = concatMap defined ds
549defined (PDirective _) = []
552updateN :: [(Name, Name)] -> Name -> Name
553updateN ns n | Just n' <- lookup n ns = n'
556updateNs :: [(Name, Name)] -> PTerm -> PTerm
558updateNs ns t = mapPT updateRef t
559 where updateRef (PRef fc f) = PRef fc (updateN ns f)
562-- updateDNs :: [(Name, Name)] -> PDecl -> PDecl
564-- updateDNs ns (PTy s f n t) | Just n' <- lookup n ns = PTy s f n' t
565-- updateDNs ns (PClauses f n c) | Just n' <- lookup n ns = PClauses f n' (map updateCNs c)
566-- where updateCNs ns (PClause n l ts r ds)
567-- = PClause (updateN ns n) (fmap (updateNs ns) l)
568-- (map (fmap (updateNs ns)) ts)
569-- (fmap (updateNs ns) r)
570-- (map (updateDNs ns) ds)
573-- | High level language terms
574data PTerm = PQuote Raw
576 | PInferRef FC Name -- ^ A name to be defined later
578 | PLam Name PTerm PTerm
579 | PPi Plicity Name PTerm PTerm
580 | PLet Name PTerm PTerm PTerm
581 | PTyped PTerm PTerm -- ^ Term with explicit type
582 | PApp FC PTerm [PArg]
583 | PAppBind FC PTerm [PArg] -- ^ implicitly bound application
584 | PMatchApp FC Name -- ^ Make an application by type matching
585 | PCase FC PTerm [(PTerm, PTerm)]
591 | PRewrite FC PTerm PTerm (Maybe PTerm)
592 | PPair FC PTerm PTerm
593 | PDPair FC PTerm PTerm PTerm
594 | PAlternative Bool [PTerm] -- True if only one may work
595 | PHidden PTerm -- ^ Irrelevant or hidden pattern
597 | PGoal FC PTerm Name PTerm
604 | PProof [PTactic] -- ^ Proof script
605 | PTactics [PTactic] -- ^ As PProof, but no auto solving
606 | PElabError Err -- ^ Error to report on elaboration
607 | PImpossible -- ^ Special case for declaring when an LHS can't typecheck
608 | PCoerced PTerm -- ^ To mark a coerced argument, so as not to coerce twice
609 | PUnifyLog PTerm -- ^ dump a trace of unifications when building term
610 | PNoImplicits PTerm -- ^ never run implicit converions on the term
615deriving instance Binary PTerm
616deriving instance NFData PTerm
619mapPT :: (PTerm -> PTerm) -> PTerm -> PTerm
620mapPT f t = f (mpt t) where
621 mpt (PLam n t s) = PLam n (mapPT f t) (mapPT f s)
622 mpt (PPi p n t s) = PPi p n (mapPT f t) (mapPT f s)
623 mpt (PLet n ty v s) = PLet n (mapPT f ty) (mapPT f v) (mapPT f s)
624 mpt (PRewrite fc t s g) = PRewrite fc (mapPT f t) (mapPT f s)
626 mpt (PApp fc t as) = PApp fc (mapPT f t) (map (fmap (mapPT f)) as)
627 mpt (PAppBind fc t as) = PAppBind fc (mapPT f t) (map (fmap (mapPT f)) as)
628 mpt (PCase fc c os) = PCase fc (mapPT f c) (map (pmap (mapPT f)) os)
629 mpt (PEq fc l r) = PEq fc (mapPT f l) (mapPT f r)
630 mpt (PTyped l r) = PTyped (mapPT f l) (mapPT f r)
631 mpt (PPair fc l r) = PPair fc (mapPT f l) (mapPT f r)
632 mpt (PDPair fc l t r) = PDPair fc (mapPT f l) (mapPT f t) (mapPT f r)
633 mpt (PAlternative a as) = PAlternative a (map (mapPT f) as)
634 mpt (PHidden t) = PHidden (mapPT f t)
635 mpt (PDoBlock ds) = PDoBlock (map (fmap (mapPT f)) ds)
636 mpt (PProof ts) = PProof (map (fmap (mapPT f)) ts)
637 mpt (PTactics ts) = PTactics (map (fmap (mapPT f)) ts)
638 mpt (PUnifyLog tm) = PUnifyLog (mapPT f tm)
639 mpt (PNoImplicits tm) = PNoImplicits (mapPT f tm)
640 mpt (PGoal fc r n sc) = PGoal fc (mapPT f r) n (mapPT f sc)
644data PTactic' t = Intro [Name] | Intros | Focus Name
645 | Refine Name [Bool] | Rewrite t
649 | LetTac Name t | LetTacTy Name t t
650 | Exact t | Compute | Trivial
651 | ProofSearch (Maybe Name) Name [Name]
654 | ProofState | ProofTerm | Undo
655 | Try (PTactic' t) (PTactic' t)
656 | TSeq (PTactic' t) (PTactic' t)
657 | ApplyTactic t -- see Language.Reflection module
660 | GoalType String (PTactic' t)
662 deriving (Show, Eq, Functor)
664deriving instance Binary PTactic'
665deriving instance NFData PTactic'
668instance Sized a => Sized (PTactic' a) where
669 size (Intro nms) = 1 + size nms
671 size (Focus nm) = 1 + size nm
672 size (Refine nm bs) = 1 + size nm + length bs
673 size (Rewrite t) = 1 + size t
674 size (Induction t) = 1 + size t
675 size (LetTac nm t) = 1 + size nm + size t
676 size (Exact t) = 1 + size t
684 size (Try l r) = 1 + size l + size r
685 size (TSeq l r) = 1 + size l + size r
686 size (ApplyTactic t) = 1 + size t
687 size (Reflect t) = 1 + size t
688 size (Fill t) = 1 + size t
692type PTactic = PTactic' PTerm
694data PDo' t = DoExp FC t
699 deriving (Eq, Functor)
701deriving instance Binary PDo'
702deriving instance NFData PDo'
705instance Sized a => Sized (PDo' a) where
706 size (DoExp fc t) = 1 + size fc + size t
707 size (DoBind fc nm t) = 1 + size fc + size nm + size t
708 size (DoBindP fc l r) = 1 + size fc + size l + size r
709 size (DoLet fc nm l r) = 1 + size fc + size nm + size l + size r
710 size (DoLetP fc l r) = 1 + size fc + size l + size r
714-- The priority gives a hint as to elaboration order. Best to elaborate
715-- things early which will help give a more concrete type to other
716-- variables, e.g. a before (interpTy a).
718data PArg' t = PImp { priority :: Int,
719 machine_inf :: Bool, -- true if the machine inferred it
720 lazyarg :: Bool, pname :: Name, getTm :: t,
722 | PExp { priority :: Int,
723 lazyarg :: Bool, getTm :: t,
725 | PConstraint { priority :: Int,
726 lazyarg :: Bool, getTm :: t,
728 | PTacImplicit { priority :: Int,
729 lazyarg :: Bool, pname :: Name,
733 deriving (Show, Eq, Functor)
735instance Sized a => Sized (PArg' a) where
736 size (PImp p _ l nm trm _) = 1 + size nm + size trm
737 size (PExp p l trm _) = 1 + size trm
738 size (PConstraint p l trm _) = 1 + size trm
739 size (PTacImplicit p l nm scr trm _) = 1 + size nm + size scr + size trm
742deriving instance Binary PArg'
743deriving instance NFData PArg'
746pimp n t mach = PImp 1 mach True n t ""
747pexp t = PExp 1 False t ""
748pconst t = PConstraint 1 False t ""
749ptacimp n s t = PTacImplicit 0 True n s t ""
751type PArg = PArg' PTerm
755data ClassInfo = CI { instanceName :: Name,
756 class_methods :: [(Name, (FnOpts, PTerm))],
757 class_defaults :: [(Name, (Name, PDecl))], -- method name -> default impl
758 class_default_superclasses :: [PDecl],
759 class_params :: [Name],
760 class_instances :: [Name] }
763deriving instance Binary ClassInfo
764deriving instance NFData ClassInfo
767-- An argument is conditionally forceable iff its forceability
768-- depends on the collapsibility of the whole type.
769data Forceability = Conditional | Unconditional deriving (Show, Enum, Bounded, Eq, Ord)
772deriving instance Binary Forceability
773deriving instance NFData Forceability
776data OptInfo = Optimise { collapsible :: Bool,
778 -- The following should actually be (IntMap Forceability)
779 -- but the corresponding Binary instance seems to be broken.
780 -- Let's store a list and convert it to IntMap whenever needed.
781 forceable :: [(Int, Forceability)],
785deriving instance Binary OptInfo
786deriving instance NFData OptInfo
790data TypeInfo = TI { con_names :: [Name],
795deriving instance Binary TypeInfo
796deriving instance NFData TypeInfo
799-- Syntactic sugar info
801data DSL' t = DSL { dsl_bind :: t,
806 index_first :: Maybe t,
807 index_next :: Maybe t,
808 dsl_lambda :: Maybe t,
811 deriving (Show, Functor)
813deriving instance Binary DSL'
814deriving instance NFData DSL'
819data SynContext = PatternSyntax | TermSyntax | AnySyntax
822deriving instance Binary SynContext
823deriving instance NFData SynContext
826data Syntax = Rule [SSymbol] PTerm SynContext
829deriving instance Binary Syntax
830deriving instance NFData Syntax
833data SSymbol = Keyword Name
840deriving instance Binary SSymbol
841deriving instance NFData SSymbol
844initDSL = DSL (PRef f (UN ">>="))
845 (PRef f (UN "return"))
853 where f = fileFC "(builtin)"
855data Using = UImplicit Name PTerm
856 | UConstraint Name [Name]
859deriving instance Binary Using
860deriving instance NFData Using
863data SyntaxInfo = Syn { using :: [Using],
864 syn_params :: [(Name, PTerm)],
865 syn_namespace :: [String],
867 decoration :: Name -> Name,
869 implicitAllowed :: Bool,
873deriving instance NFData SyntaxInfo
874deriving instance Binary SyntaxInfo
877defaultSyntax = Syn [] [] [] [] id False False initDSL
879expandNS :: SyntaxInfo -> Name -> Name
880expandNS syn n@(NS _ _) = n
881expandNS syn n = case syn_namespace syn of
886--- Pretty printing declarations and terms
888instance Show PTerm where
889 show tm = showImp Nothing False False tm
891instance Pretty PTerm where
892 pretty = prettyImp False
894instance Show PDecl where
895 show d = showDeclImp False d
897instance Show PClause where
898 show c = showCImp True c
900instance Show PData where
901 show d = showDImp False d
903showDecls :: Bool -> [PDecl] -> String
905showDecls i (d:ds) = showDeclImp i d ++ "\n" ++ showDecls i ds
907showDeclImp _ (PFix _ f ops) = show f ++ " " ++ showSep ", " ops
908showDeclImp i (PTy _ _ _ _ n t) = "tydecl " ++ showCG n ++ " : " ++ showImp Nothing i False t
909showDeclImp i (PClauses _ _ n cs) = "pat " ++ showCG n ++ "\t" ++ showSep "\n\t" (map (showCImp i) cs)
910showDeclImp _ (PData _ _ _ _ d) = showDImp True d
911showDeclImp i (PParams _ ns ps) = "params {" ++ show ns ++ "\n" ++ showDecls i ps ++ "}\n"
912showDeclImp i (PNamespace n ps) = "namespace {" ++ n ++ "\n" ++ showDecls i ps ++ "}\n"
913showDeclImp _ (PSyntax _ syn) = "syntax " ++ show syn
914showDeclImp i (PClass _ _ _ cs n ps ds)
915 = "class " ++ show cs ++ " " ++ show n ++ " " ++ show ps ++ "\n" ++ showDecls i ds
916showDeclImp i (PInstance _ _ cs n _ t _ ds)
917 = "instance " ++ show cs ++ " " ++ show n ++ " " ++ show t ++ "\n" ++ showDecls i ds
918showDeclImp _ _ = "..."
919-- showDeclImp (PImport i) = "import " ++ i
922showCImp :: Bool -> PClause -> String
923showCImp impl (PClause _ n l ws r w)
924 = showImp Nothing impl False l ++ showWs ws ++ " = " ++ showImp Nothing impl False r
925 ++ " where " ++ show w
928 showWs (x : xs) = " | " ++ showImp Nothing impl False x ++ showWs xs
929showCImp impl (PWith _ n l ws r w)
930 = showImp Nothing impl False l ++ showWs ws ++ " with " ++ showImp Nothing impl False r
931 ++ " { " ++ show w ++ " } "
934 showWs (x : xs) = " | " ++ showImp Nothing impl False x ++ showWs xs
937showDImp :: Bool -> PData -> String
938showDImp impl (PDatadecl n ty cons)
939 = "data " ++ show n ++ " : " ++ showImp Nothing impl False ty ++ " where\n\t"
941 (map (\ (_, n, t, _) -> show n ++ " : " ++ showImp Nothing impl False t) cons)
943getImps :: [PArg] -> [(Name, PTerm)]
945getImps (PImp _ _ _ n tm _ : xs) = (n, tm) : getImps xs
946getImps (_ : xs) = getImps xs
948getExps :: [PArg] -> [PTerm]
950getExps (PExp _ _ tm _ : xs) = tm : getExps xs
951getExps (_ : xs) = getExps xs
953getConsts :: [PArg] -> [PTerm]
955getConsts (PConstraint _ _ tm _ : xs) = tm : getConsts xs
956getConsts (_ : xs) = getConsts xs
958getAll :: [PArg] -> [PTerm]
961-- | Pretty-print a high-level Idris term
962prettyImp :: Bool -- ^^ whether to show implicits
963 -> PTerm -- ^^ the term to pretty-print
965prettyImp impl = prettySe 10
967 prettySe p (PQuote r) =
968 if size r > breakingSize then
969 text "![" $$ pretty r <> text "]"
971 text "![" <> pretty r <> text "]"
972 prettySe p (PPatvar fc n) = pretty n
973 prettySe p (PRef fc n) =
979 prettyBasic n@(UN _) = pretty n
980 prettyBasic (MN _ s) = text s
981 prettyBasic (NS n s) = (foldr (<>) empty (intersperse (text ".") (map text $ reverse s))) <> prettyBasic n
982 prettyBasic (SN sn) = text (show sn)
983 prettySe p (PLam n ty sc) =
985 if size sc > breakingSize then
986 text "λ" <> pretty n <+> text "=>" $+$ pretty sc
988 text "λ" <> pretty n <+> text "=>" <+> pretty sc
989 prettySe p (PLet n ty v sc) =
991 if size sc > breakingSize then
992 text "let" <+> pretty n <+> text "=" <+> prettySe 10 v <+> text "in" $+$
993 nest nestingSize (prettySe 10 sc)
995 text "let" <+> pretty n <+> text "=" <+> prettySe 10 v <+> text "in" <+>
997 prettySe p (PPi (Exp l s _ _) n ty sc)
998 | n `elem` allNamesIn sc || impl =
999 let open = if l then text "|" <> lparen else lparen in
1001 if size sc > breakingSize then
1002 open <> pretty n <+> colon <+> prettySe 10 ty <> rparen <+>
1003 st <+> text "->" $+$ prettySe 10 sc
1005 open <> pretty n <+> colon <+> prettySe 10 ty <> rparen <+>
1006 st <+> text "->" <+> prettySe 10 sc
1009 if size sc > breakingSize then
1010 prettySe 0 ty <+> st <+> text "->" $+$ prettySe 10 sc
1012 prettySe 0 ty <+> st <+> text "->" <+> prettySe 10 sc
1016 Static -> text "[static]"
1018 prettySe p (PPi (Imp l s _ _) n ty sc)
1020 let open = if l then text "|" <> lbrace else lbrace in
1022 if size sc > breakingSize then
1023 open <> pretty n <+> colon <+> prettySe 10 ty <> rbrace <+>
1024 st <+> text "->" <+> prettySe 10 sc
1026 open <> pretty n <+> colon <+> prettySe 10 ty <> rbrace <+>
1027 st <+> text "->" <+> prettySe 10 sc
1028 | otherwise = prettySe 10 sc
1032 Static -> text $ "[static]"
1034 prettySe p (PPi (Constraint _ _ _) n ty sc) =
1036 if size sc > breakingSize then
1037 prettySe 10 ty <+> text "=>" <+> prettySe 10 sc
1039 prettySe 10 ty <+> text "=>" $+$ prettySe 10 sc
1040 prettySe p (PPi (TacImp _ _ s _) n ty sc) =
1042 if size sc > breakingSize then
1043 lbrace <> text "tacimp" <+> pretty n <+> colon <+> prettySe 10 ty <>
1044 rbrace <+> text "->" $+$ prettySe 10 sc
1046 lbrace <> text "tacimp" <+> pretty n <+> colon <+> prettySe 10 ty <>
1047 rbrace <+> text "->" <+> prettySe 10 sc
1048 prettySe p (PApp _ (PRef _ f) [])
1049 | not impl = pretty f
1050 prettySe p (PAppBind _ (PRef _ f) [])
1051 | not impl = text "!" <+> pretty f
1052 prettySe p (PApp _ (PRef _ op@(UN (f:_))) args)
1053 | length (getExps args) == 2 && (not impl) && (not $ isAlpha f) =
1054 let [l, r] = getExps args in
1056 if size r > breakingSize then
1057 prettySe 1 l <+> pretty op $+$ prettySe 0 r
1059 prettySe 1 l <+> pretty op <+> prettySe 0 r
1060 prettySe p (PApp _ f as) =
1061 let args = getExps as in
1066 -- foldr (<+>) empty $ map prettyArgS as
1068 foldl' fSe empty args
1069 -- foldr (<+>) empty $ map prettyArgSe args
1072 if size r > breakingSize then
1073 l $+$ nest nestingSize (prettyArgS r)
1078 if size r > breakingSize then
1079 l $+$ nest nestingSize (prettyArgSe r)
1082 prettySe p (PCase _ scr opts) =
1083 text "case" <+> prettySe 10 scr <+> text "of" $+$ nest nestingSize prettyBody
1085 prettyBody = foldr ($$) empty $ intersperse (text "|") $ map sc opts
1087 sc (l, r) = prettySe 10 l <+> text "=>" <+> prettySe 10 r
1088 prettySe p (PHidden tm) = text "." <> prettySe 0 tm
1089 prettySe p (PRefl _ _) = text "refl"
1090 prettySe p (PResolveTC _) = text "resolvetc"
1091 prettySe p (PTrue _) = text "()"
1092 prettySe p (PFalse _) = text "_|_"
1093 prettySe p (PEq _ l r) =
1095 if size r > breakingSize then
1096 prettySe 10 l <+> text "=" $$ nest nestingSize (prettySe 10 r)
1098 prettySe 10 l <+> text "=" <+> prettySe 10 r
1099 prettySe p (PRewrite _ l r _) =
1101 if size r > breakingSize then
1102 text "rewrite" <+> prettySe 10 l <+> text "in" $$ nest nestingSize (prettySe 10 r)
1104 text "rewrite" <+> prettySe 10 l <+> text "in" <+> prettySe 10 r
1105 prettySe p (PTyped l r) =
1106 lparen <> prettySe 10 l <+> colon <+> prettySe 10 r <> rparen
1107 prettySe p (PPair _ l r) =
1108 if size r > breakingSize then
1109 lparen <> prettySe 10 l <> text "," $+$
1110 prettySe 10 r <> rparen
1112 lparen <> prettySe 10 l <> text "," <+> prettySe 10 r <> rparen
1113 prettySe p (PDPair _ l t r) =
1114 if size r > breakingSize then
1115 lparen <> prettySe 10 l <+> text "**" $+$
1116 prettySe 10 r <> rparen
1118 lparen <> prettySe 10 l <+> text "**" <+> prettySe 10 r <> rparen
1119 prettySe p (PAlternative a as) =
1120 lparen <> text "|" <> prettyAs <> text "|" <> rparen
1123 foldr (\l -> \r -> l <+> text "," <+> r) empty $ map (prettySe 10) as
1124 prettySe p PType = text "Type"
1125 prettySe p (PConstant c) = pretty c
1126 -- XXX: add pretty for tactics
1127 prettySe p (PProof ts) =
1128 text "proof" <+> lbrace $+$ nest nestingSize (text . show $ ts) $+$ rbrace
1129 prettySe p (PTactics ts) =
1130 text "tactics" <+> lbrace $+$ nest nestingSize (text . show $ ts) $+$ rbrace
1131 prettySe p (PMetavar n) = text "?" <> pretty n
1132 prettySe p (PReturn f) = text "return"
1133 prettySe p PImpossible = text "impossible"
1134 prettySe p Placeholder = text "_"
1135 prettySe p (PDoBlock _) = text "do block pretty not implemented"
1136 prettySe p (PElabError s) = pretty s
1138 prettySe p _ = text "test"
1140 prettyArgS (PImp _ _ _ n tm _) = prettyArgSi (n, tm)
1141 prettyArgS (PExp _ _ tm _) = prettyArgSe tm
1142 prettyArgS (PConstraint _ _ tm _) = prettyArgSc tm
1143 prettyArgS (PTacImplicit _ _ n _ tm _) = prettyArgSti (n, tm)
1145 prettyArgSe arg = prettySe 0 arg
1146 prettyArgSi (n, val) = lbrace <> pretty n <+> text "=" <+> prettySe 10 val <> rbrace
1147 prettyArgSc val = lbrace <> lbrace <> prettySe 10 val <> rbrace <> rbrace
1148 prettyArgSti (n, val) = lbrace <> text "auto" <+> pretty n <+> text "=" <+> prettySe 10 val <> rbrace
1150 bracket outer inner doc
1151 | inner > outer = lparen <> doc <> rparen
1155showName :: Maybe IState -- ^^ the Idris state, for information about names and colours
1156 -> [(Name, Bool)] -- ^^ the bound variables and whether they're implicit
1157 -> Bool -- ^^ whether to show implicits
1158 -> Bool -- ^^ whether to colourise
1159 -> Name -- ^^ the term to show
1161showName ist bnd impl colour n = case ist of
1162 Just i -> if colour then colourise n (idris_colourTheme i) else showbasic n
1163 Nothing -> showbasic n
1164 where name = if impl then show n else showbasic n
1165 showbasic n@(UN _) = showCG n
1166 showbasic (MN _ s) = s
1167 showbasic (NS n s) = showSep "." (reverse s) ++ "." ++ showbasic n
1168 showbasic (SN s) = show s
1170 colourise n t = let ctxt' = fmap tt_ctxt ist in
1173 Just ctxt | Just impl <- lookup n bnd -> if impl then colouriseImplicit t name
1174 else colouriseBound t name
1175 | isDConName n ctxt -> colouriseData t name
1176 | isFnName n ctxt -> colouriseFun t name
1177 | isTConName n ctxt -> colouriseType t name
1178 -- The assumption is that if a name is not bound and does not exist in the
1179 -- global context, then we're somewhere in which implicit info has been lost
1180 -- (like error messages). Thus, unknown vars are colourised as implicits.
1181 | otherwise -> colouriseImplicit t name
1184showImp :: Maybe IState -- ^^ the Idris state, for information about identifiers and colours
1185 -> Bool -- ^^ whether to show implicits
1186 -> Bool -- ^^ whether to colourise
1187 -> PTerm -- ^^ the term to show
1189showImp ist impl colour tm = se 10 [] tm where
1190 perhapsColourise :: (ColourTheme -> String -> String) -> String -> String
1191 perhapsColourise col str = case ist of
1192 Just i -> if colour then col (idris_colourTheme i) str else str
1195 se :: Int -> [(Name, Bool)] -> PTerm -> String
1196 se p bnd (PQuote r) = "![" ++ show r ++ "]"
1197 se p bnd (PPatvar fc n) = if impl then show n ++ "[p]" else show n
1198 se p bnd (PInferRef fc n) = "!" ++ show n -- ++ "[" ++ show fc ++ "]"
1200 | Just str <- slist p bnd e = str
1201 | Just num <- snat p e = perhapsColourise colouriseData (show num)
1202 se p bnd (PRef fc n) = showName ist bnd impl colour n
1203 se p bnd (PLam n ty sc) = bracket p 2 $ "\\ " ++ perhapsColourise colouriseBound (show n) ++
1204 (if impl then " : " ++ se 10 bnd ty else "") ++ " => "
1205 ++ se 10 ((n, False):bnd) sc
1206 se p bnd (PLet n ty v sc) = bracket p 2 $ "let " ++ perhapsColourise colouriseBound (show n) ++
1207 " = " ++ se 10 bnd v ++
1208 " in " ++ se 10 ((n, False):bnd) sc
1209 se p bnd (PPi (Exp l s _ param) n ty sc)
1210 | n `elem` allNamesIn sc || impl
1212 (if l then "|(" else "(") ++
1213 perhapsColourise colouriseBound (show n) ++ " : " ++ se 10 bnd ty ++
1215 (if (impl && param) then "P" else "") ++
1217 "-> " ++ se 10 ((n, False):bnd) sc
1218 | otherwise = bracket p 2 $ se 0 bnd ty ++ " " ++ st ++ "-> " ++ se 10 bnd sc
1219 where st = case s of
1220 Static -> "[static] "
1222 se p bnd (PPi (Imp l s _ _) n ty sc)
1223 | impl = bracket p 2 $ (if l then "|{" else "{") ++
1224 perhapsColourise colouriseBound (show n) ++ " : " ++ se 10 bnd ty ++
1225 "} " ++ st ++ "-> " ++ se 10 ((n, True):bnd) sc
1226 | otherwise = se 10 ((n, True):bnd) sc
1227 where st = case s of
1228 Static -> "[static] "
1230 se p bnd (PPi (Constraint _ _ _) n ty sc)
1231 = bracket p 2 $ se 10 bnd ty ++ " => " ++ se 10 bnd sc
1232 se p bnd (PPi (TacImp _ _ s _) n ty sc)
1234 "{tacimp " ++ (perhapsColourise colouriseBound (show n)) ++ " : " ++ se 10 bnd ty ++ "} -> " ++
1235 se 10 ((n, False):bnd) sc
1236 se p bnd (PMatchApp _ f) = "match " ++ show f
1237 se p bnd (PApp _ hd@(PRef _ f) [])
1238 | not impl = se p bnd hd
1239 se p bnd (PAppBind _ hd@(PRef _ f) [])
1240 | not impl = "!" ++ se p bnd hd
1241 se p bnd (PApp _ op@(PRef _ (UN (f:_))) args)
1242 | length (getExps args) == 2 && not impl && not (isAlpha f)
1243 = let [l, r] = getExps args in
1244 bracket p 1 $ se 1 bnd l ++ " " ++ se p bnd op ++ " " ++ se 0 bnd r
1245 se p bnd (PApp _ f as)
1246 = -- let args = getExps as in
1247 bracket p 1 $ se 1 bnd f ++
1248 if impl then concatMap (sArg bnd) as
1249 else concatMap (suiArg impl bnd) as
1250 se p bnd (PAppBind _ f as)
1251 = let args = getExps as in
1252 "!" ++ (bracket p 1 $ se 1 bnd f ++ if impl then concatMap (sArg bnd) as
1253 else concatMap (seArg bnd) args)
1254 se p bnd (PCase _ scr opts) = "case " ++ se 10 bnd scr ++ " of " ++ showSep " | " (map sc opts)
1255 where sc (l, r) = se 10 bnd l ++ " => " ++ se 10 bnd r
1256 se p bnd (PHidden tm) = "." ++ se 0 bnd tm
1257 se p bnd (PRefl _ t)
1258 | not impl = perhapsColourise colouriseData "refl"
1259 | otherwise = perhapsColourise colouriseData $ "refl {" ++ se 10 bnd t ++ "}"
1260 se p bnd (PResolveTC _) = "resolvetc"
1261 se p bnd (PTrue _) = perhapsColourise colouriseType "()"
1262 se p bnd (PFalse _) = perhapsColourise colouriseType "_|_"
1263 se p bnd (PEq _ l r) = bracket p 2 $ se 10 bnd l ++ perhapsColourise colouriseType " = " ++ se 10 bnd r
1264 se p bnd (PRewrite _ l r _) = bracket p 2 $ "rewrite " ++ se 10 bnd l ++ " in " ++ se 10 bnd r
1265 se p bnd (PTyped l r) = "(" ++ se 10 bnd l ++ " : " ++ se 10 bnd r ++ ")"
1266 se p bnd (PPair _ l r) = "(" ++ se 10 bnd l ++ ", " ++ se 10 bnd r ++ ")"
1267 se p bnd (PDPair _ l t r) = "(" ++ se 10 bnd l ++ " ** " ++ se 10 bnd r ++ ")"
1268 se p bnd (PAlternative a as) = "(|" ++ showSep " , " (map (se 10 bnd) as) ++ "|)"
1269 se p bnd PType = perhapsColourise colouriseType "Type"
1270 se p bnd (PConstant c) = perhapsColourise (cfun c) (show c)
1271 where cfun (AType _) = colouriseType
1272 cfun StrType = colouriseType
1273 cfun PtrType = colouriseType
1274 cfun VoidType = colouriseType
1275 cfun _ = colouriseData
1276 se p bnd (PProof ts) = "proof { " ++ show ts ++ "}"
1277 se p bnd (PTactics ts) = "tactics { " ++ show ts ++ "}"
1278 se p bnd (PMetavar n) = "?" ++ show n
1279 se p bnd (PReturn f) = "return"
1280 se p bnd PImpossible = "impossible"
1281 se p bnd Placeholder = "_"
1282 se p bnd (PDoBlock _) = "do block show not implemented"
1283 se p bnd (PElabError s) = show s
1284 se p bnd (PCoerced t) = se p bnd t
1285 se p bnd (PUnifyLog t) = "%unifyLog " ++ se p bnd t
1286 se p bnd (PNoImplicits t) = "%noimplicit " ++ se p bnd t
1287-- se p bnd x = "Not implemented"
1289 slist' p bnd (PApp _ (PRef _ nil) _)
1290 | not impl && nsroot nil == UN "Nil" = Just []
1291 slist' p bnd (PApp _ (PRef _ cons) args)
1292 | nsroot cons == UN "::",
1293 (PExp {getTm=tl}):(PExp {getTm=hd}):imps <- reverse args,
1295 Just tl' <- slist' p bnd tl
1298 isImp (PImp {}) = True
1300 slist' _ _ _ = Nothing
1302 slist p bnd e | Just es <- slist' p bnd e = Just $
1303 case es of [] -> "[]"
1304 [x] -> "[" ++ se p bnd x ++ "]"
1305 xs -> "[" ++ intercalate "," (map (se p bnd ) xs) ++ "]"
1306 slist _ _ _ = Nothing
1308 -- since Prelude is always imported, S & Z are unqualified iff they're the
1311 | show o == (natns++"Z") || show o == "Z" = Just 0
1312 snat p (PApp _ s [PExp {getTm=n}])
1313 | show s == (natns++"S") || show s == "S",
1318 natns = "Prelude.Nat."
1320 sArg bnd (PImp _ _ _ n tm _) = siArg bnd (n, tm)
1321 sArg bnd (PExp _ _ tm _) = seArg bnd tm
1322 sArg bnd (PConstraint _ _ tm _) = scArg bnd tm
1323 sArg bnd (PTacImplicit _ _ n _ tm _) = stiArg bnd (n, tm)
1325 -- show argument, implicits given by the user also shown
1326 suiArg impl bnd (PImp _ mi _ n tm _)
1327 | impl || not mi = siArg bnd (n, tm)
1328 suiArg impl bnd (PExp _ _ tm _) = seArg bnd tm
1329 suiArg impl bnd _ = ""
1331 seArg bnd arg = " " ++ se 0 bnd arg
1332 siArg bnd (n, val) =
1334 val' = se 10 bnd val in
1336 then " {" ++ n' ++ "}"
1337 else " {" ++ n' ++ " = " ++ val' ++ "}"
1338 scArg bnd val = " {{" ++ se 10 bnd val ++ "}}"
1339 stiArg bnd (n, val) = " {auto " ++ show n ++ " = " ++ se 10 bnd val ++ "}"
1341 bracket outer inner str | inner > outer = "(" ++ str ++ ")"
1345instance Sized PTerm where
1346 size (PQuote rawTerm) = size rawTerm
1347 size (PRef fc name) = size name
1348 size (PLam name ty bdy) = 1 + size ty + size bdy
1349 size (PPi plicity name ty bdy) = 1 + size ty + size bdy
1350 size (PLet name ty def bdy) = 1 + size ty + size def + size bdy
1351 size (PTyped trm ty) = 1 + size trm + size ty
1352 size (PApp fc name args) = 1 + size args
1353 size (PAppBind fc name args) = 1 + size args
1354 size (PCase fc trm bdy) = 1 + size trm + size bdy
1356 size (PFalse fc) = 1
1357 size (PRefl fc _) = 1
1358 size (PResolveTC fc) = 1
1359 size (PEq fc left right) = 1 + size left + size right
1360 size (PRewrite fc left right _) = 1 + size left + size right
1361 size (PPair fc left right) = 1 + size left + size right
1362 size (PDPair fs left ty right) = 1 + size left + size ty + size right
1363 size (PAlternative a alts) = 1 + size alts
1364 size (PHidden hidden) = size hidden
1365 size (PUnifyLog tm) = size tm
1366 size (PNoImplicits tm) = size tm
1368 size (PConstant const) = 1 + size const
1369 size Placeholder = 1
1370 size (PDoBlock dos) = 1 + size dos
1371 size (PIdiom fc term) = 1 + size term
1372 size (PReturn fc) = 1
1373 size (PMetavar name) = 1
1374 size (PProof tactics) = size tactics
1375 size (PElabError err) = size err
1376 size PImpossible = 1
1378getPArity :: PTerm -> Int
1379getPArity (PPi _ _ _ sc) = 1 + getPArity sc
1382-- Return all names, free or globally bound, in the given term.
1384allNamesIn :: PTerm -> [Name]
1385allNamesIn tm = nub $ ni [] tm
1388 | not (n `elem` env) = [n]
1389 ni env (PApp _ f as) = ni env f ++ concatMap (ni env) (map getTm as)
1390 ni env (PAppBind _ f as) = ni env f ++ concatMap (ni env) (map getTm as)
1391 ni env (PCase _ c os) = ni env c ++ concatMap (ni env) (map snd os)
1392 ni env (PLam n ty sc) = ni env ty ++ ni (n:env) sc
1393 ni env (PPi _ n ty sc) = ni env ty ++ ni (n:env) sc
1394 ni env (PHidden tm) = ni env tm
1395 ni env (PEq _ l r) = ni env l ++ ni env r
1396 ni env (PRewrite _ l r _) = ni env l ++ ni env r
1397 ni env (PTyped l r) = ni env l ++ ni env r
1398 ni env (PPair _ l r) = ni env l ++ ni env r
1399 ni env (PDPair _ (PRef _ n) t r) = ni env t ++ ni (n:env) r
1400 ni env (PDPair _ l t r) = ni env l ++ ni env t ++ ni env r
1401 ni env (PAlternative a ls) = concatMap (ni env) ls
1402 ni env (PUnifyLog tm) = ni env tm
1403 ni env (PNoImplicits tm) = ni env tm
1406-- Return names which are free in the given term.
1408namesIn :: [(Name, PTerm)] -> IState -> PTerm -> [Name]
1409namesIn uvars ist tm = nub $ ni [] tm
1412 | not (n `elem` env)
1413 = case lookupTy n (tt_ctxt ist) of
1415 _ -> if n `elem` (map fst uvars) then [n] else []
1416 ni env (PApp _ f as) = ni env f ++ concatMap (ni env) (map getTm as)
1417 ni env (PAppBind _ f as) = ni env f ++ concatMap (ni env) (map getTm as)
1418 ni env (PCase _ c os) = ni env c ++ concatMap (ni env) (map snd os)
1419 ni env (PLam n ty sc) = ni env ty ++ ni (n:env) sc
1420 ni env (PPi _ n ty sc) = ni env ty ++ ni (n:env) sc
1421 ni env (PEq _ l r) = ni env l ++ ni env r
1422 ni env (PRewrite _ l r _) = ni env l ++ ni env r
1423 ni env (PTyped l r) = ni env l ++ ni env r
1424 ni env (PPair _ l r) = ni env l ++ ni env r
1425 ni env (PDPair _ (PRef _ n) t r) = ni env t ++ ni (n:env) r
1426 ni env (PDPair _ l t r) = ni env l ++ ni env t ++ ni env r
1427 ni env (PAlternative a as) = concatMap (ni env) as
1428 ni env (PHidden tm) = ni env tm
1429 ni env (PUnifyLog tm) = ni env tm
1430 ni env (PNoImplicits tm) = ni env tm
1433-- Return which of the given names are used in the given term.
1435usedNamesIn :: [Name] -> IState -> PTerm -> [Name]
1436usedNamesIn vars ist tm = nub $ ni [] tm
1439 | n `elem` vars && not (n `elem` env)
1440 = case lookupTy n (tt_ctxt ist) of
1443 ni env (PApp _ f as) = ni env f ++ concatMap (ni env) (map getTm as)
1444 ni env (PAppBind _ f as) = ni env f ++ concatMap (ni env) (map getTm as)
1445 ni env (PCase _ c os) = ni env c ++ concatMap (ni env) (map snd os)
1446 ni env (PLam n ty sc) = ni env ty ++ ni (n:env) sc
1447 ni env (PPi _ n ty sc) = ni env ty ++ ni (n:env) sc
1448 ni env (PEq _ l r) = ni env l ++ ni env r
1449 ni env (PRewrite _ l r _) = ni env l ++ ni env r
1450 ni env (PTyped l r) = ni env l ++ ni env r
1451 ni env (PPair _ l r) = ni env l ++ ni env r
1452 ni env (PDPair _ (PRef _ n) t r) = ni env t ++ ni (n:env) r
1453 ni env (PDPair _ l t r) = ni env l ++ ni env t ++ ni env r
1454 ni env (PAlternative a as) = concatMap (ni env) as
1455 ni env (PHidden tm) = ni env tm
1456 ni env (PUnifyLog tm) = ni env tm
1457 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