1{-# LANGUAGE MultiParamTypeClasses, FlexibleInstances, DeriveFunctor,
2 TypeSynonymInstances, PatternGuards #-}
4module Idris.AbsSyntaxTree where
8import Core.Elaborate hiding (Tactic(..))
15import System.Console.Haskeline
17import Control.Monad.State
25data IOption = IOption { opt_logLevel :: Int,
27 opt_typeintype :: Bool,
30 opt_errContext :: Bool,
33 opt_ibcsubdir :: FilePath,
34 opt_importdirs :: [FilePath]
38defaultOpts = IOption 0 False False True False False True True "" []
40-- TODO: Add 'module data' to IState, which can be saved out and reloaded quickly (i.e
41-- without typechecking).
42-- This will include all the functions and data declarations, plus fixity declarations
45data IState = IState { tt_ctxt :: Context,
46 idris_constraints :: [(UConstraint, FC)],
47 idris_infixes :: [FixDecl],
48 idris_implicits :: Ctxt [PArg],
49 idris_statics :: Ctxt [Bool],
50 idris_classes :: Ctxt ClassInfo,
51 idris_dsls :: Ctxt DSL,
52 idris_optimisation :: Ctxt OptInfo,
53 idris_datatypes :: Ctxt TypeInfo,
54 idris_patdefs :: Ctxt [([Name], Term, Term)], -- not exported
55 idris_flags :: Ctxt [FnOpt],
56 idris_callgraph :: Ctxt [Name],
57 idris_calledgraph :: Ctxt [Name],
58 idris_totcheck :: [(FC, Name)],
60 idris_options :: IOption,
62 idris_metavars :: [Name],
63 syntax_rules :: [Syntax],
64 syntax_keywords :: [String],
65 imported :: [FilePath],
66 idris_scprims :: [(Name, (Int, PrimFn))],
67 idris_objs :: [FilePath],
68 idris_libs :: [String],
69 idris_hdrs :: [String],
70 proof_list :: [(Name, [String])],
72 lastParse :: Maybe Name,
73 indent_stack :: [Int],
74 brace_stack :: [Maybe Int],
75 hide_list :: [(Name, Maybe Accessibility)],
76 default_access :: Accessibility,
77 ibc_write :: [IBCWrite],
78 compiled_so :: Maybe String
81primDefs = [UN "unsafePerformIO", UN "mkLazyForeign", UN "mkForeign", UN "FalseElim"]
83-- information that needs writing for the current module's .ibc file
84data IBCWrite = IBCFix FixDecl
88 | IBCInstance Bool Name Name
98 | IBCAccess Name Accessibility
99 | IBCTotal Name Totality
100 | IBCFlags Name [FnOpt]
102 | IBCDef Name -- i.e. main context
105idrisInit = IState initContext [] [] emptyContext emptyContext emptyContext
106 emptyContext emptyContext emptyContext emptyContext
107 emptyContext emptyContext emptyContext
108 [] "" defaultOpts 6 [] [] [] [] [] [] [] []
109 [] Nothing Nothing [] [] [] Hidden [] Nothing
111-- The monad for the main REPL - reading and processing files and updating
112-- global state (hence the IO inner monad).
113type Idris = StateT IState (InputT IO)
115-- Commands in the REPL
117data Target = ViaC | ViaJava
126 | Compile Target String
149data Opt = Filename String
178-- Parsed declarations
180data Fixity = Infixl { prec :: Int }
181 | Infixr { prec :: Int }
182 | InfixN { prec :: Int }
183 | PrefixN { prec :: Int }
186deriving instance Binary Fixity
189instance Show Fixity where
190 show (Infixl i) = "infixl " ++ show i
191 show (Infixr i) = "infixr " ++ show i
192 show (InfixN i) = "infix " ++ show i
193 show (PrefixN i) = "prefix " ++ show i
195data FixDecl = Fix Fixity String
198deriving instance Binary FixDecl
201instance Ord FixDecl where
202 compare (Fix x _) (Fix y _) = compare (prec x) (prec y)
205data Static = Static | Dynamic
208deriving instance Binary Static
211-- Mark bindings with their explicitness, and laziness
212data Plicity = Imp { plazy :: Bool,
214 | Exp { plazy :: Bool,
216 | Constraint { plazy :: Bool,
218 | TacImp { plazy :: Bool,
224deriving instance Binary Plicity
227impl = Imp False Dynamic
228expl = Exp False Dynamic
229constraint = Constraint False Dynamic
230tacimpl = TacImp False Dynamic
232data FnOpt = Inlinable | TotalFn | AssertTotal | TCGen
233 | CExport String -- export, with a C name
234 | Specialise [Name] -- specialise it, freeze these names
237deriving instance Binary FnOpt
242inlinable :: FnOpts -> Bool
243inlinable = elem Inlinable
245data PDecl' t = PFix FC Fixity [String] -- fixity declaration
246 | PTy SyntaxInfo FC FnOpts Name t -- type declaration
247 | PClauses FC FnOpts Name [PClause' t] -- pattern clause
248 | PCAF FC Name t -- top level constant
249 | PData SyntaxInfo FC (PData' t) -- data declaration
250 | PParams FC [(Name, t)] [PDecl' t] -- params block
251 | PNamespace String [PDecl' t] -- new namespace
252 | PRecord SyntaxInfo FC Name t Name t -- record declaration
253 | PClass SyntaxInfo FC
256 [(Name, t)] -- parameters
257 [PDecl' t] -- declarations
258 | PInstance SyntaxInfo FC [t] -- constraints
261 t -- full instance type
262 (Maybe Name) -- explicit name
266 | PDirective (Idris ())
269deriving instance Binary PDecl'
272data PClause' t = PClause FC Name t [t] t [PDecl' t]
273 | PWith FC Name t [t] t [PDecl' t]
274 | PClauseR FC [t] t [PDecl' t]
275 | PWithR FC [t] t [PDecl' t]
278deriving instance Binary PClause'
281data PData' t = PDatadecl { d_name :: Name,
283 d_cons :: [(Name, t, FC)] }
286deriving instance Binary PData'
289-- Handy to get a free function for applying PTerm -> PTerm functions
290-- across a program, by deriving Functor
292type PDecl = PDecl' PTerm
293type PData = PData' PTerm
294type PClause = PClause' PTerm
296-- get all the names declared in a decl
298declared :: PDecl -> [Name]
299declared (PFix _ _ _) = []
300declared (PTy _ _ _ n t) = [n]
301declared (PClauses _ _ n _) = [] -- not a declaration
302declared (PData _ _ (PDatadecl n _ ts)) = n : map fstt ts
303 where fstt (a, _, _) = a
304declared (PParams _ _ ds) = concatMap declared ds
305declared (PNamespace _ ds) = concatMap declared ds
306-- declared (PImport _) = []
308defined :: PDecl -> [Name]
309defined (PFix _ _ _) = []
310defined (PTy _ _ _ n t) = []
311defined (PClauses _ _ n _) = [n] -- not a declaration
312defined (PData _ _ (PDatadecl n _ ts)) = n : map fstt ts
313 where fstt (a, _, _) = a
314defined (PParams _ _ ds) = concatMap defined ds
315defined (PNamespace _ ds) = concatMap defined ds
316-- declared (PImport _) = []
318updateN :: [(Name, Name)] -> Name -> Name
319updateN ns n | Just n' <- lookup n ns = n'
322updateNs :: [(Name, Name)] -> PTerm -> PTerm
324updateNs ns t = mapPT updateRef t
325 where updateRef (PRef fc f) = PRef fc (updateN ns f)
328-- updateDNs :: [(Name, Name)] -> PDecl -> PDecl
330-- updateDNs ns (PTy s f n t) | Just n' <- lookup n ns = PTy s f n' t
331-- updateDNs ns (PClauses f n c) | Just n' <- lookup n ns = PClauses f n' (map updateCNs c)
332-- where updateCNs ns (PClause n l ts r ds)
333-- = PClause (updateN ns n) (fmap (updateNs ns) l)
334-- (map (fmap (updateNs ns)) ts)
335-- (fmap (updateNs ns) r)
336-- (map (updateDNs ns) ds)
339-- High level language terms
341data PTerm = PQuote Raw
343 | PLam Name PTerm PTerm
344 | PPi Plicity Name PTerm PTerm
345 | PLet Name PTerm PTerm PTerm
346 | PTyped PTerm PTerm -- term with explicit type
347 | PApp FC PTerm [PArg]
348 | PCase FC PTerm [(PTerm, PTerm)]
354 | PPair FC PTerm PTerm
355 | PDPair FC PTerm PTerm PTerm
356 | PAlternative Bool [PTerm] -- True if only one may work
357 | PHidden PTerm -- irrelevant or hidden pattern
366 | PTactics [PTactic] -- as PProof, but no auto solving
367 | PElabError Err -- error to report on elaboration
368 | PImpossible -- special case for declaring when an LHS can't typecheck
371deriving instance Binary PTerm
374mapPT :: (PTerm -> PTerm) -> PTerm -> PTerm
375mapPT f t = f (mpt t) where
376 mpt (PLam n t s) = PLam n (mapPT f t) (mapPT f s)
377 mpt (PPi p n t s) = PPi p n (mapPT f t) (mapPT f s)
378 mpt (PLet n ty v s) = PLet n (mapPT f ty) (mapPT f v) (mapPT f s)
379 mpt (PApp fc t as) = PApp fc (mapPT f t) (map (fmap (mapPT f)) as)
380 mpt (PCase fc c os) = PCase fc (mapPT f c) (map (pmap (mapPT f)) os)
381 mpt (PEq fc l r) = PEq fc (mapPT f l) (mapPT f r)
382 mpt (PTyped l r) = PTyped (mapPT f l) (mapPT f r)
383 mpt (PPair fc l r) = PPair fc (mapPT f l) (mapPT f r)
384 mpt (PDPair fc l t r) = PDPair fc (mapPT f l) (mapPT f t) (mapPT f r)
385 mpt (PAlternative a as) = PAlternative a (map (mapPT f) as)
386 mpt (PHidden t) = PHidden (mapPT f t)
387 mpt (PDoBlock ds) = PDoBlock (map (fmap (mapPT f)) ds)
388 mpt (PProof ts) = PProof (map (fmap (mapPT f)) ts)
389 mpt (PTactics ts) = PTactics (map (fmap (mapPT f)) ts)
393data PTactic' t = Intro [Name] | Intros | Focus Name
394 | Refine Name [Bool] | Rewrite t | LetTac Name t
395 | Exact t | Compute | Trivial
398 | ProofState | ProofTerm | Undo
399 | Try (PTactic' t) (PTactic' t)
400 | TSeq (PTactic' t) (PTactic' t)
402 deriving (Show, Eq, Functor)
404deriving instance Binary PTactic'
407instance Sized a => Sized (PTactic' a) where
408 size (Intro nms) = 1 + size nms
410 size (Focus nm) = 1 + size nm
411 size (Refine nm bs) = 1 + size nm + length bs
412 size (Rewrite t) = 1 + size t
413 size (LetTac nm t) = 1 + size nm + size t
414 size (Exact t) = 1 + size t
422 size (Try l r) = 1 + size l + size r
423 size (TSeq l r) = 1 + size l + size r
427type PTactic = PTactic' PTerm
429data PDo' t = DoExp FC t
434 deriving (Eq, Functor)
436deriving instance Binary PDo'
439instance Sized a => Sized (PDo' a) where
440 size (DoExp fc t) = 1 + size fc + size t
441 size (DoBind fc nm t) = 1 + size fc + size nm + size t
442 size (DoBindP fc l r) = 1 + size fc + size l + size r
443 size (DoLet fc nm l r) = 1 + size fc + size nm + size l + size r
444 size (DoLetP fc l r) = 1 + size fc + size l + size r
448-- The priority gives a hint as to elaboration order. Best to elaborate
449-- things early which will help give a more concrete type to other
450-- variables, e.g. a before (interpTy a).
452data PArg' t = PImp { priority :: Int,
453 lazyarg :: Bool, pname :: Name, getTm :: t }
454 | PExp { priority :: Int,
455 lazyarg :: Bool, getTm :: t }
456 | PConstraint { priority :: Int,
457 lazyarg :: Bool, getTm :: t }
458 | PTacImplicit { priority :: Int,
459 lazyarg :: Bool, pname :: Name,
462 deriving (Show, Eq, Functor)
464instance Sized a => Sized (PArg' a) where
465 size (PImp p l nm trm) = 1 + size nm + size trm
466 size (PExp p l trm) = 1 + size trm
467 size (PConstraint p l trm) = 1 + size trm
468 size (PTacImplicit p l nm scr trm) = 1 + size nm + size scr + size trm
471deriving instance Binary PArg'
476pconst = PConstraint 0 False
477ptacimp = PTacImplicit 0 True
479type PArg = PArg' PTerm
483data ClassInfo = CI { instanceName :: Name,
484 class_methods :: [(Name, (FnOpts, PTerm))],
485 class_defaults :: [(Name, (Name, PDecl))], -- method name -> default impl
486 class_params :: [Name],
487 class_instances :: [Name] }
490deriving instance Binary ClassInfo
493data OptInfo = Optimise { collapsible :: Bool,
494 forceable :: [Int], -- argument positions
498deriving instance Binary OptInfo
502data TypeInfo = TI { con_names :: [Name] }
505deriving instance Binary TypeInfo
508-- Syntactic sugar info
510data DSL' t = DSL { dsl_bind :: t,
515 index_first :: Maybe t,
516 index_next :: Maybe t,
517 dsl_lambda :: Maybe t,
520 deriving (Show, Functor)
522deriving instance Binary DSL'
527data SynContext = PatternSyntax | TermSyntax | AnySyntax
530deriving instance Binary SynContext
533data Syntax = Rule [SSymbol] PTerm SynContext
536deriving instance Binary Syntax
539data SSymbol = Keyword Name
546deriving instance Binary SSymbol
549initDSL = DSL (PRef f (UN ">>="))
550 (PRef f (UN "return"))
558 where f = FC "(builtin)" 0
560data SyntaxInfo = Syn { using :: [(Name, PTerm)],
561 syn_params :: [(Name, PTerm)],
562 syn_namespace :: [String],
564 decoration :: Name -> Name,
566 implicitAllowed :: Bool,
570deriving instance Binary SyntaxInfo
573defaultSyntax = Syn [] [] [] [] id False False initDSL
575expandNS :: SyntaxInfo -> Name -> Name
576expandNS syn n@(NS _ _) = n
577expandNS syn n = case syn_namespace syn of
582--- Pretty printing declarations and terms
584instance Show PTerm where
585 show tm = showImp False tm
587instance Pretty PTerm where
588 pretty = prettyImp False
590instance Show PDecl where
591 show d = showDeclImp False d
593instance Show PClause where
594 show c = showCImp True c
596instance Show PData where
597 show d = showDImp False d
599showDeclImp _ (PFix _ f ops) = show f ++ " " ++ showSep ", " ops
600showDeclImp t (PTy _ _ _ n ty) = show n ++ " : " ++ showImp t ty
601showDeclImp _ (PClauses _ _ n c) = showSep "\n" (map show c)
602showDeclImp _ (PData _ _ d) = show d
604showCImp :: Bool -> PClause -> String
605showCImp impl (PClause _ n l ws r w)
606 = showImp impl l ++ showWs ws ++ " = " ++ showImp impl r
607 ++ " where " ++ show w
610 showWs (x : xs) = " | " ++ showImp impl x ++ showWs xs
611showCImp impl (PWith _ n l ws r w)
612 = showImp impl l ++ showWs ws ++ " with " ++ showImp impl r
613 ++ " { " ++ show w ++ " } "
616 showWs (x : xs) = " | " ++ showImp impl x ++ showWs xs
619showDImp :: Bool -> PData -> String
620showDImp impl (PDatadecl n ty cons)
621 = "data " ++ show n ++ " : " ++ showImp impl ty ++ " where\n\t"
623 (map (\ (n, t, _) -> show n ++ " : " ++ showImp impl t) cons)
625getImps :: [PArg] -> [(Name, PTerm)]
627getImps (PImp _ _ n tm : xs) = (n, tm) : getImps xs
628getImps (_ : xs) = getImps xs
630getExps :: [PArg] -> [PTerm]
632getExps (PExp _ _ tm : xs) = tm : getExps xs
633getExps (_ : xs) = getExps xs
635getConsts :: [PArg] -> [PTerm]
637getConsts (PConstraint _ _ tm : xs) = tm : getConsts xs
638getConsts (_ : xs) = getConsts xs
640getAll :: [PArg] -> [PTerm]
643prettyImp :: Bool -> PTerm -> Doc
644prettyImp impl = prettySe 10
646 prettySe p (PQuote r) =
647 if size r > breakingSize then
648 text "![" $$ pretty r <> text "]"
650 text "![" <> pretty r <> text "]"
651 prettySe p (PRef fc n) =
657 prettyBasic n@(UN _) = pretty n
658 prettyBasic (MN _ s) = text s
659 prettyBasic (NS n s) = (foldr (<>) empty (intersperse (text ".") (map text $ reverse s))) <> prettyBasic n
660 prettySe p (PLam n ty sc) =
662 if size sc > breakingSize then
663 text "λ" <> pretty n <+> text "=>" $+$ pretty sc
665 text "λ" <> pretty n <+> text "=>" <+> pretty sc
666 prettySe p (PLet n ty v sc) =
668 if size sc > breakingSize then
669 text "let" <+> pretty n <+> text "=" <+> prettySe 10 v <+> text "in" $+$
670 nest nestingSize (prettySe 10 sc)
672 text "let" <+> pretty n <+> text "=" <+> prettySe 10 v <+> text "in" <+>
674 prettySe p (PPi (Exp l s) n ty sc)
675 | n `elem` allNamesIn sc || impl =
676 let open = if l then text "|" <> lparen else lparen in
678 if size sc > breakingSize then
679 open <> pretty n <+> colon <+> prettySe 10 ty <> rparen <+>
680 st <+> text "->" $+$ prettySe 10 sc
682 open <> pretty n <+> colon <+> prettySe 10 ty <> rparen <+>
683 st <+> text "->" <+> prettySe 10 sc
686 if size sc > breakingSize then
687 prettySe 0 ty <+> st <+> text "->" $+$ prettySe 10 sc
689 prettySe 0 ty <+> st <+> text "->" <+> prettySe 10 sc
693 Static -> text "[static]"
695 prettySe p (PPi (Imp l s) n ty sc)
697 let open = if l then text "|" <> lbrace else lbrace in
699 if size sc > breakingSize then
700 open <> pretty n <+> colon <+> prettySe 10 ty <> rbrace <+>
701 st <+> text "->" <+> prettySe 10 sc
703 open <> pretty n <+> colon <+> prettySe 10 ty <> rbrace <+>
704 st <+> text "->" <+> prettySe 10 sc
705 | otherwise = prettySe 10 sc
709 Static -> text $ "[static]"
711 prettySe p (PPi (Constraint _ _) n ty sc) =
713 if size sc > breakingSize then
714 prettySe 10 ty <+> text "=>" <+> prettySe 10 sc
716 prettySe 10 ty <+> text "=>" $+$ prettySe 10 sc
717 prettySe p (PPi (TacImp _ _ s) n ty sc) =
719 if size sc > breakingSize then
720 lbrace <> text "tacimp" <+> pretty n <+> colon <+> prettySe 10 ty <>
721 rbrace <+> text "->" $+$ prettySe 10 sc
723 lbrace <> text "tacimp" <+> pretty n <+> colon <+> prettySe 10 ty <>
724 rbrace <+> text "->" <+> prettySe 10 sc
725 prettySe p (PApp _ (PRef _ f) [])
726 | not impl = pretty f
727 prettySe p (PApp _ (PRef _ op@(UN (f:_))) args)
728 | length (getExps args) == 2 && (not impl) && (not $ isAlpha f) =
729 let [l, r] = getExps args in
731 if size r > breakingSize then
732 prettySe 1 l <+> pretty op $+$ prettySe 0 r
734 prettySe 1 l <+> pretty op <+> prettySe 0 r
735 prettySe p (PApp _ f as) =
736 let args = getExps as in
741 -- foldr (<+>) empty $ map prettyArgS as
744 -- foldr (<+>) empty $ map prettyArgSe args
747 if size r > breakingSize then
748 l $+$ nest nestingSize (prettyArgS r)
753 if size r > breakingSize then
754 l $+$ nest nestingSize (prettyArgSe r)
757 prettySe p (PCase _ scr opts) =
758 text "case" <+> prettySe 10 scr <+> text "of" $+$ nest nestingSize prettyBody
760 prettyBody = foldr ($$) empty $ intersperse (text "|") $ map sc opts
762 sc (l, r) = prettySe 10 l <+> text "=>" <+> prettySe 10 r
763 prettySe p (PHidden tm) = text "." <> prettySe 0 tm
764 prettySe p (PRefl _) = text "refl"
765 prettySe p (PResolveTC _) = text "resolvetc"
766 prettySe p (PTrue _) = text "()"
767 prettySe p (PFalse _) = text "_|_"
768 prettySe p (PEq _ l r) =
770 if size r > breakingSize then
771 prettySe 10 l <+> text "=" $$ nest nestingSize (prettySe 10 r)
773 prettySe 10 l <+> text "=" <+> prettySe 10 r
774 prettySe p (PTyped l r) =
775 lparen <> prettySe 10 l <+> colon <+> prettySe 10 r <> rparen
776 prettySe p (PPair _ l r) =
777 if size r > breakingSize then
778 lparen <> prettySe 10 l <> text "," $+$
779 prettySe 10 r <> rparen
781 lparen <> prettySe 10 l <> text "," <+> prettySe 10 r <> rparen
782 prettySe p (PDPair _ l t r) =
783 if size r > breakingSize then
784 lparen <> prettySe 10 l <+> text "**" $+$
785 prettySe 10 r <> rparen
787 lparen <> prettySe 10 l <+> text "**" <+> prettySe 10 r <> rparen
788 prettySe p (PAlternative a as) =
789 lparen <> text "|" <> prettyAs <> text "|" <> rparen
792 foldr (\l -> \r -> l <+> text "," <+> r) empty $ map (prettySe 10) as
793 prettySe p PSet = text "Set"
794 prettySe p (PConstant c) = pretty c
795 -- XXX: add pretty for tactics
796 prettySe p (PProof ts) =
797 text "proof" <+> lbrace $+$ nest nestingSize (text . show $ ts) $+$ rbrace
798 prettySe p (PTactics ts) =
799 text "tactics" <+> lbrace $+$ nest nestingSize (text . show $ ts) $+$ rbrace
800 prettySe p (PMetavar n) = text "?" <> pretty n
801 prettySe p (PReturn f) = text "return"
802 prettySe p PImpossible = text "impossible"
803 prettySe p Placeholder = text "_"
804 prettySe p (PDoBlock _) = text "do block pretty not implemented"
805 prettySe p (PElabError s) = pretty s
807 prettySe p _ = text "test"
809 prettyArgS (PImp _ _ n tm) = prettyArgSi (n, tm)
810 prettyArgS (PExp _ _ tm) = prettyArgSe tm
811 prettyArgS (PConstraint _ _ tm) = prettyArgSc tm
812 prettyArgS (PTacImplicit _ _ n _ tm) = prettyArgSti (n, tm)
814 prettyArgSe arg = prettySe 0 arg
815 prettyArgSi (n, val) = lbrace <> pretty n <+> text "=" <+> prettySe 10 val <> rbrace
816 prettyArgSc val = lbrace <> lbrace <> prettySe 10 val <> rbrace <> rbrace
817 prettyArgSti (n, val) = lbrace <> text "auto" <+> pretty n <+> text "=" <+> prettySe 10 val <> rbrace
819 bracket outer inner doc
820 | inner > outer = lparen <> doc <> rparen
823showImp :: Bool -> PTerm -> String
824showImp impl tm = se 10 tm where
825 se p (PQuote r) = "![" ++ show r ++ "]"
826 se p (PRef fc n) = if impl then show n -- ++ "[" ++ show fc ++ "]"
828 where showbasic n@(UN _) = show n
829 showbasic (MN _ s) = s
830 showbasic (NS n s) = showSep "." (reverse s) ++ "." ++ showbasic n
831 se p (PLam n ty sc) = bracket p 2 $ "\\ " ++ show n ++
832 (if impl then " : " ++ se 10 ty else "") ++ " => "
834 se p (PLet n ty v sc) = bracket p 2 $ "let " ++ show n ++ " = " ++ se 10 v ++
836 se p (PPi (Exp l s) n ty sc)
837 | n `elem` allNamesIn sc || impl
839 if l then "|(" else "(" ++
840 show n ++ " : " ++ se 10 ty ++
843 | otherwise = bracket p 2 $ se 0 ty ++ " " ++ st ++ "-> " ++ se 10 sc
845 Static -> "[static] "
847 se p (PPi (Imp l s) n ty sc)
848 | impl = bracket p 2 $ if l then "|{" else "{" ++
849 show n ++ " : " ++ se 10 ty ++
850 "} " ++ st ++ "-> " ++ se 10 sc
851 | otherwise = se 10 sc
853 Static -> "[static] "
855 se p (PPi (Constraint _ _) n ty sc)
856 = bracket p 2 $ se 10 ty ++ " => " ++ se 10 sc
857 se p (PPi (TacImp _ _ s) n ty sc)
858 = bracket p 2 $ "{tacimp " ++ show n ++ " : " ++ se 10 ty ++ "} -> " ++ se 10 sc
859 se p (PApp _ (PRef _ f) [])
861 se p (PApp _ (PRef _ op@(UN (f:_))) args)
862 | length (getExps args) == 2 && not impl && not (isAlpha f)
863 = let [l, r] = getExps args in
864 bracket p 1 $ se 1 l ++ " " ++ show op ++ " " ++ se 0 r
866 = let args = getExps as in
867 bracket p 1 $ se 1 f ++ if impl then concatMap sArg as
868 else concatMap seArg args
869 se p (PCase _ scr opts) = "case " ++ se 10 scr ++ " of " ++ showSep " | " (map sc opts)
870 where sc (l, r) = se 10 l ++ " => " ++ se 10 r
871 se p (PHidden tm) = "." ++ se 0 tm
872 se p (PRefl _) = "refl"
873 se p (PResolveTC _) = "resolvetc"
874 se p (PTrue _) = "()"
875 se p (PFalse _) = "_|_"
876 se p (PEq _ l r) = bracket p 2 $ se 10 l ++ " = " ++ se 10 r
877 se p (PTyped l r) = "(" ++ se 10 l ++ " : " ++ se 10 r ++ ")"
878 se p (PPair _ l r) = "(" ++ se 10 l ++ ", " ++ se 10 r ++ ")"
879 se p (PDPair _ l t r) = "(" ++ se 10 l ++ " ** " ++ se 10 r ++ ")"
880 se p (PAlternative a as) = "(|" ++ showSep " , " (map (se 10) as) ++ "|)"
882 se p (PConstant c) = show c
883 se p (PProof ts) = "proof { " ++ show ts ++ "}"
884 se p (PTactics ts) = "tactics { " ++ show ts ++ "}"
885 se p (PMetavar n) = "?" ++ show n
886 se p (PReturn f) = "return"
887 se p PImpossible = "impossible"
888 se p Placeholder = "_"
889 se p (PDoBlock _) = "do block show not implemented"
890 se p (PElabError s) = show s
891-- se p x = "Not implemented"
893 sArg (PImp _ _ n tm) = siArg (n, tm)
894 sArg (PExp _ _ tm) = seArg tm
895 sArg (PConstraint _ _ tm) = scArg tm
896 sArg (PTacImplicit _ _ n _ tm) = stiArg (n, tm)
898 seArg arg = " " ++ se 0 arg
899 siArg (n, val) = " {" ++ show n ++ " = " ++ se 10 val ++ "}"
900 scArg val = " {{" ++ se 10 val ++ "}}"
901 stiArg (n, val) = " {auto " ++ show n ++ " = " ++ se 10 val ++ "}"
903 bracket outer inner str | inner > outer = "(" ++ str ++ ")"
909 | PLam Name PTerm PTerm
910 | PPi Plicity Name PTerm PTerm
911 | PLet Name PTerm PTerm PTerm
912 | PTyped PTerm PTerm -- term with explicit type
913 | PApp FC PTerm [PArg]
914 | PCase FC PTerm [(PTerm, PTerm)]
920 | PPair FC PTerm PTerm
921 | PDPair FC PTerm PTerm PTerm
922 | PAlternative [PTerm]
923 | PHidden PTerm -- irrelevant or hidden pattern
932 | PTactics [PTactic] -- as PProof, but no auto solving
933 | PElabError Err -- error to report on elaboration
934 | PImpossible -- special case for declaring when an LHS can't typecheck
937instance Sized PTerm where
938 size (PQuote rawTerm) = size rawTerm
939 size (PRef fc name) = size name
940 size (PLam name ty bdy) = 1 + size ty + size bdy
941 size (PPi plicity name ty bdy) = 1 + size ty + size bdy
942 size (PLet name ty def bdy) = 1 + size ty + size def + size bdy
943 size (PTyped trm ty) = 1 + size trm + size ty
944 size (PApp fc name args) = 1 + size args
945 size (PCase fc trm bdy) = 1 + size trm + size bdy
949 size (PResolveTC fc) = 1
950 size (PEq fc left right) = 1 + size left + size right
951 size (PPair fc left right) = 1 + size left + size right
952 size (PDPair fs left ty right) = 1 + size left + size ty + size right
953 size (PAlternative a alts) = 1 + size alts
954 size (PHidden hidden) = size hidden
956 size (PConstant const) = 1 + size const
958 size (PDoBlock dos) = 1 + size dos
959 size (PIdiom fc term) = 1 + size term
960 size (PReturn fc) = 1
961 size (PMetavar name) = 1
962 size (PProof tactics) = size tactics
963 size (PElabError err) = size err
966allNamesIn :: PTerm -> [Name]
967allNamesIn tm = nub $ ni [] tm
970 | not (n `elem` env) = [n]
971 ni env (PApp _ f as) = ni env f ++ concatMap (ni env) (map getTm as)
972 ni env (PCase _ c os) = ni env c ++ concatMap (ni env) (map snd os)
973 ni env (PLam n ty sc) = ni env ty ++ ni (n:env) sc
974 ni env (PPi _ n ty sc) = ni env ty ++ ni (n:env) sc
975 ni env (PHidden tm) = ni env tm
976 ni env (PEq _ l r) = ni env l ++ ni env r
977 ni env (PTyped l r) = ni env l ++ ni env r
978 ni env (PPair _ l r) = ni env l ++ ni env r
979 ni env (PDPair _ (PRef _ n) t r) = ni env t ++ ni (n:env) r
980 ni env (PDPair _ l t r) = ni env l ++ ni env t ++ ni env r
981 ni env (PAlternative a ls) = concatMap (ni env) ls
984namesIn :: [(Name, PTerm)] -> IState -> PTerm -> [Name]
985namesIn uvars ist tm = nub $ ni [] tm
989 = case lookupTy Nothing n (tt_ctxt ist) of
991 _ -> if n `elem` (map fst uvars) then [n] else []
992 ni env (PApp _ f as) = ni env f ++ concatMap (ni env) (map getTm as)
993 ni env (PCase _ c os) = ni env c ++ concatMap (ni env) (map snd os)
994 ni env (PLam n ty sc) = ni env ty ++ ni (n:env) sc
995 ni env (PPi _ n ty sc) = ni env ty ++ ni (n:env) sc
996 ni env (PEq _ l r) = ni env l ++ ni env r
997 ni env (PTyped l r) = ni env l ++ ni env r
998 ni env (PPair _ l r) = ni env l ++ ni env r
999 ni env (PDPair _ (PRef _ n) t r) = ni env t ++ ni (n:env) r
1000 ni env (PDPair _ l t r) = ni env l ++ ni env t ++ ni env r
1001 ni env (PAlternative a as) = concatMap (ni env) as
1002 ni env (PHidden 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