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
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 | IBCMetaInformation Name MetaInformation
182 | IBCTotal Name Totality
183 | IBCFlags Name [FnOpt]
184 | IBCTrans (Term, Term)
188 | IBCDef Name -- i.e. main context
189 | IBCNameHint (Name, Name)
190 | IBCLineApp FilePath Int PTerm
193-- | The initial state for the compiler
195idrisInit = IState initContext [] [] emptyContext emptyContext emptyContext
196 emptyContext emptyContext emptyContext emptyContext
197 emptyContext emptyContext emptyContext emptyContext
199 [] [] defaultOpts 6 [] [] [] [] [] [] [] [] [] [] [] []
200 [] Nothing Nothing [] [] [] Hidden False [] Nothing [] [] RawOutput
201 True defaultTheme stdout []
203-- | The monad for the main REPL - reading and processing files and updating
204-- global state (hence the IO inner monad).
205--type Idris = WriterT [Either String (IO ())] (State IState a))
206type Idris = StateT IState (ErrorT Err IO)
208-- Commands in the REPL
227 | ChangeDirectory FilePath
230 | Compile Codegen String
235 | AddProof (Maybe Name)
247 | DynamicLink FilePath
252 | CaseSplitAt Bool Int Name
253 | AddClauseFrom Bool Int Name
254 | AddProofClauseFrom Bool Int Name
255 | AddMissing Bool Int Name
256 | MakeWith Bool Int Name
257 | DoProofSearch Bool Int Name [Name]
261 | SetColour ColourType IdrisColour
266data Opt = Filename String
278 | NoBuiltins -- only for the really primitive stuff!
302 | OutputTy OutputType
303 | Extension LanguageExt
304 | InterpretScript String
305 | TargetTriple String
311-- Parsed declarations
313data Fixity = Infixl { prec :: Int }
314 | Infixr { prec :: Int }
315 | InfixN { prec :: Int }
316 | PrefixN { prec :: Int }
319deriving instance Binary Fixity
320deriving instance NFData Fixity
323instance Show Fixity where
324 show (Infixl i) = "infixl " ++ show i
325 show (Infixr i) = "infixr " ++ show i
326 show (InfixN i) = "infix " ++ show i
327 show (PrefixN i) = "prefix " ++ show i
329data FixDecl = Fix Fixity String
332instance Show FixDecl where
333 show (Fix f s) = show f ++ " " ++ s
336deriving instance Binary FixDecl
337deriving instance NFData FixDecl
340instance Ord FixDecl where
341 compare (Fix x _) (Fix y _) = compare (prec x) (prec y)
344data Static = Static | Dynamic
347deriving instance Binary Static
348deriving instance NFData Static
351-- Mark bindings with their explicitness, and laziness
352data Plicity = Imp { plazy :: Bool,
356 | Exp { plazy :: Bool,
360 | Constraint { plazy :: Bool,
363 | TacImp { plazy :: Bool,
370deriving instance Binary Plicity
371deriving instance NFData Plicity
374impl = Imp False Dynamic "" False
375expl = Exp False Dynamic "" False
376expl_param = Exp False Dynamic "" True
377constraint = Constraint False Dynamic ""
378tacimpl t = TacImp False Dynamic t ""
380data FnOpt = Inlinable -- always evaluate when simplifying
381 | TotalFn | PartialFn
382 | Coinductive | AssertTotal
383 | Dictionary -- type class dictionary, eval only when
384 -- a function argument, and further evaluation resutls
385 | Implicit -- implicit coercion
386 | CExport String -- export, with a C name
387 | ErrorHandler -- ^^ an error handler for use with the ErrorReflection extension
388 | Reflection -- a reflecting function, compile-time only
389 | Specialise [(Name, Maybe Int)] -- specialise it, freeze these names
392deriving instance Binary FnOpt
393deriving instance NFData FnOpt
398inlinable :: FnOpts -> Bool
399inlinable = elem Inlinable
401dictionary :: FnOpts -> Bool
402dictionary = elem Dictionary
405-- | Data declaration options
406data DataOpt = Codata -- Set if the the data-type is coinductive
407 | DefaultEliminator -- Set if an eliminator should be generated for data type
410type DataOpts = [DataOpt]
412-- | Top-level declarations such as compiler directives, definitions,
413-- datatypes and typeclasses.
415 = PFix FC Fixity [String] -- ^ Fixity declaration
416 | PTy String SyntaxInfo FC FnOpts Name t -- ^ Type declaration
417 | PPostulate String SyntaxInfo FC FnOpts Name t -- ^ Postulate
418 | PClauses FC FnOpts Name [PClause' t] -- ^ Pattern clause
419 | PCAF FC Name t -- ^ Top level constant
420 | PData String SyntaxInfo FC DataOpts (PData' t) -- ^ Data declaration.
421 | PParams FC [(Name, t)] [PDecl' t] -- ^ Params block
422 | PNamespace String [PDecl' t] -- ^ New namespace
423 | PRecord String SyntaxInfo FC Name t String Name t -- ^ Record declaration
424 | PClass String SyntaxInfo FC
427 [(Name, t)] -- parameters
428 [PDecl' t] -- declarations
429 -- ^ Type class: arguments are documentation, syntax info, source location, constraints,
430 -- class name, parameters, method declarations
431 | PInstance SyntaxInfo FC [t] -- constraints
434 t -- full instance type
435 (Maybe Name) -- explicit name
437 -- ^ Instance declaration: arguments are syntax info, source location, constraints,
438 -- class name, parameters, full instance type, optional explicit name, and definitions
439 | PDSL Name (DSL' t) -- ^ DSL declaration
440 | PSyntax FC Syntax -- ^ Syntax definition
441 | PMutual FC [PDecl' t] -- ^ Mutual block
442 | PDirective (Idris ()) -- ^ Compiler directive. The parser inserts the corresponding action in the Idris monad.
443 | PProvider SyntaxInfo FC Name t t -- ^ Type provider. The first t is the type, the second is the term
444 | PTransform FC Bool t t -- ^ Source-to-source transformation rule. If
445 -- bool is True, lhs and rhs must be convertible
448deriving instance Binary PDecl'
449deriving instance NFData PDecl'
452-- For elaborator state
453type ElabD a = Elab' [PDecl] a
455-- | One clause of a top-level definition. Term arguments to constructors are:
457-- 1. The whole application (missing for PClauseR and PWithR because they're within a "with" clause)
459-- 2. The list of extra 'with' patterns
461-- 3. The right-hand side
463-- 4. The where block (PDecl' t)
465data PClause' t = PClause FC Name t [t] t [PDecl' t] -- ^ A normal top-level definition.
466 | PWith FC Name t [t] t [PDecl' t]
467 | PClauseR FC [t] t [PDecl' t]
468 | PWithR FC [t] t [PDecl' t]
471deriving instance Binary PClause'
472deriving instance NFData PClause'
476data PData' t = PDatadecl { d_name :: Name, -- ^ The name of the datatype
477 d_tcon :: t, -- ^ Type constructor
478 d_cons :: [(String, Name, t, FC)] -- ^ Constructors
480 -- ^ Data declaration
481 | PLaterdecl { d_name :: Name, d_tcon :: t }
482 -- ^ "Placeholder" for data whose constructors are defined later
485deriving instance Binary PData'
486deriving instance NFData PData'
489-- Handy to get a free function for applying PTerm -> PTerm functions
490-- across a program, by deriving Functor
492type PDecl = PDecl' PTerm
493type PData = PData' PTerm
494type PClause = PClause' PTerm
496-- get all the names declared in a decl
498declared :: PDecl -> [Name]
499declared (PFix _ _ _) = []
500declared (PTy _ _ _ _ n t) = [n]
501declared (PPostulate _ _ _ _ n t) = [n]
502declared (PClauses _ _ n _) = [] -- not a declaration
503declared (PCAF _ n _) = [n]
504declared (PData _ _ _ _ (PDatadecl n _ ts)) = n : map fstt ts
505 where fstt (_, a, _, _) = a
506declared (PData _ _ _ _ (PLaterdecl n _)) = [n]
507declared (PParams _ _ ds) = concatMap declared ds
508declared (PNamespace _ ds) = concatMap declared ds
509declared (PRecord _ _ _ n _ _ c _) = [n, c]
510declared (PClass _ _ _ _ n _ ms) = n : concatMap declared ms
511declared (PInstance _ _ _ _ _ _ _ _) = []
512declared (PDSL n _) = [n]
513declared (PSyntax _ _) = []
514declared (PMutual _ ds) = concatMap declared ds
515declared (PDirective _) = []
517-- get the names declared, not counting nested parameter blocks
518tldeclared :: PDecl -> [Name]
519tldeclared (PFix _ _ _) = []
520tldeclared (PTy _ _ _ _ n t) = [n]
521tldeclared (PPostulate _ _ _ _ n t) = [n]
522tldeclared (PClauses _ _ n _) = [] -- not a declaration
523tldeclared (PRecord _ _ _ n _ _ c _) = [n, c]
524tldeclared (PData _ _ _ _ (PDatadecl n _ ts)) = n : map fstt ts
525 where fstt (_, a, _, _) = a
526tldeclared (PParams _ _ ds) = []
527tldeclared (PMutual _ ds) = concatMap tldeclared ds
528tldeclared (PNamespace _ ds) = concatMap tldeclared ds
529tldeclared (PClass _ _ _ _ n _ ms) = concatMap tldeclared ms
530tldeclared (PInstance _ _ _ _ _ _ _ _) = []
533defined :: PDecl -> [Name]
534defined (PFix _ _ _) = []
535defined (PTy _ _ _ _ n t) = []
536defined (PPostulate _ _ _ _ n t) = []
537defined (PClauses _ _ n _) = [n] -- not a declaration
538defined (PCAF _ n _) = [n]
539defined (PData _ _ _ _ (PDatadecl n _ ts)) = n : map fstt ts
540 where fstt (_, a, _, _) = a
541defined (PData _ _ _ _ (PLaterdecl n _)) = []
542defined (PParams _ _ ds) = concatMap defined ds
543defined (PNamespace _ ds) = concatMap defined ds
544defined (PRecord _ _ _ n _ _ c _) = [n, c]
545defined (PClass _ _ _ _ n _ ms) = n : concatMap defined ms
546defined (PInstance _ _ _ _ _ _ _ _) = []
547defined (PDSL n _) = [n]
548defined (PSyntax _ _) = []
549defined (PMutual _ ds) = concatMap defined ds
550defined (PDirective _) = []
553updateN :: [(Name, Name)] -> Name -> Name
554updateN ns n | Just n' <- lookup n ns = n'
557updateNs :: [(Name, Name)] -> PTerm -> PTerm
559updateNs ns t = mapPT updateRef t
560 where updateRef (PRef fc f) = PRef fc (updateN ns f)
563-- updateDNs :: [(Name, Name)] -> PDecl -> PDecl
565-- updateDNs ns (PTy s f n t) | Just n' <- lookup n ns = PTy s f n' t
566-- updateDNs ns (PClauses f n c) | Just n' <- lookup n ns = PClauses f n' (map updateCNs c)
567-- where updateCNs ns (PClause n l ts r ds)
568-- = PClause (updateN ns n) (fmap (updateNs ns) l)
569-- (map (fmap (updateNs ns)) ts)
570-- (fmap (updateNs ns) r)
571-- (map (updateDNs ns) ds)
574-- | High level language terms
575data PTerm = PQuote Raw
577 | PInferRef FC Name -- ^ A name to be defined later
579 | PLam Name PTerm PTerm
580 | PPi Plicity Name PTerm PTerm
581 | PLet Name PTerm PTerm PTerm
582 | PTyped PTerm PTerm -- ^ Term with explicit type
583 | PApp FC PTerm [PArg]
584 | PAppBind FC PTerm [PArg] -- ^ implicitly bound application
585 | PMatchApp FC Name -- ^ Make an application by type matching
586 | PCase FC PTerm [(PTerm, PTerm)]
592 | PRewrite FC PTerm PTerm (Maybe PTerm)
593 | PPair FC PTerm PTerm
594 | PDPair FC PTerm PTerm PTerm
595 | PAlternative Bool [PTerm] -- True if only one may work
596 | PHidden PTerm -- ^ Irrelevant or hidden pattern
598 | PGoal FC PTerm Name PTerm
605 | PProof [PTactic] -- ^ Proof script
606 | PTactics [PTactic] -- ^ As PProof, but no auto solving
607 | PElabError Err -- ^ Error to report on elaboration
608 | PImpossible -- ^ Special case for declaring when an LHS can't typecheck
609 | PCoerced PTerm -- ^ To mark a coerced argument, so as not to coerce twice
610 | PUnifyLog PTerm -- ^ dump a trace of unifications when building term
611 | PNoImplicits PTerm -- ^ never run implicit converions on the term
616deriving instance Binary PTerm
617deriving instance NFData PTerm
620mapPT :: (PTerm -> PTerm) -> PTerm -> PTerm
621mapPT f t = f (mpt t) where
622 mpt (PLam n t s) = PLam n (mapPT f t) (mapPT f s)
623 mpt (PPi p n t s) = PPi p n (mapPT f t) (mapPT f s)
624 mpt (PLet n ty v s) = PLet n (mapPT f ty) (mapPT f v) (mapPT f s)
625 mpt (PRewrite fc t s g) = PRewrite fc (mapPT f t) (mapPT f s)
627 mpt (PApp fc t as) = PApp fc (mapPT f t) (map (fmap (mapPT f)) as)
628 mpt (PAppBind fc t as) = PAppBind fc (mapPT f t) (map (fmap (mapPT f)) as)
629 mpt (PCase fc c os) = PCase fc (mapPT f c) (map (pmap (mapPT f)) os)
630 mpt (PEq fc l r) = PEq fc (mapPT f l) (mapPT f r)
631 mpt (PTyped l r) = PTyped (mapPT f l) (mapPT f r)
632 mpt (PPair fc l r) = PPair fc (mapPT f l) (mapPT f r)
633 mpt (PDPair fc l t r) = PDPair fc (mapPT f l) (mapPT f t) (mapPT f r)
634 mpt (PAlternative a as) = PAlternative a (map (mapPT f) as)
635 mpt (PHidden t) = PHidden (mapPT f t)
636 mpt (PDoBlock ds) = PDoBlock (map (fmap (mapPT f)) ds)
637 mpt (PProof ts) = PProof (map (fmap (mapPT f)) ts)
638 mpt (PTactics ts) = PTactics (map (fmap (mapPT f)) ts)
639 mpt (PUnifyLog tm) = PUnifyLog (mapPT f tm)
640 mpt (PNoImplicits tm) = PNoImplicits (mapPT f tm)
641 mpt (PGoal fc r n sc) = PGoal fc (mapPT f r) n (mapPT f sc)
645data PTactic' t = Intro [Name] | Intros | Focus Name
646 | Refine Name [Bool] | Rewrite t
650 | LetTac Name t | LetTacTy Name t t
651 | Exact t | Compute | Trivial
652 | ProofSearch (Maybe Name) Name [Name]
655 | ProofState | ProofTerm | Undo
656 | Try (PTactic' t) (PTactic' t)
657 | TSeq (PTactic' t) (PTactic' t)
658 | ApplyTactic t -- see Language.Reflection module
662 | GoalType String (PTactic' t)
664 deriving (Show, Eq, Functor)
666deriving instance Binary PTactic'
667deriving instance NFData PTactic'
670instance Sized a => Sized (PTactic' a) where
671 size (Intro nms) = 1 + size nms
673 size (Focus nm) = 1 + size nm
674 size (Refine nm bs) = 1 + size nm + length bs
675 size (Rewrite t) = 1 + size t
676 size (Induction t) = 1 + size t
677 size (LetTac nm t) = 1 + size nm + size t
678 size (Exact t) = 1 + size t
686 size (Try l r) = 1 + size l + size r
687 size (TSeq l r) = 1 + size l + size r
688 size (ApplyTactic t) = 1 + size t
689 size (Reflect t) = 1 + size t
690 size (Fill t) = 1 + size t
694type PTactic = PTactic' PTerm
696data PDo' t = DoExp FC t
701 deriving (Eq, Functor)
703deriving instance Binary PDo'
704deriving instance NFData PDo'
707instance Sized a => Sized (PDo' a) where
708 size (DoExp fc t) = 1 + size fc + size t
709 size (DoBind fc nm t) = 1 + size fc + size nm + size t
710 size (DoBindP fc l r) = 1 + size fc + size l + size r
711 size (DoLet fc nm l r) = 1 + size fc + size nm + size l + size r
712 size (DoLetP fc l r) = 1 + size fc + size l + size r
716-- The priority gives a hint as to elaboration order. Best to elaborate
717-- things early which will help give a more concrete type to other
718-- variables, e.g. a before (interpTy a).
720data PArg' t = PImp { priority :: Int,
721 machine_inf :: Bool, -- true if the machine inferred it
722 lazyarg :: Bool, pname :: Name, getTm :: t,
724 | PExp { priority :: Int,
725 lazyarg :: Bool, getTm :: t,
727 | PConstraint { priority :: Int,
728 lazyarg :: Bool, getTm :: t,
730 | PTacImplicit { priority :: Int,
731 lazyarg :: Bool, pname :: Name,
735 deriving (Show, Eq, Functor)
737instance Sized a => Sized (PArg' a) where
738 size (PImp p _ l nm trm _) = 1 + size nm + size trm
739 size (PExp p l trm _) = 1 + size trm
740 size (PConstraint p l trm _) = 1 + size trm
741 size (PTacImplicit p l nm scr trm _) = 1 + size nm + size scr + size trm
744deriving instance Binary PArg'
745deriving instance NFData PArg'
748pimp n t mach = PImp 1 mach True n t ""
749pexp t = PExp 1 False t ""
750pconst t = PConstraint 1 False t ""
751ptacimp n s t = PTacImplicit 2 True n s t ""
753type PArg = PArg' PTerm
757data ClassInfo = CI { instanceName :: Name,
758 class_methods :: [(Name, (FnOpts, PTerm))],
759 class_defaults :: [(Name, (Name, PDecl))], -- method name -> default impl
760 class_default_superclasses :: [PDecl],
761 class_params :: [Name],
762 class_instances :: [Name] }
765deriving instance Binary ClassInfo
766deriving instance NFData ClassInfo
769-- An argument is conditionally forceable iff its forceability
770-- depends on the collapsibility of the whole type.
771data Forceability = Conditional | Unconditional deriving (Show, Enum, Bounded, Eq, Ord)
774deriving instance Binary Forceability
775deriving instance NFData Forceability
778data OptInfo = Optimise { collapsible :: Bool,
780 -- The following should actually be (IntMap Forceability)
781 -- but the corresponding Binary instance seems to be broken.
782 -- Let's store a list and convert it to IntMap whenever needed.
783 forceable :: [(Int, Forceability)],
787deriving instance Binary OptInfo
788deriving instance NFData OptInfo
792data TypeInfo = TI { con_names :: [Name],
797deriving instance Binary TypeInfo
798deriving instance NFData TypeInfo
801-- Syntactic sugar info
803data DSL' t = DSL { dsl_bind :: t,
808 index_first :: Maybe t,
809 index_next :: Maybe t,
810 dsl_lambda :: Maybe t,
813 deriving (Show, Functor)
815deriving instance Binary DSL'
816deriving instance NFData DSL'
821data SynContext = PatternSyntax | TermSyntax | AnySyntax
824deriving instance Binary SynContext
825deriving instance NFData SynContext
828data Syntax = Rule [SSymbol] PTerm SynContext
831deriving instance Binary Syntax
832deriving instance NFData Syntax
835data SSymbol = Keyword Name
842deriving instance Binary SSymbol
843deriving instance NFData SSymbol
846initDSL = DSL (PRef f (UN ">>="))
847 (PRef f (UN "return"))
855 where f = fileFC "(builtin)"
857data Using = UImplicit Name PTerm
858 | UConstraint Name [Name]
861deriving instance Binary Using
862deriving instance NFData Using
865data SyntaxInfo = Syn { using :: [Using],
866 syn_params :: [(Name, PTerm)],
867 syn_namespace :: [String],
869 decoration :: Name -> Name,
871 implicitAllowed :: Bool,
875deriving instance NFData SyntaxInfo
876deriving instance Binary SyntaxInfo
879defaultSyntax = Syn [] [] [] [] id False False initDSL
881expandNS :: SyntaxInfo -> Name -> Name
882expandNS syn n@(NS _ _) = n
883expandNS syn n = case syn_namespace syn of
888--- Pretty printing declarations and terms
890instance Show PTerm where
891 show tm = showImp Nothing False False tm
893instance Pretty PTerm where
894 pretty = prettyImp False
896instance Show PDecl where
897 show d = showDeclImp False d
899instance Show PClause where
900 show c = showCImp True c
902instance Show PData where
903 show d = showDImp False d
905showDecls :: Bool -> [PDecl] -> String
907showDecls i (d:ds) = showDeclImp i d ++ "\n" ++ showDecls i ds
909showDeclImp _ (PFix _ f ops) = show f ++ " " ++ showSep ", " ops
910showDeclImp i (PTy _ _ _ _ n t) = "tydecl " ++ showCG n ++ " : " ++ showImp Nothing i False t
911showDeclImp i (PClauses _ _ n cs) = "pat " ++ showCG n ++ "\t" ++ showSep "\n\t" (map (showCImp i) cs)
912showDeclImp _ (PData _ _ _ _ d) = showDImp True d
913showDeclImp i (PParams _ ns ps) = "params {" ++ show ns ++ "\n" ++ showDecls i ps ++ "}\n"
914showDeclImp i (PNamespace n ps) = "namespace {" ++ n ++ "\n" ++ showDecls i ps ++ "}\n"
915showDeclImp _ (PSyntax _ syn) = "syntax " ++ show syn
916showDeclImp i (PClass _ _ _ cs n ps ds)
917 = "class " ++ show cs ++ " " ++ show n ++ " " ++ show ps ++ "\n" ++ showDecls i ds
918showDeclImp i (PInstance _ _ cs n _ t _ ds)
919 = "instance " ++ show cs ++ " " ++ show n ++ " " ++ show t ++ "\n" ++ showDecls i ds
920showDeclImp _ _ = "..."
921-- showDeclImp (PImport i) = "import " ++ i
924showCImp :: Bool -> PClause -> String
925showCImp impl (PClause _ n l ws r w)
926 = showImp Nothing impl False l ++ showWs ws ++ " = " ++ showImp Nothing impl False r
927 ++ " where " ++ show w
930 showWs (x : xs) = " | " ++ showImp Nothing impl False x ++ showWs xs
931showCImp impl (PWith _ n l ws r w)
932 = showImp Nothing impl False l ++ showWs ws ++ " with " ++ showImp Nothing impl False r
933 ++ " { " ++ show w ++ " } "
936 showWs (x : xs) = " | " ++ showImp Nothing impl False x ++ showWs xs
939showDImp :: Bool -> PData -> String
940showDImp impl (PDatadecl n ty cons)
941 = "data " ++ show n ++ " : " ++ showImp Nothing impl False ty ++ " where\n\t"
943 (map (\ (_, n, t, _) -> show n ++ " : " ++ showImp Nothing impl False t) cons)
945getImps :: [PArg] -> [(Name, PTerm)]
947getImps (PImp _ _ _ n tm _ : xs) = (n, tm) : getImps xs
948getImps (_ : xs) = getImps xs
950getExps :: [PArg] -> [PTerm]
952getExps (PExp _ _ tm _ : xs) = tm : getExps xs
953getExps (_ : xs) = getExps xs
955getConsts :: [PArg] -> [PTerm]
957getConsts (PConstraint _ _ tm _ : xs) = tm : getConsts xs
958getConsts (_ : xs) = getConsts xs
960getAll :: [PArg] -> [PTerm]
963-- | Pretty-print a high-level Idris term
964prettyImp :: Bool -- ^^ whether to show implicits
965 -> PTerm -- ^^ the term to pretty-print
967prettyImp impl = prettySe 10
969 prettySe p (PQuote r) =
970 if size r > breakingSize then
971 text "![" $$ pretty r <> text "]"
973 text "![" <> pretty r <> text "]"
974 prettySe p (PPatvar fc n) = pretty n
975 prettySe p (PRef fc n) =
981 prettyBasic n@(UN _) = pretty n
982 prettyBasic (MN _ s) = text s
983 prettyBasic (NS n s) = (foldr (<>) empty (intersperse (text ".") (map text $ reverse s))) <> prettyBasic n
984 prettyBasic (SN sn) = text (show sn)
985 prettySe p (PLam n ty sc) =
987 if size sc > breakingSize then
988 text "λ" <> pretty n <+> text "=>" $+$ pretty sc
990 text "λ" <> pretty n <+> text "=>" <+> pretty sc
991 prettySe p (PLet n ty v sc) =
993 if size sc > breakingSize then
994 text "let" <+> pretty n <+> text "=" <+> prettySe 10 v <+> text "in" $+$
995 nest nestingSize (prettySe 10 sc)
997 text "let" <+> pretty n <+> text "=" <+> prettySe 10 v <+> text "in" <+>
999 prettySe p (PPi (Exp l s _ _) n ty sc)
1000 | n `elem` allNamesIn sc || impl =
1001 let open = if l then text "|" <> lparen else lparen in
1003 if size sc > breakingSize then
1004 open <> pretty n <+> colon <+> prettySe 10 ty <> rparen <+>
1005 st <+> text "->" $+$ prettySe 10 sc
1007 open <> pretty n <+> colon <+> prettySe 10 ty <> rparen <+>
1008 st <+> text "->" <+> prettySe 10 sc
1011 if size sc > breakingSize then
1012 prettySe 0 ty <+> st <+> text "->" $+$ prettySe 10 sc
1014 prettySe 0 ty <+> st <+> text "->" <+> prettySe 10 sc
1018 Static -> text "[static]"
1020 prettySe p (PPi (Imp l s _ _) n ty sc)
1022 let open = if l then text "|" <> lbrace else lbrace in
1024 if size sc > breakingSize then
1025 open <> pretty n <+> colon <+> prettySe 10 ty <> rbrace <+>
1026 st <+> text "->" <+> prettySe 10 sc
1028 open <> pretty n <+> colon <+> prettySe 10 ty <> rbrace <+>
1029 st <+> text "->" <+> prettySe 10 sc
1030 | otherwise = prettySe 10 sc
1034 Static -> text $ "[static]"
1036 prettySe p (PPi (Constraint _ _ _) n ty sc) =
1038 if size sc > breakingSize then
1039 prettySe 10 ty <+> text "=>" <+> prettySe 10 sc
1041 prettySe 10 ty <+> text "=>" $+$ prettySe 10 sc
1042 prettySe p (PPi (TacImp _ _ s _) n ty sc) =
1044 if size sc > breakingSize then
1045 lbrace <> text "tacimp" <+> pretty n <+> colon <+> prettySe 10 ty <>
1046 rbrace <+> text "->" $+$ prettySe 10 sc
1048 lbrace <> text "tacimp" <+> pretty n <+> colon <+> prettySe 10 ty <>
1049 rbrace <+> text "->" <+> prettySe 10 sc
1050 prettySe p (PApp _ (PRef _ f) [])
1051 | not impl = pretty f
1052 prettySe p (PAppBind _ (PRef _ f) [])
1053 | not impl = text "!" <+> pretty f
1054 prettySe p (PApp _ (PRef _ op@(UN (f:_))) args)
1055 | length (getExps args) == 2 && (not impl) && (not $ isAlpha f) =
1056 let [l, r] = getExps args in
1058 if size r > breakingSize then
1059 prettySe 1 l <+> pretty op $+$ prettySe 0 r
1061 prettySe 1 l <+> pretty op <+> prettySe 0 r
1062 prettySe p (PApp _ f as) =
1063 let args = getExps as in
1068 -- foldr (<+>) empty $ map prettyArgS as
1070 foldl' fSe empty args
1071 -- foldr (<+>) empty $ map prettyArgSe args
1074 if size r > breakingSize then
1075 l $+$ nest nestingSize (prettyArgS r)
1080 if size r > breakingSize then
1081 l $+$ nest nestingSize (prettyArgSe r)
1084 prettySe p (PCase _ scr opts) =
1085 text "case" <+> prettySe 10 scr <+> text "of" $+$ nest nestingSize prettyBody
1087 prettyBody = foldr ($$) empty $ intersperse (text "|") $ map sc opts
1089 sc (l, r) = prettySe 10 l <+> text "=>" <+> prettySe 10 r
1090 prettySe p (PHidden tm) = text "." <> prettySe 0 tm
1091 prettySe p (PRefl _ _) = text "refl"
1092 prettySe p (PResolveTC _) = text "resolvetc"
1093 prettySe p (PTrue _) = text "()"
1094 prettySe p (PFalse _) = text "_|_"
1095 prettySe p (PEq _ l r) =
1097 if size r > breakingSize then
1098 prettySe 10 l <+> text "=" $$ nest nestingSize (prettySe 10 r)
1100 prettySe 10 l <+> text "=" <+> prettySe 10 r
1101 prettySe p (PRewrite _ l r _) =
1103 if size r > breakingSize then
1104 text "rewrite" <+> prettySe 10 l <+> text "in" $$ nest nestingSize (prettySe 10 r)
1106 text "rewrite" <+> prettySe 10 l <+> text "in" <+> prettySe 10 r
1107 prettySe p (PTyped l r) =
1108 lparen <> prettySe 10 l <+> colon <+> prettySe 10 r <> rparen
1109 prettySe p (PPair _ l r) =
1110 if size r > breakingSize then
1111 lparen <> prettySe 10 l <> text "," $+$
1112 prettySe 10 r <> rparen
1114 lparen <> prettySe 10 l <> text "," <+> prettySe 10 r <> rparen
1115 prettySe p (PDPair _ l t 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 (PAlternative a as) =
1122 lparen <> text "|" <> prettyAs <> text "|" <> rparen
1125 foldr (\l -> \r -> l <+> text "," <+> r) empty $ map (prettySe 10) as
1126 prettySe p PType = text "Type"
1127 prettySe p (PConstant c) = pretty c
1128 -- XXX: add pretty for tactics
1129 prettySe p (PProof ts) =
1130 text "proof" <+> lbrace $+$ nest nestingSize (text . show $ ts) $+$ rbrace
1131 prettySe p (PTactics ts) =
1132 text "tactics" <+> lbrace $+$ nest nestingSize (text . show $ ts) $+$ rbrace
1133 prettySe p (PMetavar n) = text "?" <> pretty n
1134 prettySe p (PReturn f) = text "return"
1135 prettySe p PImpossible = text "impossible"
1136 prettySe p Placeholder = text "_"
1137 prettySe p (PDoBlock _) = text "do block pretty not implemented"
1138 prettySe p (PElabError s) = pretty s
1140 prettySe p _ = text "test"
1142 prettyArgS (PImp _ _ _ n tm _) = prettyArgSi (n, tm)
1143 prettyArgS (PExp _ _ tm _) = prettyArgSe tm
1144 prettyArgS (PConstraint _ _ tm _) = prettyArgSc tm
1145 prettyArgS (PTacImplicit _ _ n _ tm _) = prettyArgSti (n, tm)
1147 prettyArgSe arg = prettySe 0 arg
1148 prettyArgSi (n, val) = lbrace <> pretty n <+> text "=" <+> prettySe 10 val <> rbrace
1149 prettyArgSc val = lbrace <> lbrace <> prettySe 10 val <> rbrace <> rbrace
1150 prettyArgSti (n, val) = lbrace <> text "auto" <+> pretty n <+> text "=" <+> prettySe 10 val <> rbrace
1152 bracket outer inner doc
1153 | inner > outer = lparen <> doc <> rparen
1157showName :: Maybe IState -- ^^ the Idris state, for information about names and colours
1158 -> [(Name, Bool)] -- ^^ the bound variables and whether they're implicit
1159 -> Bool -- ^^ whether to show implicits
1160 -> Bool -- ^^ whether to colourise
1161 -> Name -- ^^ the term to show
1163showName ist bnd impl colour n = case ist of
1164 Just i -> if colour then colourise n (idris_colourTheme i) else showbasic n
1165 Nothing -> showbasic n
1166 where name = if impl then show n else showbasic n
1167 showbasic n@(UN _) = showCG n
1168 showbasic (MN _ s) = s
1169 showbasic (NS n s) = showSep "." (reverse s) ++ "." ++ showbasic n
1170 showbasic (SN s) = show s
1172 colourise n t = let ctxt' = fmap tt_ctxt ist in
1175 Just ctxt | Just impl <- lookup n bnd -> if impl then colouriseImplicit t name
1176 else colouriseBound t name
1177 | isDConName n ctxt -> colouriseData t name
1178 | isFnName n ctxt -> colouriseFun t name
1179 | isTConName n ctxt -> colouriseType t name
1180 -- The assumption is that if a name is not bound and does not exist in the
1181 -- global context, then we're somewhere in which implicit info has been lost
1182 -- (like error messages). Thus, unknown vars are colourised as implicits.
1183 | otherwise -> colouriseImplicit t name
1186showImp :: Maybe IState -- ^^ the Idris state, for information about identifiers and colours
1187 -> Bool -- ^^ whether to show implicits
1188 -> Bool -- ^^ whether to colourise
1189 -> PTerm -- ^^ the term to show
1191showImp ist impl colour tm = se 10 [] tm where
1192 perhapsColourise :: (ColourTheme -> String -> String) -> String -> String
1193 perhapsColourise col str = case ist of
1194 Just i -> if colour then col (idris_colourTheme i) str else str
1197 se :: Int -> [(Name, Bool)] -> PTerm -> String
1198 se p bnd (PQuote r) = "![" ++ show r ++ "]"
1199 se p bnd (PPatvar fc n) = if impl then show n ++ "[p]" else show n
1200 se p bnd (PInferRef fc n) = "!" ++ show n -- ++ "[" ++ show fc ++ "]"
1202 | Just str <- slist p bnd e = str
1203 | Just num <- snat p e = perhapsColourise colouriseData (show num)
1204 se p bnd (PRef fc n) = showName ist bnd impl colour n
1205 se p bnd (PLam n ty sc) = bracket p 2 $ "\\ " ++ perhapsColourise colouriseBound (show n) ++
1206 (if impl then " : " ++ se 10 bnd ty else "") ++ " => "
1207 ++ se 10 ((n, False):bnd) sc
1208 se p bnd (PLet n ty v sc) = bracket p 2 $ "let " ++ perhapsColourise colouriseBound (show n) ++
1209 " = " ++ se 10 bnd v ++
1210 " in " ++ se 10 ((n, False):bnd) sc
1211 se p bnd (PPi (Exp l s _ param) n ty sc)
1212 | n `elem` allNamesIn sc || impl
1214 (if l then "|(" else "(") ++
1215 perhapsColourise colouriseBound (show n) ++ " : " ++ se 10 bnd ty ++
1217 (if (impl && param) then "P" else "") ++
1219 "-> " ++ se 10 ((n, False):bnd) sc
1220 | otherwise = bracket p 2 $ se 0 bnd ty ++ " " ++ st ++ "-> " ++ se 10 bnd sc
1221 where st = case s of
1222 Static -> "[static] "
1224 se p bnd (PPi (Imp l s _ _) n ty sc)
1225 | impl = bracket p 2 $ (if l then "|{" else "{") ++
1226 perhapsColourise colouriseBound (show n) ++ " : " ++ se 10 bnd ty ++
1227 "} " ++ st ++ "-> " ++ se 10 ((n, True):bnd) sc
1228 | otherwise = se 10 ((n, True):bnd) sc
1229 where st = case s of
1230 Static -> "[static] "
1232 se p bnd (PPi (Constraint _ _ _) n ty sc)
1233 = bracket p 2 $ se 10 bnd ty ++ " => " ++ se 10 bnd sc
1234 se p bnd (PPi (TacImp _ _ s _) n ty sc)
1236 "{tacimp " ++ (perhapsColourise colouriseBound (show n)) ++ " : " ++ se 10 bnd ty ++ "} -> " ++
1237 se 10 ((n, False):bnd) sc
1238 se p bnd (PMatchApp _ f) = "match " ++ show f
1239 se p bnd (PApp _ hd@(PRef _ f) [])
1240 | not impl = se p bnd hd
1241 se p bnd (PAppBind _ hd@(PRef _ f) [])
1242 | not impl = "!" ++ se p bnd hd
1243 se p bnd (PApp _ op@(PRef _ (UN (f:_))) args)
1244 | length (getExps args) == 2 && not impl && not (isAlpha f)
1245 = let [l, r] = getExps args in
1246 bracket p 1 $ se 1 bnd l ++ " " ++ se p bnd op ++ " " ++ se 0 bnd r
1247 se p bnd (PApp _ f as)
1248 = -- let args = getExps as in
1249 bracket p 1 $ se 1 bnd f ++
1250 if impl then concatMap (sArg bnd) as
1251 else concatMap (suiArg impl bnd) as
1252 se p bnd (PAppBind _ f as)
1253 = let args = getExps as in
1254 "!" ++ (bracket p 1 $ se 1 bnd f ++ if impl then concatMap (sArg bnd) as
1255 else concatMap (seArg bnd) args)
1256 se p bnd (PCase _ scr opts) = "case " ++ se 10 bnd scr ++ " of " ++ showSep " | " (map sc opts)
1257 where sc (l, r) = se 10 bnd l ++ " => " ++ se 10 bnd r
1258 se p bnd (PHidden tm) = "." ++ se 0 bnd tm
1259 se p bnd (PRefl _ t)
1260 | not impl = perhapsColourise colouriseData "refl"
1261 | otherwise = perhapsColourise colouriseData $ "refl {" ++ se 10 bnd t ++ "}"
1262 se p bnd (PResolveTC _) = "resolvetc"
1263 se p bnd (PTrue _) = perhapsColourise colouriseType "()"
1264 se p bnd (PFalse _) = perhapsColourise colouriseType "_|_"
1265 se p bnd (PEq _ l r) = bracket p 2 $ se 10 bnd l ++ perhapsColourise colouriseType " = " ++ se 10 bnd r
1266 se p bnd (PRewrite _ l r _) = bracket p 2 $ "rewrite " ++ se 10 bnd l ++ " in " ++ se 10 bnd r
1267 se p bnd (PTyped l r) = "(" ++ se 10 bnd l ++ " : " ++ se 10 bnd r ++ ")"
1268 se p bnd (PPair _ l r) = "(" ++ se 10 bnd l ++ ", " ++ se 10 bnd r ++ ")"
1269 se p bnd (PDPair _ l t r) = "(" ++ se 10 bnd l ++ " ** " ++ se 10 bnd r ++ ")"
1270 se p bnd (PAlternative a as) = "(|" ++ showSep " , " (map (se 10 bnd) as) ++ "|)"
1271 se p bnd PType = perhapsColourise colouriseType "Type"
1272 se p bnd (PConstant c) = perhapsColourise (cfun c) (show c)
1273 where cfun (AType _) = colouriseType
1274 cfun StrType = colouriseType
1275 cfun PtrType = colouriseType
1276 cfun VoidType = colouriseType
1277 cfun _ = colouriseData
1278 se p bnd (PProof ts) = "proof { " ++ show ts ++ "}"
1279 se p bnd (PTactics ts) = "tactics { " ++ show ts ++ "}"
1280 se p bnd (PMetavar n) = "?" ++ show n
1281 se p bnd (PReturn f) = "return"
1282 se p bnd PImpossible = "impossible"
1283 se p bnd Placeholder = "_"
1284 se p bnd (PDoBlock _) = "do block show not implemented"
1285 se p bnd (PElabError s) = show s
1286 se p bnd (PCoerced t) = se p bnd t
1287 se p bnd (PUnifyLog t) = "%unifyLog " ++ se p bnd t
1288 se p bnd (PNoImplicits t) = "%noimplicit " ++ se p bnd t
1289-- se p bnd x = "Not implemented"
1291 slist' p bnd (PApp _ (PRef _ nil) _)
1292 | not impl && nsroot nil == UN "Nil" = Just []
1293 slist' p bnd (PApp _ (PRef _ cons) args)
1294 | nsroot cons == UN "::",
1295 (PExp {getTm=tl}):(PExp {getTm=hd}):imps <- reverse args,
1297 Just tl' <- slist' p bnd tl
1300 isImp (PImp {}) = True
1302 slist' _ _ _ = Nothing
1304 slist p bnd e | Just es <- slist' p bnd e = Just $
1305 case es of [] -> "[]"
1306 [x] -> "[" ++ se p bnd x ++ "]"
1307 xs -> "[" ++ intercalate "," (map (se p bnd ) xs) ++ "]"
1308 slist _ _ _ = Nothing
1310 -- since Prelude is always imported, S & Z are unqualified iff they're the
1313 | show o == (natns++"Z") || show o == "Z" = Just 0
1314 snat p (PApp _ s [PExp {getTm=n}])
1315 | show s == (natns++"S") || show s == "S",
1320 natns = "Prelude.Nat."
1322 sArg bnd (PImp _ _ _ n tm _) = siArg bnd (n, tm)
1323 sArg bnd (PExp _ _ tm _) = seArg bnd tm
1324 sArg bnd (PConstraint _ _ tm _) = scArg bnd tm
1325 sArg bnd (PTacImplicit _ _ n _ tm _) = stiArg bnd (n, tm)
1327 -- show argument, implicits given by the user also shown
1328 suiArg impl bnd (PImp _ mi _ n tm _)
1329 | impl || not mi = siArg bnd (n, tm)
1330 suiArg impl bnd (PExp _ _ tm _) = seArg bnd tm
1331 suiArg impl bnd _ = ""
1333 seArg bnd arg = " " ++ se 0 bnd arg
1334 siArg bnd (n, val) =
1336 val' = se 10 bnd val in
1338 then " {" ++ n' ++ "}"
1339 else " {" ++ n' ++ " = " ++ val' ++ "}"
1340 scArg bnd val = " {{" ++ se 10 bnd val ++ "}}"
1341 stiArg bnd (n, val) = " {auto " ++ show n ++ " = " ++ se 10 bnd val ++ "}"
1343 bracket outer inner str | inner > outer = "(" ++ str ++ ")"
1347instance Sized PTerm where
1348 size (PQuote rawTerm) = size rawTerm
1349 size (PRef fc name) = size name
1350 size (PLam name ty bdy) = 1 + size ty + size bdy
1351 size (PPi plicity name ty bdy) = 1 + size ty + size bdy
1352 size (PLet name ty def bdy) = 1 + size ty + size def + size bdy
1353 size (PTyped trm ty) = 1 + size trm + size ty
1354 size (PApp fc name args) = 1 + size args
1355 size (PAppBind fc name args) = 1 + size args
1356 size (PCase fc trm bdy) = 1 + size trm + size bdy
1358 size (PFalse fc) = 1
1359 size (PRefl fc _) = 1
1360 size (PResolveTC fc) = 1
1361 size (PEq fc left right) = 1 + size left + size right
1362 size (PRewrite fc left right _) = 1 + size left + size right
1363 size (PPair fc left right) = 1 + size left + size right
1364 size (PDPair fs left ty right) = 1 + size left + size ty + size right
1365 size (PAlternative a alts) = 1 + size alts
1366 size (PHidden hidden) = size hidden
1367 size (PUnifyLog tm) = size tm
1368 size (PNoImplicits tm) = size tm
1370 size (PConstant const) = 1 + size const
1371 size Placeholder = 1
1372 size (PDoBlock dos) = 1 + size dos
1373 size (PIdiom fc term) = 1 + size term
1374 size (PReturn fc) = 1
1375 size (PMetavar name) = 1
1376 size (PProof tactics) = size tactics
1377 size (PElabError err) = size err
1378 size PImpossible = 1
1380getPArity :: PTerm -> Int
1381getPArity (PPi _ _ _ sc) = 1 + getPArity sc
1384-- Return all names, free or globally bound, in the given term.
1386allNamesIn :: PTerm -> [Name]
1387allNamesIn tm = nub $ ni [] tm
1390 | not (n `elem` env) = [n]
1391 ni env (PApp _ f as) = ni env f ++ concatMap (ni env) (map getTm as)
1392 ni env (PAppBind _ f as) = ni env f ++ concatMap (ni env) (map getTm as)
1393 ni env (PCase _ c os) = ni env c ++ concatMap (ni env) (map snd os)
1394 ni env (PLam n ty sc) = ni env ty ++ ni (n:env) sc
1395 ni env (PPi _ n ty sc) = ni env ty ++ ni (n:env) sc
1396 ni env (PHidden tm) = ni env tm
1397 ni env (PEq _ l r) = ni env l ++ ni env r
1398 ni env (PRewrite _ l r _) = ni env l ++ ni env r
1399 ni env (PTyped l r) = ni env l ++ ni env r
1400 ni env (PPair _ l r) = ni env l ++ ni env r
1401 ni env (PDPair _ (PRef _ n) t r) = ni env t ++ ni (n:env) r
1402 ni env (PDPair _ l t r) = ni env l ++ ni env t ++ ni env r
1403 ni env (PAlternative a ls) = concatMap (ni env) ls
1404 ni env (PUnifyLog tm) = ni env tm
1405 ni env (PNoImplicits tm) = ni env tm
1408-- Return names which are free in the given term.
1410namesIn :: [(Name, PTerm)] -> IState -> PTerm -> [Name]
1411namesIn uvars ist tm = nub $ ni [] tm
1414 | not (n `elem` env)
1415 = case lookupTy n (tt_ctxt ist) of
1417 _ -> if n `elem` (map fst uvars) then [n] else []
1418 ni env (PApp _ f as) = ni env f ++ concatMap (ni env) (map getTm as)
1419 ni env (PAppBind _ f as) = ni env f ++ concatMap (ni env) (map getTm as)
1420 ni env (PCase _ c os) = ni env c ++ concatMap (ni env) (map snd os)
1421 ni env (PLam n ty sc) = ni env ty ++ ni (n:env) sc
1422 ni env (PPi _ n ty sc) = ni env ty ++ ni (n:env) sc
1423 ni env (PEq _ l r) = ni env l ++ ni env r
1424 ni env (PRewrite _ l r _) = ni env l ++ ni env r
1425 ni env (PTyped l r) = ni env l ++ ni env r
1426 ni env (PPair _ l r) = ni env l ++ ni env r
1427 ni env (PDPair _ (PRef _ n) t r) = ni env t ++ ni (n:env) r
1428 ni env (PDPair _ l t r) = ni env l ++ ni env t ++ ni env r
1429 ni env (PAlternative a as) = concatMap (ni env) as
1430 ni env (PHidden tm) = ni env tm
1431 ni env (PUnifyLog tm) = ni env tm
1432 ni env (PNoImplicits tm) = ni env tm
1435-- Return which of the given names are used in the given term.
1437usedNamesIn :: [Name] -> IState -> PTerm -> [Name]
1438usedNamesIn vars ist tm = nub $ ni [] tm
1441 | n `elem` vars && not (n `elem` env)
1442 = case lookupTy n (tt_ctxt ist) of
1445 ni env (PApp _ f as) = ni env f ++ concatMap (ni env) (map getTm as)
1446 ni env (PAppBind _ f as) = ni env f ++ concatMap (ni env) (map getTm as)
1447 ni env (PCase _ c os) = ni env c ++ concatMap (ni env) (map snd os)
1448 ni env (PLam n ty sc) = ni env ty ++ ni (n:env) sc
1449 ni env (PPi _ n ty sc) = ni env ty ++ ni (n:env) sc
1450 ni env (PEq _ l r) = ni env l ++ ni env r
1451 ni env (PRewrite _ l r _) = ni env l ++ ni env r
1452 ni env (PTyped l r) = ni env l ++ ni env r
1453 ni env (PPair _ l r) = ni env l ++ ni env r
1454 ni env (PDPair _ (PRef _ n) t r) = ni env t ++ ni (n:env) r
1455 ni env (PDPair _ l t r) = ni env l ++ ni env t ++ ni env r
1456 ni env (PAlternative a as) = concatMap (ni env) as
1457 ni env (PHidden tm) = ni env tm
1458 ni env (PUnifyLog tm) = ni env tm
1459 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