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
29import Data.Word (Word)
33data IOption = IOption { opt_logLevel :: Int,
35 opt_typeintype :: Bool,
37 opt_showimp :: Bool, -- ^^ show implicits
38 opt_errContext :: Bool,
43 opt_codegen :: Codegen,
44 opt_outputTy :: OutputType,
45 opt_ibcsubdir :: FilePath,
46 opt_importdirs :: [FilePath],
50 opt_cmdline :: [Opt] -- remember whole command line
54defaultOpts = IOption { opt_logLevel = 0
55 , opt_typecase = False
56 , opt_typeintype = False
59 , opt_errContext = False
62 , opt_nobanner = False
65 , opt_outputTy = Executable
74data LanguageExt = TypeProviders | ErrorReflection deriving (Show, Eq, Read, Ord)
76-- | The output mode in use
77data OutputMode = RawOutput | IdeSlave Integer deriving Show
79-- TODO: Add 'module data' to IState, which can be saved out and reloaded quickly (i.e
80-- without typechecking).
81-- This will include all the functions and data declarations, plus fixity declarations
84-- | The global state used in the Idris monad
86 tt_ctxt :: Context, -- ^ All the currently defined names and their terms
87 idris_constraints :: [(UConstraint, FC)],
88 -- ^ A list of universe constraints and their corresponding source locations
89 idris_infixes :: [FixDecl], -- ^ Currently defined infix operators
90 idris_implicits :: Ctxt [PArg],
91 idris_statics :: Ctxt [Bool],
92 idris_classes :: Ctxt ClassInfo,
93 idris_dsls :: Ctxt DSL,
94 idris_optimisation :: Ctxt OptInfo,
95 idris_datatypes :: Ctxt TypeInfo,
96 idris_namehints :: Ctxt [Name],
97 idris_patdefs :: Ctxt ([([Name], Term, Term)], [PTerm]), -- not exported
98 -- ^ list of lhs/rhs, and a list of missing clauses
99 idris_flags :: Ctxt [FnOpt],
100 idris_callgraph :: Ctxt CGInfo, -- name, args used in each pos
101 idris_calledgraph :: Ctxt [Name],
102 idris_docstrings :: Ctxt String,
103 idris_totcheck :: [(FC, Name)], -- names to check totality on
104 idris_defertotcheck :: [(FC, Name)], -- names to check at the end
105 idris_options :: IOption,
107 idris_lineapps :: [((FilePath, Int), PTerm)],
108 -- ^ Full application LHS on source line
109 idris_metavars :: [(Name, (Maybe Name, Int, Bool))], -- ^ The currently defined but not proven metavariables
110 idris_coercions :: [Name],
111 idris_transforms :: [(Term, Term)],
112 syntax_rules :: [Syntax],
113 syntax_keywords :: [String],
114 imported :: [FilePath], -- ^ The imported modules
115 idris_scprims :: [(Name, (Int, PrimFn))],
116 idris_objs :: [(Codegen, FilePath)],
117 idris_libs :: [(Codegen, String)],
118 idris_cgflags :: [(Codegen, String)],
119 idris_hdrs :: [(Codegen, String)],
120 proof_list :: [(Name, [String])],
121 errLine :: Maybe Int,
122 lastParse :: Maybe Name,
123 indent_stack :: [Int],
124 brace_stack :: [Maybe Int],
125 hide_list :: [(Name, Maybe Accessibility)],
126 default_access :: Accessibility,
127 default_total :: Bool,
128 ibc_write :: [IBCWrite],
129 compiled_so :: Maybe String,
130 idris_dynamic_libs :: [DynamicLib],
131 idris_language_extensions :: [LanguageExt],
132 idris_outputmode :: OutputMode,
133 idris_colourRepl :: Bool,
134 idris_colourTheme :: ColourTheme,
135 idris_outh :: Handle,
136 idris_errorhandlers :: [Name],
137 idris_nameIdx :: (Int, Ctxt (Int, Name))
140data SizeChange = Smaller | Same | Bigger | Unknown
143deriving instance Binary SizeChange
144deriving instance NFData SizeChange
147type SCGEntry = (Name, [Maybe (Int, SizeChange)])
149data CGInfo = CGInfo { argsdef :: [Name],
150 calls :: [(Name, [[Name]])],
156deriving instance Binary CGInfo
157deriving instance NFData CGInfo
160primDefs = [sUN "unsafePerformPrimIO",
161 sUN "mkLazyForeignPrim",
165-- information that needs writing for the current module's .ibc file
166data IBCWrite = IBCFix FixDecl
170 | IBCInstance Bool Name Name
177 | IBCObj Codegen FilePath
178 | IBCLib Codegen String
179 | IBCCGFlag Codegen String
181 | IBCHeader Codegen String
182 | IBCAccess Name Accessibility
183 | IBCMetaInformation Name MetaInformation
184 | IBCTotal Name Totality
185 | IBCFlags Name [FnOpt]
186 | IBCTrans (Term, Term)
190 | IBCDef Name -- i.e. main context
191 | IBCNameHint (Name, Name)
192 | IBCLineApp FilePath Int PTerm
195-- | The initial state for the compiler
197idrisInit = IState initContext [] [] emptyContext emptyContext emptyContext
198 emptyContext emptyContext emptyContext emptyContext
199 emptyContext emptyContext emptyContext emptyContext
201 [] [] defaultOpts 6 [] [] [] [] [] [] [] [] [] [] [] []
202 [] Nothing Nothing [] [] [] Hidden False [] Nothing [] [] RawOutput
203 True defaultTheme stdout [] (0, emptyContext)
205-- | The monad for the main REPL - reading and processing files and updating
206-- global state (hence the IO inner monad).
207--type Idris = WriterT [Either String (IO ())] (State IState a))
208type Idris = StateT IState (ErrorT Err IO)
210-- Commands in the REPL
229 | ChangeDirectory FilePath
232 | Compile Codegen String
237 | AddProof (Maybe Name)
249 | DynamicLink FilePath
254 | CaseSplitAt Bool Int Name
255 | AddClauseFrom Bool Int Name
256 | AddProofClauseFrom Bool Int Name
257 | AddMissing Bool Int Name
258 | MakeWith Bool Int Name
259 | DoProofSearch Bool Int Name [Name]
263 | SetColour ColourType IdrisColour
268data Opt = Filename String
280 | NoBuiltins -- only for the really primitive stuff!
305 | OutputTy OutputType
306 | Extension LanguageExt
307 | InterpretScript String
308 | TargetTriple String
314-- Parsed declarations
316data Fixity = Infixl { prec :: Int }
317 | Infixr { prec :: Int }
318 | InfixN { prec :: Int }
319 | PrefixN { prec :: Int }
322deriving instance Binary Fixity
323deriving instance NFData Fixity
326instance Show Fixity where
327 show (Infixl i) = "infixl " ++ show i
328 show (Infixr i) = "infixr " ++ show i
329 show (InfixN i) = "infix " ++ show i
330 show (PrefixN i) = "prefix " ++ show i
332data FixDecl = Fix Fixity String
335instance Show FixDecl where
336 show (Fix f s) = show f ++ " " ++ s
339deriving instance Binary FixDecl
340deriving instance NFData FixDecl
343instance Ord FixDecl where
344 compare (Fix x _) (Fix y _) = compare (prec x) (prec y)
347data Static = Static | Dynamic
350deriving instance Binary Static
351deriving instance NFData Static
354-- Mark bindings with their explicitness, and laziness
355data Plicity = Imp { plazy :: Bool,
359 | Exp { plazy :: Bool,
363 | Constraint { plazy :: Bool,
366 | TacImp { plazy :: Bool,
373deriving instance Binary Plicity
374deriving instance NFData Plicity
377impl = Imp False Dynamic "" False
378expl = Exp False Dynamic "" False
379expl_param = Exp False Dynamic "" True
380constraint = Constraint False Dynamic ""
381tacimpl t = TacImp False Dynamic t ""
383data FnOpt = Inlinable -- always evaluate when simplifying
384 | TotalFn | PartialFn
385 | Coinductive | AssertTotal
386 | Dictionary -- type class dictionary, eval only when
387 -- a function argument, and further evaluation resutls
388 | Implicit -- implicit coercion
389 | CExport String -- export, with a C name
390 | ErrorHandler -- ^^ an error handler for use with the ErrorReflection extension
391 | Reflection -- a reflecting function, compile-time only
392 | Specialise [(Name, Maybe Int)] -- specialise it, freeze these names
395deriving instance Binary FnOpt
396deriving instance NFData FnOpt
401inlinable :: FnOpts -> Bool
402inlinable = elem Inlinable
404dictionary :: FnOpts -> Bool
405dictionary = elem Dictionary
408-- | Data declaration options
409data DataOpt = Codata -- Set if the the data-type is coinductive
410 | DefaultEliminator -- Set if an eliminator should be generated for data type
413type DataOpts = [DataOpt]
415-- | Top-level declarations such as compiler directives, definitions,
416-- datatypes and typeclasses.
418 = PFix FC Fixity [String] -- ^ Fixity declaration
419 | PTy String SyntaxInfo FC FnOpts Name t -- ^ Type declaration
420 | PPostulate String SyntaxInfo FC FnOpts Name t -- ^ Postulate
421 | PClauses FC FnOpts Name [PClause' t] -- ^ Pattern clause
422 | PCAF FC Name t -- ^ Top level constant
423 | PData String SyntaxInfo FC DataOpts (PData' t) -- ^ Data declaration.
424 | PParams FC [(Name, t)] [PDecl' t] -- ^ Params block
425 | PNamespace String [PDecl' t] -- ^ New namespace
426 | PRecord String SyntaxInfo FC Name t String Name t -- ^ Record declaration
427 | PClass String SyntaxInfo FC
430 [(Name, t)] -- parameters
431 [PDecl' t] -- declarations
432 -- ^ Type class: arguments are documentation, syntax info, source location, constraints,
433 -- class name, parameters, method declarations
434 | PInstance SyntaxInfo FC [t] -- constraints
437 t -- full instance type
438 (Maybe Name) -- explicit name
440 -- ^ Instance declaration: arguments are syntax info, source location, constraints,
441 -- class name, parameters, full instance type, optional explicit name, and definitions
442 | PDSL Name (DSL' t) -- ^ DSL declaration
443 | PSyntax FC Syntax -- ^ Syntax definition
444 | PMutual FC [PDecl' t] -- ^ Mutual block
445 | PDirective (Idris ()) -- ^ Compiler directive. The parser inserts the corresponding action in the Idris monad.
446 | PProvider SyntaxInfo FC Name t t -- ^ Type provider. The first t is the type, the second is the term
447 | PTransform FC Bool t t -- ^ Source-to-source transformation rule. If
448 -- bool is True, lhs and rhs must be convertible
451deriving instance Binary PDecl'
452deriving instance NFData PDecl'
455-- For elaborator state
456type ElabD a = Elab' [PDecl] a
458-- | One clause of a top-level definition. Term arguments to constructors are:
460-- 1. The whole application (missing for PClauseR and PWithR because they're within a "with" clause)
462-- 2. The list of extra 'with' patterns
464-- 3. The right-hand side
466-- 4. The where block (PDecl' t)
468data PClause' t = PClause FC Name t [t] t [PDecl' t] -- ^ A normal top-level definition.
469 | PWith FC Name t [t] t [PDecl' t]
470 | PClauseR FC [t] t [PDecl' t]
471 | PWithR FC [t] t [PDecl' t]
474deriving instance Binary PClause'
475deriving instance NFData PClause'
479data PData' t = PDatadecl { d_name :: Name, -- ^ The name of the datatype
480 d_tcon :: t, -- ^ Type constructor
481 d_cons :: [(String, Name, t, FC, [Name])] -- ^ Constructors
483 -- ^ Data declaration
484 | PLaterdecl { d_name :: Name, d_tcon :: t }
485 -- ^ "Placeholder" for data whose constructors are defined later
488deriving instance Binary PData'
489deriving instance NFData PData'
492-- Handy to get a free function for applying PTerm -> PTerm functions
493-- across a program, by deriving Functor
495type PDecl = PDecl' PTerm
496type PData = PData' PTerm
497type PClause = PClause' PTerm
499-- get all the names declared in a decl
501declared :: PDecl -> [Name]
502declared (PFix _ _ _) = []
503declared (PTy _ _ _ _ n t) = [n]
504declared (PPostulate _ _ _ _ n t) = [n]
505declared (PClauses _ _ n _) = [] -- not a declaration
506declared (PCAF _ n _) = [n]
507declared (PData _ _ _ _ (PDatadecl n _ ts)) = n : map fstt ts
508 where fstt (_, a, _, _, _) = a
509declared (PData _ _ _ _ (PLaterdecl n _)) = [n]
510declared (PParams _ _ ds) = concatMap declared ds
511declared (PNamespace _ ds) = concatMap declared ds
512declared (PRecord _ _ _ n _ _ c _) = [n, c]
513declared (PClass _ _ _ _ n _ ms) = n : concatMap declared ms
514declared (PInstance _ _ _ _ _ _ _ _) = []
515declared (PDSL n _) = [n]
516declared (PSyntax _ _) = []
517declared (PMutual _ ds) = concatMap declared ds
518declared (PDirective _) = []
520-- get the names declared, not counting nested parameter blocks
521tldeclared :: PDecl -> [Name]
522tldeclared (PFix _ _ _) = []
523tldeclared (PTy _ _ _ _ n t) = [n]
524tldeclared (PPostulate _ _ _ _ n t) = [n]
525tldeclared (PClauses _ _ n _) = [] -- not a declaration
526tldeclared (PRecord _ _ _ n _ _ c _) = [n, c]
527tldeclared (PData _ _ _ _ (PDatadecl n _ ts)) = n : map fstt ts
528 where fstt (_, a, _, _, _) = a
529tldeclared (PParams _ _ ds) = []
530tldeclared (PMutual _ ds) = concatMap tldeclared ds
531tldeclared (PNamespace _ ds) = concatMap tldeclared ds
532tldeclared (PClass _ _ _ _ n _ ms) = concatMap tldeclared ms
533tldeclared (PInstance _ _ _ _ _ _ _ _) = []
536defined :: PDecl -> [Name]
537defined (PFix _ _ _) = []
538defined (PTy _ _ _ _ n t) = []
539defined (PPostulate _ _ _ _ n t) = []
540defined (PClauses _ _ n _) = [n] -- not a declaration
541defined (PCAF _ n _) = [n]
542defined (PData _ _ _ _ (PDatadecl n _ ts)) = n : map fstt ts
543 where fstt (_, a, _, _, _) = a
544defined (PData _ _ _ _ (PLaterdecl n _)) = []
545defined (PParams _ _ ds) = concatMap defined ds
546defined (PNamespace _ ds) = concatMap defined ds
547defined (PRecord _ _ _ n _ _ c _) = [n, c]
548defined (PClass _ _ _ _ n _ ms) = n : concatMap defined ms
549defined (PInstance _ _ _ _ _ _ _ _) = []
550defined (PDSL n _) = [n]
551defined (PSyntax _ _) = []
552defined (PMutual _ ds) = concatMap defined ds
553defined (PDirective _) = []
556updateN :: [(Name, Name)] -> Name -> Name
557updateN ns n | Just n' <- lookup n ns = n'
560updateNs :: [(Name, Name)] -> PTerm -> PTerm
562updateNs ns t = mapPT updateRef t
563 where updateRef (PRef fc f) = PRef fc (updateN ns f)
566-- updateDNs :: [(Name, Name)] -> PDecl -> PDecl
568-- updateDNs ns (PTy s f n t) | Just n' <- lookup n ns = PTy s f n' t
569-- updateDNs ns (PClauses f n c) | Just n' <- lookup n ns = PClauses f n' (map updateCNs c)
570-- where updateCNs ns (PClause n l ts r ds)
571-- = PClause (updateN ns n) (fmap (updateNs ns) l)
572-- (map (fmap (updateNs ns)) ts)
573-- (fmap (updateNs ns) r)
574-- (map (updateDNs ns) ds)
577-- | High level language terms
578data PTerm = PQuote Raw
580 | PInferRef FC Name -- ^ A name to be defined later
582 | PLam Name PTerm PTerm
583 | PPi Plicity Name PTerm PTerm
584 | PLet Name PTerm PTerm PTerm
585 | PTyped PTerm PTerm -- ^ Term with explicit type
586 | PApp FC PTerm [PArg]
587 | PAppBind FC PTerm [PArg] -- ^ implicitly bound application
588 | PMatchApp FC Name -- ^ Make an application by type matching
589 | PCase FC PTerm [(PTerm, PTerm)]
595 | PRewrite FC PTerm PTerm (Maybe PTerm)
596 | PPair FC PTerm PTerm
597 | PDPair FC PTerm PTerm PTerm
598 | PAlternative Bool [PTerm] -- True if only one may work
599 | PHidden PTerm -- ^ Irrelevant or hidden pattern
601 | PGoal FC PTerm Name PTerm
608 | PProof [PTactic] -- ^ Proof script
609 | PTactics [PTactic] -- ^ As PProof, but no auto solving
610 | PElabError Err -- ^ Error to report on elaboration
611 | PImpossible -- ^ Special case for declaring when an LHS can't typecheck
612 | PCoerced PTerm -- ^ To mark a coerced argument, so as not to coerce twice
613 | PDisamb [[T.Text]] PTerm -- ^ Preferences for explicit namespaces
614 | PUnifyLog PTerm -- ^ dump a trace of unifications when building term
615 | PNoImplicits PTerm -- ^ never run implicit converions on the term
620deriving instance Binary PTerm
621deriving instance NFData PTerm
624mapPT :: (PTerm -> PTerm) -> PTerm -> PTerm
625mapPT f t = f (mpt t) where
626 mpt (PLam n t s) = PLam n (mapPT f t) (mapPT f s)
627 mpt (PPi p n t s) = PPi p n (mapPT f t) (mapPT f s)
628 mpt (PLet n ty v s) = PLet n (mapPT f ty) (mapPT f v) (mapPT f s)
629 mpt (PRewrite fc t s g) = PRewrite fc (mapPT f t) (mapPT f s)
631 mpt (PApp fc t as) = PApp fc (mapPT f t) (map (fmap (mapPT f)) as)
632 mpt (PAppBind fc t as) = PAppBind fc (mapPT f t) (map (fmap (mapPT f)) as)
633 mpt (PCase fc c os) = PCase fc (mapPT f c) (map (pmap (mapPT f)) os)
634 mpt (PEq fc l r) = PEq fc (mapPT f l) (mapPT f r)
635 mpt (PTyped l r) = PTyped (mapPT f l) (mapPT f r)
636 mpt (PPair fc l r) = PPair fc (mapPT f l) (mapPT f r)
637 mpt (PDPair fc l t r) = PDPair fc (mapPT f l) (mapPT f t) (mapPT f r)
638 mpt (PAlternative a as) = PAlternative a (map (mapPT f) as)
639 mpt (PHidden t) = PHidden (mapPT f t)
640 mpt (PDoBlock ds) = PDoBlock (map (fmap (mapPT f)) ds)
641 mpt (PProof ts) = PProof (map (fmap (mapPT f)) ts)
642 mpt (PTactics ts) = PTactics (map (fmap (mapPT f)) ts)
643 mpt (PUnifyLog tm) = PUnifyLog (mapPT f tm)
644 mpt (PDisamb ns tm) = PDisamb ns (mapPT f tm)
645 mpt (PNoImplicits tm) = PNoImplicits (mapPT f tm)
646 mpt (PGoal fc r n sc) = PGoal fc (mapPT f r) n (mapPT f sc)
650data PTactic' t = Intro [Name] | Intros | Focus Name
651 | Refine Name [Bool] | Rewrite t
655 | LetTac Name t | LetTacTy Name t t
656 | Exact t | Compute | Trivial
657 | ProofSearch (Maybe Name) Name [Name]
660 | ProofState | ProofTerm | Undo
661 | Try (PTactic' t) (PTactic' t)
662 | TSeq (PTactic' t) (PTactic' t)
663 | ApplyTactic t -- see Language.Reflection module
667 | GoalType String (PTactic' t)
669 deriving (Show, Eq, Functor)
671deriving instance Binary PTactic'
672deriving instance NFData PTactic'
675instance Sized a => Sized (PTactic' a) where
676 size (Intro nms) = 1 + size nms
678 size (Focus nm) = 1 + size nm
679 size (Refine nm bs) = 1 + size nm + length bs
680 size (Rewrite t) = 1 + size t
681 size (Induction t) = 1 + size t
682 size (LetTac nm t) = 1 + size nm + size t
683 size (Exact t) = 1 + size t
691 size (Try l r) = 1 + size l + size r
692 size (TSeq l r) = 1 + size l + size r
693 size (ApplyTactic t) = 1 + size t
694 size (Reflect t) = 1 + size t
695 size (Fill t) = 1 + size t
699type PTactic = PTactic' PTerm
701data PDo' t = DoExp FC t
706 deriving (Eq, Functor)
708deriving instance Binary PDo'
709deriving instance NFData PDo'
712instance Sized a => Sized (PDo' a) where
713 size (DoExp fc t) = 1 + size fc + size t
714 size (DoBind fc nm t) = 1 + size fc + size nm + size t
715 size (DoBindP fc l r) = 1 + size fc + size l + size r
716 size (DoLet fc nm l r) = 1 + size fc + size nm + size l + size r
717 size (DoLetP fc l r) = 1 + size fc + size l + size r
721-- The priority gives a hint as to elaboration order. Best to elaborate
722-- things early which will help give a more concrete type to other
723-- variables, e.g. a before (interpTy a).
725data PArg' t = PImp { priority :: Int,
726 machine_inf :: Bool, -- true if the machine inferred it
727 lazyarg :: Bool, pname :: Name, getTm :: t,
729 | PExp { priority :: Int,
730 lazyarg :: Bool, getTm :: t,
732 | PConstraint { priority :: Int,
733 lazyarg :: Bool, getTm :: t,
735 | PTacImplicit { priority :: Int,
736 lazyarg :: Bool, pname :: Name,
740 deriving (Show, Eq, Functor)
742instance Sized a => Sized (PArg' a) where
743 size (PImp p _ l nm trm _) = 1 + size nm + size trm
744 size (PExp p l trm _) = 1 + size trm
745 size (PConstraint p l trm _) = 1 + size trm
746 size (PTacImplicit p l nm scr trm _) = 1 + size nm + size scr + size trm
749deriving instance Binary PArg'
750deriving instance NFData PArg'
753pimp n t mach = PImp 1 mach True n t ""
754pexp t = PExp 1 False t ""
755pconst t = PConstraint 1 False t ""
756ptacimp n s t = PTacImplicit 2 True n s t ""
758type PArg = PArg' PTerm
762data ClassInfo = CI { instanceName :: Name,
763 class_methods :: [(Name, (FnOpts, PTerm))],
764 class_defaults :: [(Name, (Name, PDecl))], -- method name -> default impl
765 class_default_superclasses :: [PDecl],
766 class_params :: [Name],
767 class_instances :: [Name] }
770deriving instance Binary ClassInfo
771deriving instance NFData ClassInfo
774-- An argument is conditionally forceable iff its forceability
775-- depends on the collapsibility of the whole type.
776data Forceability = Conditional | Unconditional deriving (Show, Enum, Bounded, Eq, Ord)
779deriving instance Binary Forceability
780deriving instance NFData Forceability
783data OptInfo = Optimise { collapsible :: Bool,
785 -- The following should actually be (IntMap Forceability)
786 -- but the corresponding Binary instance seems to be broken.
787 -- Let's store a list and convert it to IntMap whenever needed.
788 forceable :: [(Int, Forceability)],
792deriving instance Binary OptInfo
793deriving instance NFData OptInfo
797data TypeInfo = TI { con_names :: [Name],
802deriving instance Binary TypeInfo
803deriving instance NFData TypeInfo
806-- Syntactic sugar info
808data DSL' t = DSL { dsl_bind :: t,
813 index_first :: Maybe t,
814 index_next :: Maybe t,
815 dsl_lambda :: Maybe t,
818 deriving (Show, Functor)
820deriving instance Binary DSL'
821deriving instance NFData DSL'
826data SynContext = PatternSyntax | TermSyntax | AnySyntax
829deriving instance Binary SynContext
830deriving instance NFData SynContext
833data Syntax = Rule [SSymbol] PTerm SynContext
836deriving instance Binary Syntax
837deriving instance NFData Syntax
840data SSymbol = Keyword Name
847deriving instance Binary SSymbol
848deriving instance NFData SSymbol
851initDSL = DSL (PRef f (sUN ">>="))
852 (PRef f (sUN "return"))
854 (PRef f (sUN "pure"))
860 where f = fileFC "(builtin)"
862data Using = UImplicit Name PTerm
863 | UConstraint Name [Name]
866deriving instance Binary Using
867deriving instance NFData Using
870data SyntaxInfo = Syn { using :: [Using],
871 syn_params :: [(Name, PTerm)],
872 syn_namespace :: [String],
874 decoration :: Name -> Name,
876 implicitAllowed :: Bool,
880deriving instance NFData SyntaxInfo
881deriving instance Binary SyntaxInfo
884defaultSyntax = Syn [] [] [] [] id False False initDSL
886expandNS :: SyntaxInfo -> Name -> Name
887expandNS syn n@(NS _ _) = n
888expandNS syn n = case syn_namespace syn of
893--- Pretty printing declarations and terms
895instance Show PTerm where
896 show tm = showImp Nothing False False tm
898instance Pretty PTerm where
899 pretty = prettyImp False
901instance Show PDecl where
902 show d = showDeclImp False d
904instance Show PClause where
905 show c = showCImp True c
907instance Show PData where
908 show d = showDImp False d
910showDecls :: Bool -> [PDecl] -> String
912showDecls i (d:ds) = showDeclImp i d ++ "\n" ++ showDecls i ds
914showDeclImp _ (PFix _ f ops) = show f ++ " " ++ showSep ", " ops
915showDeclImp i (PTy _ _ _ _ n t) = "tydecl " ++ showCG n ++ " : " ++ showImp Nothing i False t
916showDeclImp i (PClauses _ _ n cs) = "pat " ++ showCG n ++ "\t" ++ showSep "\n\t" (map (showCImp i) cs)
917showDeclImp _ (PData _ _ _ _ d) = showDImp True d
918showDeclImp i (PParams _ ns ps) = "params {" ++ show ns ++ "\n" ++ showDecls i ps ++ "}\n"
919showDeclImp i (PNamespace n ps) = "namespace {" ++ n ++ "\n" ++ showDecls i ps ++ "}\n"
920showDeclImp _ (PSyntax _ syn) = "syntax " ++ show syn
921showDeclImp i (PClass _ _ _ cs n ps ds)
922 = "class " ++ show cs ++ " " ++ show n ++ " " ++ show ps ++ "\n" ++ showDecls i ds
923showDeclImp i (PInstance _ _ cs n _ t _ ds)
924 = "instance " ++ show cs ++ " " ++ show n ++ " " ++ show t ++ "\n" ++ showDecls i ds
925showDeclImp _ _ = "..."
926-- showDeclImp (PImport i) = "import " ++ i
929showCImp :: Bool -> PClause -> String
930showCImp impl (PClause _ n l ws r w)
931 = showImp Nothing impl False l ++ showWs ws ++ " = " ++ showImp Nothing impl False r
932 ++ " where " ++ show w
935 showWs (x : xs) = " | " ++ showImp Nothing impl False x ++ showWs xs
936showCImp impl (PWith _ n l ws r w)
937 = showImp Nothing impl False l ++ showWs ws ++ " with " ++ showImp Nothing impl False r
938 ++ " { " ++ show w ++ " } "
941 showWs (x : xs) = " | " ++ showImp Nothing impl False x ++ showWs xs
944showDImp :: Bool -> PData -> String
945showDImp impl (PDatadecl n ty cons)
946 = "data " ++ show n ++ " : " ++ showImp Nothing impl False ty ++ " where\n\t"
948 (map (\ (_, n, t, _, _) -> show n ++ " : " ++ showImp Nothing impl False t) cons)
950getImps :: [PArg] -> [(Name, PTerm)]
952getImps (PImp _ _ _ n tm _ : xs) = (n, tm) : getImps xs
953getImps (_ : xs) = getImps xs
955getExps :: [PArg] -> [PTerm]
957getExps (PExp _ _ tm _ : xs) = tm : getExps xs
958getExps (_ : xs) = getExps xs
960getConsts :: [PArg] -> [PTerm]
962getConsts (PConstraint _ _ tm _ : xs) = tm : getConsts xs
963getConsts (_ : xs) = getConsts xs
965getAll :: [PArg] -> [PTerm]
968-- | Pretty-print a high-level Idris term
969prettyImp :: Bool -- ^^ whether to show implicits
970 -> PTerm -- ^^ the term to pretty-print
972prettyImp impl = prettySe 10
974 prettySe p (PQuote r) =
975 if size r > breakingSize then
976 text "![" $$ pretty r <> text "]"
978 text "![" <> pretty r <> text "]"
979 prettySe p (PPatvar fc n) = pretty n
980 prettySe p (PRef fc n) =
986 prettyBasic n@(UN _) = pretty n
987 prettyBasic (MN _ s) = text (str s)
988 prettyBasic (NS n s) = (foldr (<>) empty (intersperse (text ".") (map (text.str) $ reverse s))) <> prettyBasic n
989 prettyBasic (SN sn) = text (show sn)
990 prettySe p (PLam n ty sc) =
992 if size sc > breakingSize then
993 text "λ" <> pretty n <+> text "=>" $+$ pretty sc
995 text "λ" <> pretty n <+> text "=>" <+> pretty sc
996 prettySe p (PLet n ty v sc) =
998 if size sc > breakingSize then
999 text "let" <+> pretty n <+> text "=" <+> prettySe 10 v <+> text "in" $+$
1000 nest nestingSize (prettySe 10 sc)
1002 text "let" <+> pretty n <+> text "=" <+> prettySe 10 v <+> text "in" <+>
1004 prettySe p (PPi (Exp l s _ _) n ty sc)
1005 | n `elem` allNamesIn sc || impl =
1006 let open = if l then text "|" <> lparen else lparen in
1008 if size sc > breakingSize then
1009 open <> pretty n <+> colon <+> prettySe 10 ty <> rparen <+>
1010 st <+> text "->" $+$ prettySe 10 sc
1012 open <> pretty n <+> colon <+> prettySe 10 ty <> rparen <+>
1013 st <+> text "->" <+> prettySe 10 sc
1016 if size sc > breakingSize then
1017 prettySe 0 ty <+> st <+> text "->" $+$ prettySe 10 sc
1019 prettySe 0 ty <+> st <+> text "->" <+> prettySe 10 sc
1023 Static -> text "[static]"
1025 prettySe p (PPi (Imp l s _ _) n ty sc)
1027 let open = if l then text "|" <> lbrace else lbrace in
1029 if size sc > breakingSize then
1030 open <> pretty n <+> colon <+> prettySe 10 ty <> rbrace <+>
1031 st <+> text "->" <+> prettySe 10 sc
1033 open <> pretty n <+> colon <+> prettySe 10 ty <> rbrace <+>
1034 st <+> text "->" <+> prettySe 10 sc
1035 | otherwise = prettySe 10 sc
1039 Static -> text $ "[static]"
1041 prettySe p (PPi (Constraint _ _ _) n ty sc) =
1043 if size sc > breakingSize then
1044 prettySe 10 ty <+> text "=>" <+> prettySe 10 sc
1046 prettySe 10 ty <+> text "=>" $+$ prettySe 10 sc
1047 prettySe p (PPi (TacImp _ _ s _) n ty sc) =
1049 if size sc > breakingSize then
1050 lbrace <> text "tacimp" <+> pretty n <+> colon <+> prettySe 10 ty <>
1051 rbrace <+> text "->" $+$ prettySe 10 sc
1053 lbrace <> text "tacimp" <+> pretty n <+> colon <+> prettySe 10 ty <>
1054 rbrace <+> text "->" <+> prettySe 10 sc
1055 prettySe p (PApp _ (PRef _ f) [])
1056 | not impl = pretty f
1057 prettySe p (PAppBind _ (PRef _ f) [])
1058 | not impl = text "!" <+> pretty f
1059 prettySe p (PApp _ (PRef _ op@(UN nm)) args)
1061 length (getExps args) == 2 && (not impl) && (not $ isAlpha (thead nm)) =
1062 let [l, r] = getExps args in
1064 if size r > breakingSize then
1065 prettySe 1 l <+> pretty op $+$ prettySe 0 r
1067 prettySe 1 l <+> pretty op <+> prettySe 0 r
1068 prettySe p (PApp _ f as) =
1069 let args = getExps as in
1074 -- foldr (<+>) empty $ map prettyArgS as
1076 foldl' fSe empty args
1077 -- foldr (<+>) empty $ map prettyArgSe args
1080 if size r > breakingSize then
1081 l $+$ nest nestingSize (prettyArgS r)
1086 if size r > breakingSize then
1087 l $+$ nest nestingSize (prettyArgSe r)
1090 prettySe p (PCase _ scr opts) =
1091 text "case" <+> prettySe 10 scr <+> text "of" $+$ nest nestingSize prettyBody
1093 prettyBody = foldr ($$) empty $ intersperse (text "|") $ map sc opts
1095 sc (l, r) = prettySe 10 l <+> text "=>" <+> prettySe 10 r
1096 prettySe p (PHidden tm) = text "." <> prettySe 0 tm
1097 prettySe p (PRefl _ _) = text "refl"
1098 prettySe p (PResolveTC _) = text "resolvetc"
1099 prettySe p (PTrue _) = text "()"
1100 prettySe p (PFalse _) = text "_|_"
1101 prettySe p (PEq _ l r) =
1103 if size r > breakingSize then
1104 prettySe 10 l <+> text "=" $$ nest nestingSize (prettySe 10 r)
1106 prettySe 10 l <+> text "=" <+> prettySe 10 r
1107 prettySe p (PRewrite _ l r _) =
1109 if size r > breakingSize then
1110 text "rewrite" <+> prettySe 10 l <+> text "in" $$ nest nestingSize (prettySe 10 r)
1112 text "rewrite" <+> prettySe 10 l <+> text "in" <+> prettySe 10 r
1113 prettySe p (PTyped l r) =
1114 lparen <> prettySe 10 l <+> colon <+> prettySe 10 r <> rparen
1115 prettySe p (PPair _ l r) =
1116 if size r > breakingSize then
1117 lparen <> prettySe 10 l <> text "," $+$
1118 prettySe 10 r <> rparen
1120 lparen <> prettySe 10 l <> text "," <+> prettySe 10 r <> rparen
1121 prettySe p (PDPair _ l t r) =
1122 if size r > breakingSize then
1123 lparen <> prettySe 10 l <+> text "**" $+$
1124 prettySe 10 r <> rparen
1126 lparen <> prettySe 10 l <+> text "**" <+> prettySe 10 r <> rparen
1127 prettySe p (PAlternative a as) =
1128 lparen <> text "|" <> prettyAs <> text "|" <> rparen
1131 foldr (\l -> \r -> l <+> text "," <+> r) empty $ map (prettySe 10) as
1132 prettySe p PType = text "Type"
1133 prettySe p (PConstant c) = pretty c
1134 -- XXX: add pretty for tactics
1135 prettySe p (PProof ts) =
1136 text "proof" <+> lbrace $+$ nest nestingSize (text . show $ ts) $+$ rbrace
1137 prettySe p (PTactics ts) =
1138 text "tactics" <+> lbrace $+$ nest nestingSize (text . show $ ts) $+$ rbrace
1139 prettySe p (PMetavar n) = text "?" <> pretty n
1140 prettySe p (PReturn f) = text "return"
1141 prettySe p PImpossible = text "impossible"
1142 prettySe p Placeholder = text "_"
1143 prettySe p (PDoBlock _) = text "do block pretty not implemented"
1144 prettySe p (PElabError s) = pretty s
1146 prettySe p _ = text "test"
1148 prettyArgS (PImp _ _ _ n tm _) = prettyArgSi (n, tm)
1149 prettyArgS (PExp _ _ tm _) = prettyArgSe tm
1150 prettyArgS (PConstraint _ _ tm _) = prettyArgSc tm
1151 prettyArgS (PTacImplicit _ _ n _ tm _) = prettyArgSti (n, tm)
1153 prettyArgSe arg = prettySe 0 arg
1154 prettyArgSi (n, val) = lbrace <> pretty n <+> text "=" <+> prettySe 10 val <> rbrace
1155 prettyArgSc val = lbrace <> lbrace <> prettySe 10 val <> rbrace <> rbrace
1156 prettyArgSti (n, val) = lbrace <> text "auto" <+> pretty n <+> text "=" <+> prettySe 10 val <> rbrace
1158 bracket outer inner doc
1159 | inner > outer = lparen <> doc <> rparen
1163showName :: Maybe IState -- ^^ the Idris state, for information about names and colours
1164 -> [(Name, Bool)] -- ^^ the bound variables and whether they're implicit
1165 -> Bool -- ^^ whether to show implicits
1166 -> Bool -- ^^ whether to colourise
1167 -> Name -- ^^ the term to show
1169showName ist bnd impl colour n = case ist of
1170 Just i -> if colour then colourise n (idris_colourTheme i) else showbasic n
1171 Nothing -> showbasic n
1172 where name = if impl then show n else showbasic n
1173 showbasic n@(UN _) = showCG n
1174 showbasic (MN _ s) = str s
1175 showbasic (NS n s) = showSep "." (map str (reverse s)) ++ "." ++ showbasic n
1176 showbasic (SN s) = show s
1178 colourise n t = let ctxt' = fmap tt_ctxt ist in
1181 Just ctxt | Just impl <- lookup n bnd -> if impl then colouriseImplicit t name
1182 else colouriseBound t name
1183 | isDConName n ctxt -> colouriseData t name
1184 | isFnName n ctxt -> colouriseFun t name
1185 | isTConName n ctxt -> colouriseType t name
1186 -- The assumption is that if a name is not bound and does not exist in the
1187 -- global context, then we're somewhere in which implicit info has been lost
1188 -- (like error messages). Thus, unknown vars are colourised as implicits.
1189 | otherwise -> colouriseImplicit t name
1192showImp :: Maybe IState -- ^^ the Idris state, for information about identifiers and colours
1193 -> Bool -- ^^ whether to show implicits
1194 -> Bool -- ^^ whether to colourise
1195 -> PTerm -- ^^ the term to show
1197showImp ist impl colour tm = se 10 [] tm where
1198 perhapsColourise :: (ColourTheme -> String -> String) -> String -> String
1199 perhapsColourise col str = case ist of
1200 Just i -> if colour then col (idris_colourTheme i) str else str
1203 se :: Int -> [(Name, Bool)] -> PTerm -> String
1204 se p bnd (PQuote r) = "![" ++ show r ++ "]"
1205 se p bnd (PPatvar fc n) = if impl then show n ++ "[p]" else show n
1206 se p bnd (PInferRef fc n) = "!" ++ show n -- ++ "[" ++ show fc ++ "]"
1208 | Just str <- slist p bnd e = str
1209 | Just num <- snat p e = perhapsColourise colouriseData (show num)
1210 se p bnd (PRef fc n) = showName ist bnd impl colour n
1211 se p bnd (PLam n ty sc) = bracket p 2 $ "\\ " ++ perhapsColourise colouriseBound (show n) ++
1212 (if impl then " : " ++ se 10 bnd ty else "") ++ " => "
1213 ++ se 10 ((n, False):bnd) sc
1214 se p bnd (PLet n ty v sc) = bracket p 2 $ "let " ++ perhapsColourise colouriseBound (show n) ++
1215 " = " ++ se 10 bnd v ++
1216 " in " ++ se 10 ((n, False):bnd) sc
1217 se p bnd (PPi (Exp l s _ param) n ty sc)
1218 | n `elem` allNamesIn sc || impl
1220 (if l then "|(" else "(") ++
1221 perhapsColourise colouriseBound (show n) ++ " : " ++ se 10 bnd ty ++
1223 (if (impl && param) then "P" else "") ++
1225 "-> " ++ se 10 ((n, False):bnd) sc
1226 | otherwise = bracket p 2 $ se 0 bnd ty ++ " " ++ st ++ "-> " ++ se 10 bnd sc
1227 where st = case s of
1228 Static -> "[static] "
1230 se p bnd (PPi (Imp l s _ _) n ty sc)
1231 | impl = bracket p 2 $ (if l then "|{" else "{") ++
1232 perhapsColourise colouriseBound (show n) ++ " : " ++ se 10 bnd ty ++
1233 "} " ++ st ++ "-> " ++ se 10 ((n, True):bnd) sc
1234 | otherwise = se 10 ((n, True):bnd) sc
1235 where st = case s of
1236 Static -> "[static] "
1238 se p bnd (PPi (Constraint _ _ _) n ty sc)
1239 = bracket p 2 $ se 10 bnd ty ++ " => " ++ se 10 bnd sc
1240 se p bnd (PPi (TacImp _ _ s _) n ty sc)
1242 "{tacimp " ++ (perhapsColourise colouriseBound (show n)) ++ " : " ++ se 10 bnd ty ++ "} -> " ++
1243 se 10 ((n, False):bnd) sc
1244 se p bnd (PMatchApp _ f) = "match " ++ show f
1245 se p bnd (PApp _ hd@(PRef _ f) [])
1246 | not impl = se p bnd hd
1247 se p bnd (PAppBind _ hd@(PRef _ f) [])
1248 | not impl = "!" ++ se p bnd hd
1249 se p bnd (PApp _ op@(PRef _ (UN nm)) args)
1251 length (getExps args) == 2 && not impl && not (isAlpha (thead nm))
1252 = let [l, r] = getExps args in
1253 bracket p 1 $ se 1 bnd l ++ " " ++ se p bnd op ++ " " ++ se 0 bnd r
1254 se p bnd (PApp _ f as)
1255 = -- let args = getExps as in
1256 bracket p 1 $ se 1 bnd f ++
1257 if impl then concatMap (sArg bnd) as
1258 else concatMap (suiArg impl bnd) as
1259 se p bnd (PAppBind _ f as)
1260 = let args = getExps as in
1261 "!" ++ (bracket p 1 $ se 1 bnd f ++ if impl then concatMap (sArg bnd) as
1262 else concatMap (seArg bnd) args)
1263 se p bnd (PCase _ scr opts) = "case " ++ se 10 bnd scr ++ " of " ++ showSep " | " (map sc opts)
1264 where sc (l, r) = se 10 bnd l ++ " => " ++ se 10 bnd r
1265 se p bnd (PHidden tm) = "." ++ se 0 bnd tm
1266 se p bnd (PRefl _ t)
1267 | not impl = perhapsColourise colouriseData "refl"
1268 | otherwise = perhapsColourise colouriseData $ "refl {" ++ se 10 bnd t ++ "}"
1269 se p bnd (PResolveTC _) = "resolvetc"
1270 se p bnd (PTrue _) = perhapsColourise colouriseType "()"
1271 se p bnd (PFalse _) = perhapsColourise colouriseType "_|_"
1272 se p bnd (PEq _ l r) = bracket p 2 $ se 10 bnd l ++ perhapsColourise colouriseType " = " ++ se 10 bnd r
1273 se p bnd (PRewrite _ l r _) = bracket p 2 $ "rewrite " ++ se 10 bnd l ++ " in " ++ se 10 bnd r
1274 se p bnd (PTyped l r) = "(" ++ se 10 bnd l ++ " : " ++ se 10 bnd r ++ ")"
1275 se p bnd (PPair _ l r) = "(" ++ se 10 bnd l ++ ", " ++ se 10 bnd r ++ ")"
1276 se p bnd (PDPair _ l t r) = "(" ++ se 10 bnd l ++ " ** " ++ se 10 bnd r ++ ")"
1277 se p bnd (PAlternative a as) = "(|" ++ showSep " , " (map (se 10 bnd) as) ++ "|)"
1278 se p bnd PType = perhapsColourise colouriseType "Type"
1279 se p bnd (PConstant c) = perhapsColourise (cfun c) (show c)
1280 where cfun (AType _) = colouriseType
1281 cfun StrType = colouriseType
1282 cfun PtrType = colouriseType
1283 cfun VoidType = colouriseType
1284 cfun _ = colouriseData
1285 se p bnd (PProof ts) = "proof { " ++ show ts ++ "}"
1286 se p bnd (PTactics ts) = "tactics { " ++ show ts ++ "}"
1287 se p bnd (PMetavar n) = "?" ++ show n
1288 se p bnd (PReturn f) = "return"
1289 se p bnd PImpossible = "impossible"
1290 se p bnd Placeholder = "_"
1291 se p bnd (PDoBlock _) = "do block show not implemented"
1292 se p bnd (PElabError s) = show s
1293 se p bnd (PCoerced t) = se p bnd t
1294 se p bnd (PUnifyLog t) = "%unifyLog " ++ se p bnd t
1295 se p bnd (PDisamb ns t) = "%disamb " ++ show ns ++ se p bnd t
1296 se p bnd (PNoImplicits t) = "%noimplicit " ++ se p bnd t
1297-- se p bnd x = "Not implemented"
1299 slist' p bnd (PApp _ (PRef _ nil) _)
1300 | not impl && nsroot nil == sUN "Nil" = Just []
1301 slist' p bnd (PApp _ (PRef _ cons) args)
1302 | nsroot cons == sUN "::",
1303 (PExp {getTm=tl}):(PExp {getTm=hd}):imps <- reverse args,
1305 Just tl' <- slist' p bnd tl
1308 isImp (PImp {}) = True
1310 slist' _ _ _ = Nothing
1312 slist p bnd e | Just es <- slist' p bnd e = Just $
1313 case es of [] -> "[]"
1314 [x] -> "[" ++ se p bnd x ++ "]"
1315 xs -> "[" ++ intercalate "," (map (se p bnd ) xs) ++ "]"
1316 slist _ _ _ = Nothing
1318 -- since Prelude is always imported, S & Z are unqualified iff they're the
1321 | show o == (natns++"Z") || show o == "Z" = Just 0
1322 snat p (PApp _ s [PExp {getTm=n}])
1323 | show s == (natns++"S") || show s == "S",
1328 natns = "Prelude.Nat."
1330 sArg bnd (PImp _ _ _ n tm _) = siArg bnd (n, tm)
1331 sArg bnd (PExp _ _ tm _) = seArg bnd tm
1332 sArg bnd (PConstraint _ _ tm _) = scArg bnd tm
1333 sArg bnd (PTacImplicit _ _ n _ tm _) = stiArg bnd (n, tm)
1335 -- show argument, implicits given by the user also shown
1336 suiArg impl bnd (PImp _ mi _ n tm _)
1337 | impl || not mi = siArg bnd (n, tm)
1338 suiArg impl bnd (PExp _ _ tm _) = seArg bnd tm
1339 suiArg impl bnd _ = ""
1341 seArg bnd arg = " " ++ se 0 bnd arg
1342 siArg bnd (n, val) =
1344 val' = se 10 bnd val in
1346 then " {" ++ n' ++ "}"
1347 else " {" ++ n' ++ " = " ++ val' ++ "}"
1348 scArg bnd val = " {{" ++ se 10 bnd val ++ "}}"
1349 stiArg bnd (n, val) = " {auto " ++ show n ++ " = " ++ se 10 bnd val ++ "}"
1351 bracket outer inner str | inner > outer = "(" ++ str ++ ")"
1355instance Sized PTerm where
1356 size (PQuote rawTerm) = size rawTerm
1357 size (PRef fc name) = size name
1358 size (PLam name ty bdy) = 1 + size ty + size bdy
1359 size (PPi plicity name ty bdy) = 1 + size ty + size bdy
1360 size (PLet name ty def bdy) = 1 + size ty + size def + size bdy
1361 size (PTyped trm ty) = 1 + size trm + size ty
1362 size (PApp fc name args) = 1 + size args
1363 size (PAppBind fc name args) = 1 + size args
1364 size (PCase fc trm bdy) = 1 + size trm + size bdy
1366 size (PFalse fc) = 1
1367 size (PRefl fc _) = 1
1368 size (PResolveTC fc) = 1
1369 size (PEq fc left right) = 1 + size left + size right
1370 size (PRewrite fc left right _) = 1 + size left + size right
1371 size (PPair fc left right) = 1 + size left + size right
1372 size (PDPair fs left ty right) = 1 + size left + size ty + size right
1373 size (PAlternative a alts) = 1 + size alts
1374 size (PHidden hidden) = size hidden
1375 size (PUnifyLog tm) = size tm
1376 size (PDisamb _ tm) = size tm
1377 size (PNoImplicits tm) = size tm
1379 size (PConstant const) = 1 + size const
1380 size Placeholder = 1
1381 size (PDoBlock dos) = 1 + size dos
1382 size (PIdiom fc term) = 1 + size term
1383 size (PReturn fc) = 1
1384 size (PMetavar name) = 1
1385 size (PProof tactics) = size tactics
1386 size (PElabError err) = size err
1387 size PImpossible = 1
1389getPArity :: PTerm -> Int
1390getPArity (PPi _ _ _ sc) = 1 + getPArity sc
1393-- Return all names, free or globally bound, in the given term.
1395allNamesIn :: PTerm -> [Name]
1396allNamesIn tm = nub $ ni [] tm
1399 | not (n `elem` env) = [n]
1400 ni env (PPatvar _ n) = [n]
1401 ni env (PApp _ f as) = ni env f ++ concatMap (ni env) (map getTm as)
1402 ni env (PAppBind _ f as) = ni env f ++ concatMap (ni env) (map getTm as)
1403 ni env (PCase _ c os) = ni env c ++ concatMap (ni env) (map snd os)
1404 ni env (PLam n ty sc) = ni env ty ++ ni (n:env) sc
1405 ni env (PPi _ n ty sc) = ni env ty ++ ni (n:env) sc
1406 ni env (PHidden tm) = ni env tm
1407 ni env (PEq _ l r) = ni env l ++ ni env r
1408 ni env (PRewrite _ l r _) = ni env l ++ ni env r
1409 ni env (PTyped l r) = ni env l ++ ni env r
1410 ni env (PPair _ l r) = ni env l ++ ni env r
1411 ni env (PDPair _ (PRef _ n) t r) = ni env t ++ ni (n:env) r
1412 ni env (PDPair _ l t r) = ni env l ++ ni env t ++ ni env r
1413 ni env (PAlternative a ls) = concatMap (ni env) ls
1414 ni env (PUnifyLog tm) = ni env tm
1415 ni env (PDisamb _ tm) = ni env tm
1416 ni env (PNoImplicits tm) = ni env tm
1419-- Return all names defined in binders in the given term
1420boundNamesIn :: PTerm -> [Name]
1421boundNamesIn tm = nub $ ni tm
1423 ni (PApp _ f as) = ni f ++ concatMap (ni) (map getTm as)
1424 ni (PAppBind _ f as) = ni f ++ concatMap (ni) (map getTm as)
1425 ni (PCase _ c os) = ni c ++ concatMap (ni) (map snd os)
1426 ni (PLam n ty sc) = n : (ni ty ++ ni sc)
1427 ni (PLet n ty val sc) = n : (ni ty ++ ni val ++ ni sc)
1428 ni (PPi _ n ty sc) = n : (ni ty ++ ni sc)
1429 ni (PEq _ l r) = ni l ++ ni r
1430 ni (PRewrite _ l r _) = ni l ++ ni r
1431 ni (PTyped l r) = ni l ++ ni r
1432 ni (PPair _ l r) = ni l ++ ni r
1433 ni (PDPair _ (PRef _ n) t r) = ni t ++ ni r
1434 ni (PDPair _ l t r) = ni l ++ ni t ++ ni r
1435 ni (PAlternative a as) = concatMap (ni) as
1436 ni (PHidden tm) = ni tm
1437 ni (PUnifyLog tm) = ni tm
1438 ni (PDisamb _ tm) = ni tm
1439 ni (PNoImplicits tm) = ni tm
1442-- Return names which are free in the given term.
1443namesIn :: [(Name, PTerm)] -> IState -> PTerm -> [Name]
1444namesIn uvars ist tm = nub $ ni [] tm
1447 | not (n `elem` env)
1448 = case lookupTy n (tt_ctxt ist) of
1450 _ -> if n `elem` (map fst uvars) then [n] else []
1451 ni env (PApp _ f as) = ni env f ++ concatMap (ni env) (map getTm as)
1452 ni env (PAppBind _ f as) = ni env f ++ concatMap (ni env) (map getTm as)
1453 ni env (PCase _ c os) = ni env c ++ concatMap (ni env) (map snd os)
1454 ni env (PLam n ty sc) = ni env ty ++ ni (n:env) sc
1455 ni env (PPi _ n ty sc) = ni env ty ++ ni (n:env) sc
1456 ni env (PEq _ l r) = ni env l ++ ni env r
1457 ni env (PRewrite _ l r _) = ni env l ++ ni env r
1458 ni env (PTyped l r) = ni env l ++ ni env r
1459 ni env (PPair _ l r) = ni env l ++ ni env r
1460 ni env (PDPair _ (PRef _ n) t r) = ni env t ++ ni (n:env) r
1461 ni env (PDPair _ l t r) = ni env l ++ ni env t ++ ni env r
1462 ni env (PAlternative a as) = concatMap (ni env) as
1463 ni env (PHidden tm) = ni env tm
1464 ni env (PUnifyLog tm) = ni env tm
1465 ni env (PDisamb _ tm) = ni env tm
1466 ni env (PNoImplicits tm) = ni env tm
1469-- Return which of the given names are used in the given term.
1471usedNamesIn :: [Name] -> IState -> PTerm -> [Name]
1472usedNamesIn vars ist tm = nub $ ni [] tm
1475 | n `elem` vars && not (n `elem` env)
1476 = case lookupTy n (tt_ctxt ist) of
1479 ni env (PApp _ f as) = ni env f ++ concatMap (ni env) (map getTm as)
1480 ni env (PAppBind _ f as) = ni env f ++ concatMap (ni env) (map getTm as)
1481 ni env (PCase _ c os) = ni env c ++ concatMap (ni env) (map snd os)
1482 ni env (PLam n ty sc) = ni env ty ++ ni (n:env) sc
1483 ni env (PPi _ n ty sc) = ni env ty ++ ni (n:env) sc
1484 ni env (PEq _ l r) = ni env l ++ ni env r
1485 ni env (PRewrite _ l r _) = ni env l ++ ni env r
1486 ni env (PTyped l r) = ni env l ++ ni env r
1487 ni env (PPair _ l r) = ni env l ++ ni env r
1488 ni env (PDPair _ (PRef _ n) t r) = ni env t ++ ni (n:env) r
1489 ni env (PDPair _ l t r) = ni env l ++ ni env t ++ ni env r
1490 ni env (PAlternative a as) = concatMap (ni env) as
1491 ni env (PHidden tm) = ni env tm
1492 ni env (PUnifyLog tm) = ni env tm
1493 ni env (PDisamb _ tm) = ni env tm
1494 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