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 idris_errRev :: [(Term, Term)],
113 syntax_rules :: [Syntax],
114 syntax_keywords :: [String],
115 imported :: [FilePath], -- ^ The imported modules
116 idris_scprims :: [(Name, (Int, PrimFn))],
117 idris_objs :: [(Codegen, FilePath)],
118 idris_libs :: [(Codegen, String)],
119 idris_cgflags :: [(Codegen, String)],
120 idris_hdrs :: [(Codegen, String)],
121 proof_list :: [(Name, [String])],
122 errLine :: Maybe Int,
123 lastParse :: Maybe Name,
124 indent_stack :: [Int],
125 brace_stack :: [Maybe Int],
126 hide_list :: [(Name, Maybe Accessibility)],
127 default_access :: Accessibility,
128 default_total :: Bool,
129 ibc_write :: [IBCWrite],
130 compiled_so :: Maybe String,
131 idris_dynamic_libs :: [DynamicLib],
132 idris_language_extensions :: [LanguageExt],
133 idris_outputmode :: OutputMode,
134 idris_colourRepl :: Bool,
135 idris_colourTheme :: ColourTheme,
136 idris_outh :: Handle,
137 idris_errorhandlers :: [Name],
138 idris_nameIdx :: (Int, Ctxt (Int, Name))
141data SizeChange = Smaller | Same | Bigger | Unknown
144deriving instance Binary SizeChange
145deriving instance NFData SizeChange
148type SCGEntry = (Name, [Maybe (Int, SizeChange)])
150data CGInfo = CGInfo { argsdef :: [Name],
151 calls :: [(Name, [[Name]])],
157deriving instance Binary CGInfo
158deriving instance NFData CGInfo
161primDefs = [sUN "unsafePerformPrimIO",
162 sUN "mkLazyForeignPrim",
166-- information that needs writing for the current module's .ibc file
167data IBCWrite = IBCFix FixDecl
171 | IBCInstance Bool Name Name
178 | IBCObj Codegen FilePath
179 | IBCLib Codegen String
180 | IBCCGFlag Codegen String
182 | IBCHeader Codegen String
183 | IBCAccess Name Accessibility
184 | IBCMetaInformation Name MetaInformation
185 | IBCTotal Name Totality
186 | IBCFlags Name [FnOpt]
187 | IBCTrans (Term, Term)
188 | IBCErrRev (Term, Term)
192 | IBCDef Name -- i.e. main context
193 | IBCNameHint (Name, Name)
194 | IBCLineApp FilePath Int PTerm
197-- | The initial state for the compiler
199idrisInit = IState initContext [] [] emptyContext emptyContext emptyContext
200 emptyContext emptyContext emptyContext emptyContext
201 emptyContext emptyContext emptyContext emptyContext
203 [] [] defaultOpts 6 [] [] [] [] [] [] [] [] [] [] [] [] []
204 [] Nothing Nothing [] [] [] Hidden False [] Nothing [] [] RawOutput
205 True defaultTheme stdout [] (0, emptyContext)
207-- | The monad for the main REPL - reading and processing files and updating
208-- global state (hence the IO inner monad).
209--type Idris = WriterT [Either String (IO ())] (State IState a))
210type Idris = StateT IState (ErrorT Err IO)
212-- Commands in the REPL
231 | ChangeDirectory FilePath
234 | Compile Codegen String
239 | AddProof (Maybe Name)
251 | DynamicLink FilePath
256 | CaseSplitAt Bool Int Name
257 | AddClauseFrom Bool Int Name
258 | AddProofClauseFrom Bool Int Name
259 | AddMissing Bool Int Name
260 | MakeWith Bool Int Name
261 | DoProofSearch Bool Int Name [Name]
265 | SetColour ColourType IdrisColour
270data Opt = Filename String
282 | NoBuiltins -- only for the really primitive stuff!
307 | OutputTy OutputType
308 | Extension LanguageExt
309 | InterpretScript String
310 | TargetTriple String
316-- Parsed declarations
318data Fixity = Infixl { prec :: Int }
319 | Infixr { prec :: Int }
320 | InfixN { prec :: Int }
321 | PrefixN { prec :: Int }
324deriving instance Binary Fixity
325deriving instance NFData Fixity
328instance Show Fixity where
329 show (Infixl i) = "infixl " ++ show i
330 show (Infixr i) = "infixr " ++ show i
331 show (InfixN i) = "infix " ++ show i
332 show (PrefixN i) = "prefix " ++ show i
334data FixDecl = Fix Fixity String
337instance Show FixDecl where
338 show (Fix f s) = show f ++ " " ++ s
341deriving instance Binary FixDecl
342deriving instance NFData FixDecl
345instance Ord FixDecl where
346 compare (Fix x _) (Fix y _) = compare (prec x) (prec y)
349data Static = Static | Dynamic
352deriving instance Binary Static
353deriving instance NFData Static
356-- Mark bindings with their explicitness, and laziness
357data Plicity = Imp { pargopts :: [ArgOpt],
361 | Exp { pargopts :: [ArgOpt],
365 | Constraint { pargopts :: [ArgOpt],
368 | TacImp { pargopts :: [ArgOpt],
374plazy :: Plicity -> Bool
375plazy tm = Lazy `elem` pargopts tm
378deriving instance Binary Plicity
379deriving instance NFData Plicity
382impl = Imp [Lazy] Dynamic "" False
383expl = Exp [] Dynamic "" False
384expl_param = Exp [] Dynamic "" True
385constraint = Constraint [] Dynamic ""
386tacimpl t = TacImp [] Dynamic t ""
388data FnOpt = Inlinable -- always evaluate when simplifying
389 | TotalFn | PartialFn
390 | Coinductive | AssertTotal
391 | Dictionary -- type class dictionary, eval only when
392 -- a function argument, and further evaluation resutls
393 | Implicit -- implicit coercion
394 | CExport String -- export, with a C name
395 | ErrorHandler -- ^^ an error handler for use with the ErrorReflection extension
396 | ErrorReverse -- ^^ attempt to reverse normalise before showing in error
397 | Reflection -- a reflecting function, compile-time only
398 | Specialise [(Name, Maybe Int)] -- specialise it, freeze these names
401deriving instance Binary FnOpt
402deriving instance NFData FnOpt
407inlinable :: FnOpts -> Bool
408inlinable = elem Inlinable
410dictionary :: FnOpts -> Bool
411dictionary = elem Dictionary
414-- | Data declaration options
415data DataOpt = Codata -- Set if the the data-type is coinductive
416 | DefaultEliminator -- Set if an eliminator should be generated for data type
420type DataOpts = [DataOpt]
422-- | Top-level declarations such as compiler directives, definitions,
423-- datatypes and typeclasses.
425 = PFix FC Fixity [String] -- ^ Fixity declaration
426 | PTy String SyntaxInfo FC FnOpts Name t -- ^ Type declaration
427 | PPostulate String SyntaxInfo FC FnOpts Name t -- ^ Postulate
428 | PClauses FC FnOpts Name [PClause' t] -- ^ Pattern clause
429 | PCAF FC Name t -- ^ Top level constant
430 | PData String SyntaxInfo FC DataOpts (PData' t) -- ^ Data declaration.
431 | PParams FC [(Name, t)] [PDecl' t] -- ^ Params block
432 | PNamespace String [PDecl' t] -- ^ New namespace
433 | PRecord String SyntaxInfo FC Name t String Name t -- ^ Record declaration
434 | PClass String SyntaxInfo FC
437 [(Name, t)] -- parameters
438 [PDecl' t] -- declarations
439 -- ^ Type class: arguments are documentation, syntax info, source location, constraints,
440 -- class name, parameters, method declarations
441 | PInstance SyntaxInfo FC [t] -- constraints
444 t -- full instance type
445 (Maybe Name) -- explicit name
447 -- ^ Instance declaration: arguments are syntax info, source location, constraints,
448 -- class name, parameters, full instance type, optional explicit name, and definitions
449 | PDSL Name (DSL' t) -- ^ DSL declaration
450 | PSyntax FC Syntax -- ^ Syntax definition
451 | PMutual FC [PDecl' t] -- ^ Mutual block
452 | PDirective (Idris ()) -- ^ Compiler directive. The parser inserts the corresponding action in the Idris monad.
453 | PProvider SyntaxInfo FC Name t t -- ^ Type provider. The first t is the type, the second is the term
454 | PTransform FC Bool t t -- ^ Source-to-source transformation rule. If
455 -- bool is True, lhs and rhs must be convertible
458deriving instance Binary PDecl'
459deriving instance NFData PDecl'
462-- For elaborator state
463type ElabD a = Elab' [PDecl] a
465-- | One clause of a top-level definition. Term arguments to constructors are:
467-- 1. The whole application (missing for PClauseR and PWithR because they're within a "with" clause)
469-- 2. The list of extra 'with' patterns
471-- 3. The right-hand side
473-- 4. The where block (PDecl' t)
475data PClause' t = PClause FC Name t [t] t [PDecl' t] -- ^ A normal top-level definition.
476 | PWith FC Name t [t] t [PDecl' t]
477 | PClauseR FC [t] t [PDecl' t]
478 | PWithR FC [t] t [PDecl' t]
481deriving instance Binary PClause'
482deriving instance NFData PClause'
486data PData' t = PDatadecl { d_name :: Name, -- ^ The name of the datatype
487 d_tcon :: t, -- ^ Type constructor
488 d_cons :: [(String, Name, t, FC, [Name])] -- ^ Constructors
490 -- ^ Data declaration
491 | PLaterdecl { d_name :: Name, d_tcon :: t }
492 -- ^ "Placeholder" for data whose constructors are defined later
495deriving instance Binary PData'
496deriving instance NFData PData'
499-- Handy to get a free function for applying PTerm -> PTerm functions
500-- across a program, by deriving Functor
502type PDecl = PDecl' PTerm
503type PData = PData' PTerm
504type PClause = PClause' PTerm
506-- get all the names declared in a decl
508declared :: PDecl -> [Name]
509declared (PFix _ _ _) = []
510declared (PTy _ _ _ _ n t) = [n]
511declared (PPostulate _ _ _ _ n t) = [n]
512declared (PClauses _ _ n _) = [] -- not a declaration
513declared (PCAF _ n _) = [n]
514declared (PData _ _ _ _ (PDatadecl n _ ts)) = n : map fstt ts
515 where fstt (_, a, _, _, _) = a
516declared (PData _ _ _ _ (PLaterdecl n _)) = [n]
517declared (PParams _ _ ds) = concatMap declared ds
518declared (PNamespace _ ds) = concatMap declared ds
519declared (PRecord _ _ _ n _ _ c _) = [n, c]
520declared (PClass _ _ _ _ n _ ms) = n : concatMap declared ms
521declared (PInstance _ _ _ _ _ _ _ _) = []
522declared (PDSL n _) = [n]
523declared (PSyntax _ _) = []
524declared (PMutual _ ds) = concatMap declared ds
525declared (PDirective _) = []
527-- get the names declared, not counting nested parameter blocks
528tldeclared :: PDecl -> [Name]
529tldeclared (PFix _ _ _) = []
530tldeclared (PTy _ _ _ _ n t) = [n]
531tldeclared (PPostulate _ _ _ _ n t) = [n]
532tldeclared (PClauses _ _ n _) = [] -- not a declaration
533tldeclared (PRecord _ _ _ n _ _ c _) = [n, c]
534tldeclared (PData _ _ _ _ (PDatadecl n _ ts)) = n : map fstt ts
535 where fstt (_, a, _, _, _) = a
536tldeclared (PParams _ _ ds) = []
537tldeclared (PMutual _ ds) = concatMap tldeclared ds
538tldeclared (PNamespace _ ds) = concatMap tldeclared ds
539tldeclared (PClass _ _ _ _ n _ ms) = concatMap tldeclared ms
540tldeclared (PInstance _ _ _ _ _ _ _ _) = []
543defined :: PDecl -> [Name]
544defined (PFix _ _ _) = []
545defined (PTy _ _ _ _ n t) = []
546defined (PPostulate _ _ _ _ n t) = []
547defined (PClauses _ _ n _) = [n] -- not a declaration
548defined (PCAF _ n _) = [n]
549defined (PData _ _ _ _ (PDatadecl n _ ts)) = n : map fstt ts
550 where fstt (_, a, _, _, _) = a
551defined (PData _ _ _ _ (PLaterdecl n _)) = []
552defined (PParams _ _ ds) = concatMap defined ds
553defined (PNamespace _ ds) = concatMap defined ds
554defined (PRecord _ _ _ n _ _ c _) = [n, c]
555defined (PClass _ _ _ _ n _ ms) = n : concatMap defined ms
556defined (PInstance _ _ _ _ _ _ _ _) = []
557defined (PDSL n _) = [n]
558defined (PSyntax _ _) = []
559defined (PMutual _ ds) = concatMap defined ds
560defined (PDirective _) = []
563updateN :: [(Name, Name)] -> Name -> Name
564updateN ns n | Just n' <- lookup n ns = n'
567updateNs :: [(Name, Name)] -> PTerm -> PTerm
569updateNs ns t = mapPT updateRef t
570 where updateRef (PRef fc f) = PRef fc (updateN ns f)
573-- updateDNs :: [(Name, Name)] -> PDecl -> PDecl
575-- updateDNs ns (PTy s f n t) | Just n' <- lookup n ns = PTy s f n' t
576-- updateDNs ns (PClauses f n c) | Just n' <- lookup n ns = PClauses f n' (map updateCNs c)
577-- where updateCNs ns (PClause n l ts r ds)
578-- = PClause (updateN ns n) (fmap (updateNs ns) l)
579-- (map (fmap (updateNs ns)) ts)
580-- (fmap (updateNs ns) r)
581-- (map (updateDNs ns) ds)
584-- | High level language terms
585data PTerm = PQuote Raw
587 | PInferRef FC Name -- ^ A name to be defined later
589 | PLam Name PTerm PTerm
590 | PPi Plicity Name PTerm PTerm
591 | PLet Name PTerm PTerm PTerm
592 | PTyped PTerm PTerm -- ^ Term with explicit type
593 | PApp FC PTerm [PArg]
594 | PAppBind FC PTerm [PArg] -- ^ implicitly bound application
595 | PMatchApp FC Name -- ^ Make an application by type matching
596 | PCase FC PTerm [(PTerm, PTerm)]
602 | PRewrite FC PTerm PTerm (Maybe PTerm)
603 | PPair FC PTerm PTerm
604 | PDPair FC PTerm PTerm PTerm
605 | PAlternative Bool [PTerm] -- True if only one may work
606 | PHidden PTerm -- ^ Irrelevant or hidden pattern
608 | PGoal FC PTerm Name PTerm
615 | PProof [PTactic] -- ^ Proof script
616 | PTactics [PTactic] -- ^ As PProof, but no auto solving
617 | PElabError Err -- ^ Error to report on elaboration
618 | PImpossible -- ^ Special case for declaring when an LHS can't typecheck
619 | PCoerced PTerm -- ^ To mark a coerced argument, so as not to coerce twice
620 | PDisamb [[T.Text]] PTerm -- ^ Preferences for explicit namespaces
621 | PUnifyLog PTerm -- ^ dump a trace of unifications when building term
622 | PNoImplicits PTerm -- ^ never run implicit converions on the term
627deriving instance Binary PTerm
628deriving instance NFData PTerm
631mapPT :: (PTerm -> PTerm) -> PTerm -> PTerm
632mapPT f t = f (mpt t) where
633 mpt (PLam n t s) = PLam n (mapPT f t) (mapPT f s)
634 mpt (PPi p n t s) = PPi p n (mapPT f t) (mapPT f s)
635 mpt (PLet n ty v s) = PLet n (mapPT f ty) (mapPT f v) (mapPT f s)
636 mpt (PRewrite fc t s g) = PRewrite fc (mapPT f t) (mapPT f s)
638 mpt (PApp fc t as) = PApp fc (mapPT f t) (map (fmap (mapPT f)) as)
639 mpt (PAppBind fc t as) = PAppBind fc (mapPT f t) (map (fmap (mapPT f)) as)
640 mpt (PCase fc c os) = PCase fc (mapPT f c) (map (pmap (mapPT f)) os)
641 mpt (PEq fc l r) = PEq fc (mapPT f l) (mapPT f r)
642 mpt (PTyped l r) = PTyped (mapPT f l) (mapPT f r)
643 mpt (PPair fc l r) = PPair fc (mapPT f l) (mapPT f r)
644 mpt (PDPair fc l t r) = PDPair fc (mapPT f l) (mapPT f t) (mapPT f r)
645 mpt (PAlternative a as) = PAlternative a (map (mapPT f) as)
646 mpt (PHidden t) = PHidden (mapPT f t)
647 mpt (PDoBlock ds) = PDoBlock (map (fmap (mapPT f)) ds)
648 mpt (PProof ts) = PProof (map (fmap (mapPT f)) ts)
649 mpt (PTactics ts) = PTactics (map (fmap (mapPT f)) ts)
650 mpt (PUnifyLog tm) = PUnifyLog (mapPT f tm)
651 mpt (PDisamb ns tm) = PDisamb ns (mapPT f tm)
652 mpt (PNoImplicits tm) = PNoImplicits (mapPT f tm)
653 mpt (PGoal fc r n sc) = PGoal fc (mapPT f r) n (mapPT f sc)
657data PTactic' t = Intro [Name] | Intros | Focus Name
658 | Refine Name [Bool] | Rewrite t
662 | LetTac Name t | LetTacTy Name t t
663 | Exact t | Compute | Trivial
664 | ProofSearch (Maybe Name) Name [Name]
667 | ProofState | ProofTerm | Undo
668 | Try (PTactic' t) (PTactic' t)
669 | TSeq (PTactic' t) (PTactic' t)
670 | ApplyTactic t -- see Language.Reflection module
674 | GoalType String (PTactic' t)
676 deriving (Show, Eq, Functor)
678deriving instance Binary PTactic'
679deriving instance NFData PTactic'
682instance Sized a => Sized (PTactic' a) where
683 size (Intro nms) = 1 + size nms
685 size (Focus nm) = 1 + size nm
686 size (Refine nm bs) = 1 + size nm + length bs
687 size (Rewrite t) = 1 + size t
688 size (Induction t) = 1 + size t
689 size (LetTac nm t) = 1 + size nm + size t
690 size (Exact t) = 1 + size t
698 size (Try l r) = 1 + size l + size r
699 size (TSeq l r) = 1 + size l + size r
700 size (ApplyTactic t) = 1 + size t
701 size (Reflect t) = 1 + size t
702 size (Fill t) = 1 + size t
706type PTactic = PTactic' PTerm
708data PDo' t = DoExp FC t
713 deriving (Eq, Functor)
715deriving instance Binary PDo'
716deriving instance NFData PDo'
719instance Sized a => Sized (PDo' a) where
720 size (DoExp fc t) = 1 + size fc + size t
721 size (DoBind fc nm t) = 1 + size fc + size nm + size t
722 size (DoBindP fc l r) = 1 + size fc + size l + size r
723 size (DoLet fc nm l r) = 1 + size fc + size nm + size l + size r
724 size (DoLetP fc l r) = 1 + size fc + size l + size r
728-- The priority gives a hint as to elaboration order. Best to elaborate
729-- things early which will help give a more concrete type to other
730-- variables, e.g. a before (interpTy a).
732data PArg' t = PImp { priority :: Int,
733 machine_inf :: Bool, -- true if the machine inferred it
735 pname :: Name, getTm :: t,
737 | PExp { priority :: Int,
741 | PConstraint { priority :: Int,
745 | PTacImplicit { priority :: Int,
751 deriving (Show, Eq, Functor)
753data ArgOpt = Lazy | HideDisplay
756lazyarg :: PArg' t -> Bool
757lazyarg tm = Lazy `elem` argopts tm
759instance Sized a => Sized (PArg' a) where
760 size (PImp p _ l nm trm _) = 1 + size nm + size trm
761 size (PExp p l trm _) = 1 + size trm
762 size (PConstraint p l trm _) = 1 + size trm
763 size (PTacImplicit p l nm scr trm _) = 1 + size nm + size scr + size trm
766deriving instance Binary PArg'
767deriving instance NFData PArg'
770pimp n t mach = PImp 1 mach [Lazy] n t ""
771pexp t = PExp 1 [] t ""
772pconst t = PConstraint 1 [] t ""
773ptacimp n s t = PTacImplicit 2 [Lazy] n s t ""
775type PArg = PArg' PTerm
779data ClassInfo = CI { instanceName :: Name,
780 class_methods :: [(Name, (FnOpts, PTerm))],
781 class_defaults :: [(Name, (Name, PDecl))], -- method name -> default impl
782 class_default_superclasses :: [PDecl],
783 class_params :: [Name],
784 class_instances :: [Name] }
787deriving instance Binary ClassInfo
788deriving instance NFData ClassInfo
791-- An argument is conditionally forceable iff its forceability
792-- depends on the collapsibility of the whole type.
793data Forceability = Conditional | Unconditional deriving (Show, Enum, Bounded, Eq, Ord)
796deriving instance Binary Forceability
797deriving instance NFData Forceability
800data OptInfo = Optimise { collapsible :: Bool,
802 -- The following should actually be (IntMap Forceability)
803 -- but the corresponding Binary instance seems to be broken.
804 -- Let's store a list and convert it to IntMap whenever needed.
805 forceable :: [(Int, Forceability)],
809deriving instance Binary OptInfo
810deriving instance NFData OptInfo
814data TypeInfo = TI { con_names :: [Name],
816 data_opts :: DataOpts,
820deriving instance Binary TypeInfo
821deriving instance NFData TypeInfo
824-- Syntactic sugar info
826data DSL' t = DSL { dsl_bind :: t,
831 index_first :: Maybe t,
832 index_next :: Maybe t,
833 dsl_lambda :: Maybe t,
836 deriving (Show, Functor)
838deriving instance Binary DSL'
839deriving instance NFData DSL'
844data SynContext = PatternSyntax | TermSyntax | AnySyntax
847deriving instance Binary SynContext
848deriving instance NFData SynContext
851data Syntax = Rule [SSymbol] PTerm SynContext
854deriving instance Binary Syntax
855deriving instance NFData Syntax
858data SSymbol = Keyword Name
865deriving instance Binary SSymbol
866deriving instance NFData SSymbol
869initDSL = DSL (PRef f (sUN ">>="))
870 (PRef f (sUN "return"))
872 (PRef f (sUN "pure"))
878 where f = fileFC "(builtin)"
880data Using = UImplicit Name PTerm
881 | UConstraint Name [Name]
884deriving instance Binary Using
885deriving instance NFData Using
888data SyntaxInfo = Syn { using :: [Using],
889 syn_params :: [(Name, PTerm)],
890 syn_namespace :: [String],
892 decoration :: Name -> Name,
894 implicitAllowed :: Bool,
898deriving instance NFData SyntaxInfo
899deriving instance Binary SyntaxInfo
902defaultSyntax = Syn [] [] [] [] id False False initDSL
904expandNS :: SyntaxInfo -> Name -> Name
905expandNS syn n@(NS _ _) = n
906expandNS syn n = case syn_namespace syn of
911--- Pretty printing declarations and terms
913instance Show PTerm where
914 show tm = showImp Nothing False False tm
916instance Pretty PTerm where
917 pretty = prettyImp False
919instance Show PDecl where
920 show d = showDeclImp False d
922instance Show PClause where
923 show c = showCImp True c
925instance Show PData where
926 show d = showDImp False d
928showDecls :: Bool -> [PDecl] -> String
930showDecls i (d:ds) = showDeclImp i d ++ "\n" ++ showDecls i ds
932showDeclImp _ (PFix _ f ops) = show f ++ " " ++ showSep ", " ops
933showDeclImp i (PTy _ _ _ _ n t) = "tydecl " ++ showCG n ++ " : " ++ showImp Nothing i False t
934showDeclImp i (PClauses _ _ n cs) = "pat " ++ showCG n ++ "\t" ++ showSep "\n\t" (map (showCImp i) cs)
935showDeclImp _ (PData _ _ _ _ d) = showDImp True d
936showDeclImp i (PParams _ ns ps) = "params {" ++ show ns ++ "\n" ++ showDecls i ps ++ "}\n"
937showDeclImp i (PNamespace n ps) = "namespace {" ++ n ++ "\n" ++ showDecls i ps ++ "}\n"
938showDeclImp _ (PSyntax _ syn) = "syntax " ++ show syn
939showDeclImp i (PClass _ _ _ cs n ps ds)
940 = "class " ++ show cs ++ " " ++ show n ++ " " ++ show ps ++ "\n" ++ showDecls i ds
941showDeclImp i (PInstance _ _ cs n _ t _ ds)
942 = "instance " ++ show cs ++ " " ++ show n ++ " " ++ show t ++ "\n" ++ showDecls i ds
943showDeclImp _ _ = "..."
944-- showDeclImp (PImport i) = "import " ++ i
947showCImp :: Bool -> PClause -> String
948showCImp impl (PClause _ n l ws r w)
949 = showImp Nothing impl False l ++ showWs ws ++ " = " ++ showImp Nothing impl False r
950 ++ " where " ++ show w
953 showWs (x : xs) = " | " ++ showImp Nothing impl False x ++ showWs xs
954showCImp impl (PWith _ n l ws r w)
955 = showImp Nothing impl False l ++ showWs ws ++ " with " ++ showImp Nothing impl False r
956 ++ " { " ++ show w ++ " } "
959 showWs (x : xs) = " | " ++ showImp Nothing impl False x ++ showWs xs
962showDImp :: Bool -> PData -> String
963showDImp impl (PDatadecl n ty cons)
964 = "data " ++ show n ++ " : " ++ showImp Nothing impl False ty ++ " where\n\t"
966 (map (\ (_, n, t, _, _) -> show n ++ " : " ++ showImp Nothing impl False t) cons)
968getImps :: [PArg] -> [(Name, PTerm)]
970getImps (PImp _ _ _ n tm _ : xs) = (n, tm) : getImps xs
971getImps (_ : xs) = getImps xs
973getExps :: [PArg] -> [PTerm]
975getExps (PExp _ _ tm _ : xs) = tm : getExps xs
976getExps (_ : xs) = getExps xs
978getConsts :: [PArg] -> [PTerm]
980getConsts (PConstraint _ _ tm _ : xs) = tm : getConsts xs
981getConsts (_ : xs) = getConsts xs
983getAll :: [PArg] -> [PTerm]
986-- | Pretty-print a high-level Idris term
987prettyImp :: Bool -- ^^ whether to show implicits
988 -> PTerm -- ^^ the term to pretty-print
990prettyImp impl = prettySe 10
992 prettySe p (PQuote r) =
993 if size r > breakingSize then
994 text "![" $$ pretty r <> text "]"
996 text "![" <> pretty r <> text "]"
997 prettySe p (PPatvar fc n) = pretty n
998 prettySe p (PRef fc n) =
1004 prettyBasic n@(UN _) = pretty n
1005 prettyBasic (MN _ s) = text (str s)
1006 prettyBasic (NS n s) = (foldr (<>) empty (intersperse (text ".") (map (text.str) $ reverse s))) <> prettyBasic n
1007 prettyBasic (SN sn) = text (show sn)
1008 prettySe p (PLam n ty sc) =
1010 if size sc > breakingSize then
1011 text "λ" <> pretty n <+> text "=>" $+$ pretty sc
1013 text "λ" <> pretty n <+> text "=>" <+> pretty sc
1014 prettySe p (PLet n ty v sc) =
1016 if size sc > breakingSize then
1017 text "let" <+> pretty n <+> text "=" <+> prettySe 10 v <+> text "in" $+$
1018 nest nestingSize (prettySe 10 sc)
1020 text "let" <+> pretty n <+> text "=" <+> prettySe 10 v <+> text "in" <+>
1022 prettySe p (PPi (Exp l s _ _) n ty sc)
1023 | n `elem` allNamesIn sc || impl =
1024 let open = if Lazy `elem` l then text "|" <> lparen else lparen in
1026 if size sc > breakingSize then
1027 open <> pretty n <+> colon <+> prettySe 10 ty <> rparen <+>
1028 st <+> text "->" $+$ prettySe 10 sc
1030 open <> pretty n <+> colon <+> prettySe 10 ty <> rparen <+>
1031 st <+> text "->" <+> prettySe 10 sc
1034 if size sc > breakingSize then
1035 prettySe 0 ty <+> st <+> text "->" $+$ prettySe 10 sc
1037 prettySe 0 ty <+> st <+> text "->" <+> prettySe 10 sc
1041 Static -> text "[static]"
1043 prettySe p (PPi (Imp l s _ _) n ty sc)
1045 let open = if Lazy `elem` l then text "|" <> lbrace else lbrace in
1047 if size sc > breakingSize then
1048 open <> pretty n <+> colon <+> prettySe 10 ty <> rbrace <+>
1049 st <+> text "->" <+> prettySe 10 sc
1051 open <> pretty n <+> colon <+> prettySe 10 ty <> rbrace <+>
1052 st <+> text "->" <+> prettySe 10 sc
1053 | otherwise = prettySe 10 sc
1057 Static -> text $ "[static]"
1059 prettySe p (PPi (Constraint _ _ _) n ty sc) =
1061 if size sc > breakingSize then
1062 prettySe 10 ty <+> text "=>" <+> prettySe 10 sc
1064 prettySe 10 ty <+> text "=>" $+$ prettySe 10 sc
1065 prettySe p (PPi (TacImp _ _ s _) n ty sc) =
1067 if size sc > breakingSize then
1068 lbrace <> text "tacimp" <+> pretty n <+> colon <+> prettySe 10 ty <>
1069 rbrace <+> text "->" $+$ prettySe 10 sc
1071 lbrace <> text "tacimp" <+> pretty n <+> colon <+> prettySe 10 ty <>
1072 rbrace <+> text "->" <+> prettySe 10 sc
1073 prettySe p (PApp _ (PRef _ f) [])
1074 | not impl = pretty f
1075 prettySe p (PAppBind _ (PRef _ f) [])
1076 | not impl = text "!" <+> pretty f
1077 prettySe p (PApp _ (PRef _ op@(UN nm)) args)
1079 length (getExps args) == 2 && (not impl) && (not $ isAlpha (thead nm)) =
1080 let [l, r] = getExps args in
1082 if size r > breakingSize then
1083 prettySe 1 l <+> pretty op $+$ prettySe 0 r
1085 prettySe 1 l <+> pretty op <+> prettySe 0 r
1086 prettySe p (PApp _ f as) =
1087 let args = getExps as in
1092 -- foldr (<+>) empty $ map prettyArgS as
1094 foldl' fSe empty args
1095 -- foldr (<+>) empty $ map prettyArgSe args
1098 if size r > breakingSize then
1099 l $+$ nest nestingSize (prettyArgS r)
1104 if size r > breakingSize then
1105 l $+$ nest nestingSize (prettyArgSe r)
1108 prettySe p (PCase _ scr opts) =
1109 text "case" <+> prettySe 10 scr <+> text "of" $+$ nest nestingSize prettyBody
1111 prettyBody = foldr ($$) empty $ intersperse (text "|") $ map sc opts
1113 sc (l, r) = prettySe 10 l <+> text "=>" <+> prettySe 10 r
1114 prettySe p (PHidden tm) = text "." <> prettySe 0 tm
1115 prettySe p (PRefl _ _) = text "refl"
1116 prettySe p (PResolveTC _) = text "resolvetc"
1117 prettySe p (PTrue _) = text "()"
1118 prettySe p (PFalse _) = text "_|_"
1119 prettySe p (PEq _ l r) =
1121 if size r > breakingSize then
1122 prettySe 10 l <+> text "=" $$ nest nestingSize (prettySe 10 r)
1124 prettySe 10 l <+> text "=" <+> prettySe 10 r
1125 prettySe p (PRewrite _ l r _) =
1127 if size r > breakingSize then
1128 text "rewrite" <+> prettySe 10 l <+> text "in" $$ nest nestingSize (prettySe 10 r)
1130 text "rewrite" <+> prettySe 10 l <+> text "in" <+> prettySe 10 r
1131 prettySe p (PTyped l r) =
1132 lparen <> prettySe 10 l <+> colon <+> prettySe 10 r <> rparen
1133 prettySe p (PPair _ l r) =
1134 if size r > breakingSize then
1135 lparen <> prettySe 10 l <> text "," $+$
1136 prettySe 10 r <> rparen
1138 lparen <> prettySe 10 l <> text "," <+> prettySe 10 r <> rparen
1139 prettySe p (PDPair _ l t r) =
1140 if size r > breakingSize then
1141 lparen <> prettySe 10 l <+> text "**" $+$
1142 prettySe 10 r <> rparen
1144 lparen <> prettySe 10 l <+> text "**" <+> prettySe 10 r <> rparen
1145 prettySe p (PAlternative a as) =
1146 lparen <> text "|" <> prettyAs <> text "|" <> rparen
1149 foldr (\l -> \r -> l <+> text "," <+> r) empty $ map (prettySe 10) as
1150 prettySe p PType = text "Type"
1151 prettySe p (PConstant c) = pretty c
1152 -- XXX: add pretty for tactics
1153 prettySe p (PProof ts) =
1154 text "proof" <+> lbrace $+$ nest nestingSize (text . show $ ts) $+$ rbrace
1155 prettySe p (PTactics ts) =
1156 text "tactics" <+> lbrace $+$ nest nestingSize (text . show $ ts) $+$ rbrace
1157 prettySe p (PMetavar n) = text "?" <> pretty n
1158 prettySe p (PReturn f) = text "return"
1159 prettySe p PImpossible = text "impossible"
1160 prettySe p Placeholder = text "_"
1161 prettySe p (PDoBlock _) = text "do block pretty not implemented"
1162 prettySe p (PElabError s) = pretty s
1164 prettySe p _ = text "test"
1166 prettyArgS (PImp _ _ _ n tm _) = prettyArgSi (n, tm)
1167 prettyArgS (PExp _ _ tm _) = prettyArgSe tm
1168 prettyArgS (PConstraint _ _ tm _) = prettyArgSc tm
1169 prettyArgS (PTacImplicit _ _ n _ tm _) = prettyArgSti (n, tm)
1171 prettyArgSe arg = prettySe 0 arg
1172 prettyArgSi (n, val) = lbrace <> pretty n <+> text "=" <+> prettySe 10 val <> rbrace
1173 prettyArgSc val = lbrace <> lbrace <> prettySe 10 val <> rbrace <> rbrace
1174 prettyArgSti (n, val) = lbrace <> text "auto" <+> pretty n <+> text "=" <+> prettySe 10 val <> rbrace
1176 bracket outer inner doc
1177 | inner > outer = lparen <> doc <> rparen
1181showName :: Maybe IState -- ^^ the Idris state, for information about names and colours
1182 -> [(Name, Bool)] -- ^^ the bound variables and whether they're implicit
1183 -> Bool -- ^^ whether to show implicits
1184 -> Bool -- ^^ whether to colourise
1185 -> Name -- ^^ the term to show
1187showName ist bnd impl colour n = case ist of
1188 Just i -> if colour then colourise n (idris_colourTheme i) else showbasic n
1189 Nothing -> showbasic n
1190 where name = if impl then show n else showbasic n
1191 showbasic n@(UN _) = showCG n
1192 showbasic (MN _ s) = str s
1193 showbasic (NS n s) = showSep "." (map str (reverse s)) ++ "." ++ showbasic n
1194 showbasic (SN s) = show s
1196 colourise n t = let ctxt' = fmap tt_ctxt ist in
1199 Just ctxt | Just impl <- lookup n bnd -> if impl then colouriseImplicit t name
1200 else colouriseBound t name
1201 | isDConName n ctxt -> colouriseData t name
1202 | isFnName n ctxt -> colouriseFun t name
1203 | isTConName n ctxt -> colouriseType t name
1204 -- The assumption is that if a name is not bound and does not exist in the
1205 -- global context, then we're somewhere in which implicit info has been lost
1206 -- (like error messages). Thus, unknown vars are colourised as implicits.
1207 | otherwise -> colouriseImplicit t name
1210showImp :: Maybe IState -- ^^ the Idris state, for information about identifiers and colours
1211 -> Bool -- ^^ whether to show implicits
1212 -> Bool -- ^^ whether to colourise
1213 -> PTerm -- ^^ the term to show
1215showImp ist impl colour tm = se 10 [] tm where
1216 perhapsColourise :: (ColourTheme -> String -> String) -> String -> String
1217 perhapsColourise col str = case ist of
1218 Just i -> if colour then col (idris_colourTheme i) str else str
1221 se :: Int -> [(Name, Bool)] -> PTerm -> String
1222 se p bnd (PQuote r) = "![" ++ show r ++ "]"
1223 se p bnd (PPatvar fc n) = if impl then show n ++ "[p]" else show n
1224 se p bnd (PInferRef fc n) = "!" ++ show n -- ++ "[" ++ show fc ++ "]"
1226 | Just str <- slist p bnd e = str
1227 | Just num <- snat p e = perhapsColourise colouriseData (show num)
1228 se p bnd (PRef fc n) = showName ist bnd impl colour n
1229 se p bnd (PLam n ty sc) = bracket p 2 $ "\\ " ++ perhapsColourise colouriseBound (show n) ++
1230 (if impl then " : " ++ se 10 bnd ty else "") ++ " => "
1231 ++ se 10 ((n, False):bnd) sc
1232 se p bnd (PLet n ty v sc) = bracket p 2 $ "let " ++ perhapsColourise colouriseBound (show n) ++
1233 " = " ++ se 10 bnd v ++
1234 " in " ++ se 10 ((n, False):bnd) sc
1235 se p bnd (PPi (Exp l s _ param) n ty sc)
1236 | n `elem` allNamesIn sc || impl
1238 (if Lazy `elem` l then "|(" else "(") ++
1239 perhapsColourise colouriseBound (show n) ++ " : " ++ se 10 bnd ty ++
1241 (if (impl && param) then "P" else "") ++
1243 "-> " ++ se 10 ((n, False):bnd) sc
1244 | otherwise = bracket p 2 $ se 0 bnd ty ++ " " ++ st ++ "-> " ++ se 10 bnd sc
1245 where st = case s of
1246 Static -> "[static] "
1248 se p bnd (PPi (Imp l s _ _) n ty sc)
1249 | impl = bracket p 2 $ (if Lazy `elem` l then "|{" else "{") ++
1250 perhapsColourise colouriseBound (show n) ++ " : " ++ se 10 bnd ty ++
1251 "} " ++ st ++ "-> " ++ se 10 ((n, True):bnd) sc
1252 | otherwise = se 10 ((n, True):bnd) sc
1253 where st = case s of
1254 Static -> "[static] "
1256 se p bnd (PPi (Constraint _ _ _) n ty sc)
1257 = bracket p 2 $ se 10 bnd ty ++ " => " ++ se 10 bnd sc
1258 se p bnd (PPi (TacImp _ _ s _) n ty sc)
1260 "{tacimp " ++ (perhapsColourise colouriseBound (show n)) ++ " : " ++ se 10 bnd ty ++ "} -> " ++
1261 se 10 ((n, False):bnd) sc
1262 se p bnd (PMatchApp _ f) = "match " ++ show f
1263 se p bnd (PApp _ hd@(PRef fc f) [tm])
1264 | PConstant (Idris.Core.TT.Str str) <- getTm tm,
1265 f == sUN "Symbol_" = "'" ++ se 10 bnd (PRef fc (sUN str))
1266 se p bnd (PApp _ hd@(PRef _ f) [])
1267 | not impl = se p bnd hd
1268 se p bnd (PAppBind _ hd@(PRef _ f) [])
1269 | not impl = "!" ++ se p bnd hd
1270 se p bnd (PApp _ op@(PRef _ (UN nm)) args)
1272 length (getExps args) == 2 && not impl && not (isAlpha (thead nm))
1273 = let [l, r] = getExps args in
1274 bracket p 1 $ se 1 bnd l ++ " " ++ se p bnd op ++ " " ++ se 0 bnd r
1275 se p bnd (PApp _ f as)
1276 = -- let args = getExps as in
1277 bracket p 1 $ se 1 bnd f ++
1278 if impl then concatMap (sArg bnd) as
1279 else concatMap (suiArg impl bnd) as
1280 se p bnd (PAppBind _ f as)
1281 = let args = getExps as in
1282 "!" ++ (bracket p 1 $ se 1 bnd f ++ if impl then concatMap (sArg bnd) as
1283 else concatMap (seArg bnd) args)
1284 se p bnd (PCase _ scr opts) = "case " ++ se 10 bnd scr ++ " of " ++ showSep " | " (map sc opts)
1285 where sc (l, r) = se 10 bnd l ++ " => " ++ se 10 bnd r
1286 se p bnd (PHidden tm) = "." ++ se 0 bnd tm
1287 se p bnd (PRefl _ t)
1288 | not impl = perhapsColourise colouriseData "refl"
1289 | otherwise = perhapsColourise colouriseData $ "refl {" ++ se 10 bnd t ++ "}"
1290 se p bnd (PResolveTC _) = "resolvetc"
1291 se p bnd (PTrue _) = perhapsColourise colouriseType "()"
1292 se p bnd (PFalse _) = perhapsColourise colouriseType "_|_"
1293 se p bnd (PEq _ l r) = bracket p 2 $ se 10 bnd l ++ perhapsColourise colouriseType " = " ++ se 10 bnd r
1294 se p bnd (PRewrite _ l r _) = bracket p 2 $ "rewrite " ++ se 10 bnd l ++ " in " ++ se 10 bnd r
1295 se p bnd (PTyped l r) = "(" ++ se 10 bnd l ++ " : " ++ se 10 bnd r ++ ")"
1296 se p bnd (PPair _ l r) = "(" ++ se 10 bnd l ++ ", " ++ se 10 bnd r ++ ")"
1297 se p bnd (PDPair _ l t r) = "(" ++ se 10 bnd l ++ " ** " ++ se 10 bnd r ++ ")"
1298 se p bnd (PAlternative a as) = "(|" ++ showSep " , " (map (se 10 bnd) as) ++ "|)"
1299 se p bnd PType = perhapsColourise colouriseType "Type"
1300 se p bnd (PConstant c) = perhapsColourise (cfun c) (show c)
1301 where cfun (AType _) = colouriseType
1302 cfun StrType = colouriseType
1303 cfun PtrType = colouriseType
1304 cfun VoidType = colouriseType
1305 cfun _ = colouriseData
1306 se p bnd (PProof ts) = "proof { " ++ show ts ++ "}"
1307 se p bnd (PTactics ts) = "tactics { " ++ show ts ++ "}"
1308 se p bnd (PMetavar n) = "?" ++ show n
1309 se p bnd (PReturn f) = "return"
1310 se p bnd PImpossible = "impossible"
1311 se p bnd Placeholder = "_"
1312 se p bnd (PDoBlock _) = "do block show not implemented"
1313 se p bnd (PElabError s) = show s
1314 se p bnd (PCoerced t) = se p bnd t
1315 se p bnd (PUnifyLog t) = "%unifyLog " ++ se p bnd t
1316 se p bnd (PDisamb ns t) = "%disamb " ++ show ns ++ se p bnd t
1317 se p bnd (PNoImplicits t) = "%noimplicit " ++ se p bnd t
1318-- se p bnd x = "Not implemented"
1320 slist' p bnd (PApp _ (PRef _ nil) _)
1321 | not impl && nsroot nil == sUN "Nil" = Just []
1322 slist' p bnd (PApp _ (PRef _ cons) args)
1323 | nsroot cons == sUN "::",
1324 (PExp {getTm=tl}):(PExp {getTm=hd}):imps <- reverse args,
1326 Just tl' <- slist' p bnd tl
1329 isImp (PImp {}) = True
1331 slist' _ _ _ = Nothing
1333 slist p bnd e | Just es <- slist' p bnd e = Just $
1334 case es of [] -> "[]"
1335 [x] -> "[" ++ se p bnd x ++ "]"
1336 xs -> "[" ++ intercalate "," (map (se p bnd ) xs) ++ "]"
1337 slist _ _ _ = Nothing
1339 -- since Prelude is always imported, S & Z are unqualified iff they're the
1342 | show o == (natns++"Z") || show o == "Z" = Just 0
1343 snat p (PApp _ s [PExp {getTm=n}])
1344 | show s == (natns++"S") || show s == "S",
1349 natns = "Prelude.Nat."
1351 sArg bnd (PImp _ _ _ n tm _) = siArg bnd (n, tm)
1352 sArg bnd (PExp _ _ tm _) = seArg bnd tm
1353 sArg bnd (PConstraint _ _ tm _) = scArg bnd tm
1354 sArg bnd (PTacImplicit _ _ n _ tm _) = stiArg bnd (n, tm)
1356 -- show argument, implicits given by the user also shown
1357 suiArg impl bnd (PImp _ mi _ n tm _)
1358 | impl || not mi = siArg bnd (n, tm)
1359 suiArg impl bnd (PExp _ _ tm _) = seArg bnd tm
1360 suiArg impl bnd _ = ""
1362 seArg bnd arg = " " ++ se 0 bnd arg
1363 siArg bnd (n, val) =
1365 val' = se 10 bnd val in
1367 then " {" ++ n' ++ "}"
1368 else " {" ++ n' ++ " = " ++ val' ++ "}"
1369 scArg bnd val = " {{" ++ se 10 bnd val ++ "}}"
1370 stiArg bnd (n, val) = " {auto " ++ show n ++ " = " ++ se 10 bnd val ++ "}"
1372 bracket outer inner str | inner > outer = "(" ++ str ++ ")"
1376instance Sized PTerm where
1377 size (PQuote rawTerm) = size rawTerm
1378 size (PRef fc name) = size name
1379 size (PLam name ty bdy) = 1 + size ty + size bdy
1380 size (PPi plicity name ty bdy) = 1 + size ty + size bdy
1381 size (PLet name ty def bdy) = 1 + size ty + size def + size bdy
1382 size (PTyped trm ty) = 1 + size trm + size ty
1383 size (PApp fc name args) = 1 + size args
1384 size (PAppBind fc name args) = 1 + size args
1385 size (PCase fc trm bdy) = 1 + size trm + size bdy
1387 size (PFalse fc) = 1
1388 size (PRefl fc _) = 1
1389 size (PResolveTC fc) = 1
1390 size (PEq fc left right) = 1 + size left + size right
1391 size (PRewrite fc left right _) = 1 + size left + size right
1392 size (PPair fc left right) = 1 + size left + size right
1393 size (PDPair fs left ty right) = 1 + size left + size ty + size right
1394 size (PAlternative a alts) = 1 + size alts
1395 size (PHidden hidden) = size hidden
1396 size (PUnifyLog tm) = size tm
1397 size (PDisamb _ tm) = size tm
1398 size (PNoImplicits tm) = size tm
1400 size (PConstant const) = 1 + size const
1401 size Placeholder = 1
1402 size (PDoBlock dos) = 1 + size dos
1403 size (PIdiom fc term) = 1 + size term
1404 size (PReturn fc) = 1
1405 size (PMetavar name) = 1
1406 size (PProof tactics) = size tactics
1407 size (PElabError err) = size err
1408 size PImpossible = 1
1410getPArity :: PTerm -> Int
1411getPArity (PPi _ _ _ sc) = 1 + getPArity sc
1414-- Return all names, free or globally bound, in the given term.
1416allNamesIn :: PTerm -> [Name]
1417allNamesIn tm = nub $ ni [] tm
1420 | not (n `elem` env) = [n]
1421 ni env (PPatvar _ n) = [n]
1422 ni env (PApp _ f as) = ni env f ++ concatMap (ni env) (map getTm as)
1423 ni env (PAppBind _ f as) = ni env f ++ concatMap (ni env) (map getTm as)
1424 ni env (PCase _ c os) = ni env c ++ concatMap (ni env) (map snd os)
1425 ni env (PLam n ty sc) = ni env ty ++ ni (n:env) sc
1426 ni env (PPi _ n ty sc) = ni env ty ++ ni (n:env) sc
1427 ni env (PHidden tm) = ni env tm
1428 ni env (PEq _ l r) = ni env l ++ ni env r
1429 ni env (PRewrite _ l r _) = ni env l ++ ni env r
1430 ni env (PTyped l r) = ni env l ++ ni env r
1431 ni env (PPair _ l r) = ni env l ++ ni env r
1432 ni env (PDPair _ (PRef _ n) t r) = ni env t ++ ni (n:env) r
1433 ni env (PDPair _ l t r) = ni env l ++ ni env t ++ ni env r
1434 ni env (PAlternative a ls) = concatMap (ni env) ls
1435 ni env (PUnifyLog tm) = ni env tm
1436 ni env (PDisamb _ tm) = ni env tm
1437 ni env (PNoImplicits tm) = ni env tm
1440-- Return all names defined in binders in the given term
1441boundNamesIn :: PTerm -> [Name]
1442boundNamesIn tm = nub $ ni tm
1444 ni (PApp _ f as) = ni f ++ concatMap (ni) (map getTm as)
1445 ni (PAppBind _ f as) = ni f ++ concatMap (ni) (map getTm as)
1446 ni (PCase _ c os) = ni c ++ concatMap (ni) (map snd os)
1447 ni (PLam n ty sc) = n : (ni ty ++ ni sc)
1448 ni (PLet n ty val sc) = n : (ni ty ++ ni val ++ ni sc)
1449 ni (PPi _ n ty sc) = n : (ni ty ++ ni sc)
1450 ni (PEq _ l r) = ni l ++ ni r
1451 ni (PRewrite _ l r _) = ni l ++ ni r
1452 ni (PTyped l r) = ni l ++ ni r
1453 ni (PPair _ l r) = ni l ++ ni r
1454 ni (PDPair _ (PRef _ n) t r) = ni t ++ ni r
1455 ni (PDPair _ l t r) = ni l ++ ni t ++ ni r
1456 ni (PAlternative a as) = concatMap (ni) as
1457 ni (PHidden tm) = ni tm
1458 ni (PUnifyLog tm) = ni tm
1459 ni (PDisamb _ tm) = ni tm
1460 ni (PNoImplicits tm) = ni tm
1463-- Return names which are free in the given term.
1464namesIn :: [(Name, PTerm)] -> IState -> PTerm -> [Name]
1465namesIn uvars ist tm = nub $ ni [] tm
1468 | not (n `elem` env)
1469 = case lookupTy n (tt_ctxt ist) of
1471 _ -> if n `elem` (map fst uvars) then [n] else []
1472 ni env (PApp _ f as) = ni env f ++ concatMap (ni env) (map getTm as)
1473 ni env (PAppBind _ f as) = ni env f ++ concatMap (ni env) (map getTm as)
1474 ni env (PCase _ c os) = ni env c ++ concatMap (ni env) (map snd os)
1475 ni env (PLam n ty sc) = ni env ty ++ ni (n:env) sc
1476 ni env (PPi _ n ty sc) = ni env ty ++ ni (n:env) sc
1477 ni env (PEq _ l r) = ni env l ++ ni env r
1478 ni env (PRewrite _ l r _) = ni env l ++ ni env r
1479 ni env (PTyped l r) = ni env l ++ ni env r
1480 ni env (PPair _ l r) = ni env l ++ ni env r
1481 ni env (PDPair _ (PRef _ n) t r) = ni env t ++ ni (n:env) r
1482 ni env (PDPair _ l t r) = ni env l ++ ni env t ++ ni env r
1483 ni env (PAlternative a as) = concatMap (ni env) as
1484 ni env (PHidden tm) = ni env tm
1485 ni env (PUnifyLog tm) = ni env tm
1486 ni env (PDisamb _ tm) = ni env tm
1487 ni env (PNoImplicits tm) = ni env tm
1490-- Return which of the given names are used in the given term.
1492usedNamesIn :: [Name] -> IState -> PTerm -> [Name]
1493usedNamesIn vars ist tm = nub $ ni [] tm
1496 | n `elem` vars && not (n `elem` env)
1497 = case lookupTy n (tt_ctxt ist) of
1500 ni env (PApp _ f as) = ni env f ++ concatMap (ni env) (map getTm as)
1501 ni env (PAppBind _ f as) = ni env f ++ concatMap (ni env) (map getTm as)
1502 ni env (PCase _ c os) = ni env c ++ concatMap (ni env) (map snd os)
1503 ni env (PLam n ty sc) = ni env ty ++ ni (n:env) sc
1504 ni env (PPi _ n ty sc) = ni env ty ++ ni (n:env) sc
1505 ni env (PEq _ l r) = ni env l ++ ni env r
1506 ni env (PRewrite _ l r _) = ni env l ++ ni env r
1507 ni env (PTyped l r) = ni env l ++ ni env r
1508 ni env (PPair _ l r) = ni env l ++ ni env r
1509 ni env (PDPair _ (PRef _ n) t r) = ni env t ++ ni (n:env) r
1510 ni env (PDPair _ l t r) = ni env l ++ ni env t ++ ni env r
1511 ni env (PAlternative a as) = concatMap (ni env) as
1512 ni env (PHidden tm) = ni env tm
1513 ni env (PUnifyLog tm) = ni env tm
1514 ni env (PDisamb _ tm) = ni env tm
1515 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