1{-# LANGUAGE MultiParamTypeClasses, FlexibleInstances, DeriveFunctor,
2 TypeSynonymInstances, PatternGuards #-}
4module Idris.AbsSyntaxTree where
8import Core.Elaborate hiding (Tactic(..))
15import System.Console.Haskeline
17import Control.Monad.Trans.State.Strict
25data IOption = IOption { opt_logLevel :: Int,
27 opt_typeintype :: Bool,
30 opt_errContext :: Bool,
33 opt_ibcsubdir :: FilePath,
34 opt_importdirs :: [FilePath],
35 opt_cmdline :: [Opt] -- remember whole command line
39defaultOpts = IOption 0 False False True False False True True "" [] []
41-- TODO: Add 'module data' to IState, which can be saved out and reloaded quickly (i.e
42-- without typechecking).
43-- This will include all the functions and data declarations, plus fixity declarations
48 idris_constraints :: [(UConstraint, FC)],
49 idris_infixes :: [FixDecl],
50 idris_implicits :: Ctxt [PArg],
51 idris_statics :: Ctxt [Bool],
52 idris_classes :: Ctxt ClassInfo,
53 idris_dsls :: Ctxt DSL,
54 idris_optimisation :: Ctxt OptInfo,
55 idris_datatypes :: Ctxt TypeInfo,
56 idris_patdefs :: Ctxt [([Name], Term, Term)], -- not exported
57 idris_flags :: Ctxt [FnOpt],
58 idris_callgraph :: Ctxt CGInfo, -- name, args used in each pos
59 idris_calledgraph :: Ctxt [Name],
60 idris_docstrings :: Ctxt String,
61 idris_totcheck :: [(FC, Name)],
63 idris_options :: IOption,
65 idris_metavars :: [Name],
66 syntax_rules :: [Syntax],
67 syntax_keywords :: [String],
68 imported :: [FilePath],
69 idris_scprims :: [(Name, (Int, PrimFn))],
70 idris_objs :: [FilePath],
71 idris_libs :: [String],
72 idris_hdrs :: [String],
73 proof_list :: [(Name, [String])],
75 lastParse :: Maybe Name,
76 indent_stack :: [Int],
77 brace_stack :: [Maybe Int],
78 hide_list :: [(Name, Maybe Accessibility)],
79 default_access :: Accessibility,
80 default_total :: Bool,
81 ibc_write :: [IBCWrite],
82 compiled_so :: Maybe String
85data SizeChange = Smaller | Same | Bigger | Unknown
88deriving instance Binary SizeChange
91type SCGEntry = (Name, [Maybe (Int, SizeChange)])
93data CGInfo = CGInfo { argsdef :: [Name],
94 calls :: [(Name, [[Name]])],
100deriving instance Binary CGInfo
103primDefs = [UN "unsafePerformIO", UN "mkLazyForeign", UN "mkForeign", UN "FalseElim"]
105-- information that needs writing for the current module's .ibc file
106data IBCWrite = IBCFix FixDecl
110 | IBCInstance Bool Name Name
120 | IBCAccess Name Accessibility
121 | IBCTotal Name Totality
122 | IBCFlags Name [FnOpt]
125 | IBCDef Name -- i.e. main context
128idrisInit = IState initContext [] [] emptyContext emptyContext emptyContext
129 emptyContext emptyContext emptyContext emptyContext
130 emptyContext emptyContext emptyContext emptyContext
131 [] "" defaultOpts 6 [] [] [] [] [] [] [] []
132 [] Nothing Nothing [] [] [] Hidden False [] Nothing
134-- The monad for the main REPL - reading and processing files and updating
135-- global state (hence the IO inner monad).
136type Idris = StateT IState (InputT IO)
138-- Commands in the REPL
140data Target = ViaC | ViaJava
152 | Compile Target String
158 | AddProof (Maybe Name)
177data Opt = Filename String
212-- Parsed declarations
214data Fixity = Infixl { prec :: Int }
215 | Infixr { prec :: Int }
216 | InfixN { prec :: Int }
217 | PrefixN { prec :: Int }
220deriving instance Binary Fixity
223instance Show Fixity where
224 show (Infixl i) = "infixl " ++ show i
225 show (Infixr i) = "infixr " ++ show i
226 show (InfixN i) = "infix " ++ show i
227 show (PrefixN i) = "prefix " ++ show i
229data FixDecl = Fix Fixity String
232deriving instance Binary FixDecl
235instance Ord FixDecl where
236 compare (Fix x _) (Fix y _) = compare (prec x) (prec y)
239data Static = Static | Dynamic
242deriving instance Binary Static
245-- Mark bindings with their explicitness, and laziness
246data Plicity = Imp { plazy :: Bool,
249 | Exp { plazy :: Bool,
252 | Constraint { plazy :: Bool,
255 | TacImp { plazy :: Bool,
262deriving instance Binary Plicity
265impl = Imp False Dynamic ""
266expl = Exp False Dynamic ""
267constraint = Constraint False Dynamic ""
268tacimpl t = TacImp False Dynamic t ""
270data FnOpt = Inlinable | TotalFn | PartialFn
271 | Coinductive | AssertTotal | TCGen
272 | CExport String -- export, with a C name
273 | Specialise [Name] -- specialise it, freeze these names
276deriving instance Binary FnOpt
281inlinable :: FnOpts -> Bool
282inlinable = elem Inlinable
284data PDecl' t = PFix FC Fixity [String] -- fixity declaration
285 | PTy String SyntaxInfo FC FnOpts Name t -- type declaration
286 | PClauses FC FnOpts Name [PClause' t] -- pattern clause
287 | PCAF FC Name t -- top level constant
288 | PData String SyntaxInfo FC Bool -- codata
289 (PData' t) -- data declaration
290 | PParams FC [(Name, t)] [PDecl' t] -- params block
291 | PNamespace String [PDecl' t] -- new namespace
292 | PRecord String SyntaxInfo FC Name t String Name t -- record declaration
293 | PClass String SyntaxInfo FC
296 [(Name, t)] -- parameters
297 [PDecl' t] -- declarations
298 | PInstance SyntaxInfo FC [t] -- constraints
301 t -- full instance type
302 (Maybe Name) -- explicit name
306 | PMutual FC [PDecl' t]
307 | PDirective (Idris ())
310deriving instance Binary PDecl'
313data PClause' t = PClause FC Name t [t] t [PDecl' t]
314 | PWith FC Name t [t] t [PDecl' t]
315 | PClauseR FC [t] t [PDecl' t]
316 | PWithR FC [t] t [PDecl' t]
319deriving instance Binary PClause'
322data PData' t = PDatadecl { d_name :: Name,
324 d_cons :: [(String, Name, t, FC)] }
325 | PLaterdecl { d_name :: Name, d_tcon :: t }
328deriving instance Binary PData'
331-- Handy to get a free function for applying PTerm -> PTerm functions
332-- across a program, by deriving Functor
334type PDecl = PDecl' PTerm
335type PData = PData' PTerm
336type PClause = PClause' PTerm
338-- get all the names declared in a decl
340declared :: PDecl -> [Name]
341declared (PFix _ _ _) = []
342declared (PTy _ _ _ _ n t) = [n]
343declared (PClauses _ _ n _) = [] -- not a declaration
344declared (PRecord _ _ _ n _ _ c _) = [n, c]
345declared (PData _ _ _ _ (PDatadecl n _ ts)) = n : map fstt ts
346 where fstt (_, a, _, _) = a
347declared (PParams _ _ ds) = concatMap declared ds
348declared (PMutual _ ds) = concatMap declared ds
349declared (PNamespace _ ds) = concatMap declared ds
350-- declared (PImport _) = []
352defined :: PDecl -> [Name]
353defined (PFix _ _ _) = []
354defined (PTy _ _ _ _ n t) = []
355defined (PClauses _ _ n _) = [n] -- not a declaration
356defined (PRecord _ _ _ n _ _ c _) = [n, c]
357defined (PData _ _ _ _ (PDatadecl n _ ts)) = n : map fstt ts
358 where fstt (_, a, _, _) = a
359defined (PParams _ _ ds) = concatMap defined ds
360defined (PMutual _ ds) = concatMap defined ds
361defined (PNamespace _ ds) = concatMap defined ds
362-- declared (PImport _) = []
364updateN :: [(Name, Name)] -> Name -> Name
365updateN ns n | Just n' <- lookup n ns = n'
368updateNs :: [(Name, Name)] -> PTerm -> PTerm
370updateNs ns t = mapPT updateRef t
371 where updateRef (PRef fc f) = PRef fc (updateN ns f)
374-- updateDNs :: [(Name, Name)] -> PDecl -> PDecl
376-- updateDNs ns (PTy s f n t) | Just n' <- lookup n ns = PTy s f n' t
377-- updateDNs ns (PClauses f n c) | Just n' <- lookup n ns = PClauses f n' (map updateCNs c)
378-- where updateCNs ns (PClause n l ts r ds)
379-- = PClause (updateN ns n) (fmap (updateNs ns) l)
380-- (map (fmap (updateNs ns)) ts)
381-- (fmap (updateNs ns) r)
382-- (map (updateDNs ns) ds)
385-- High level language terms
387data PTerm = PQuote Raw
390 | PLam Name PTerm PTerm
391 | PPi Plicity Name PTerm PTerm
392 | PLet Name PTerm PTerm PTerm
393 | PTyped PTerm PTerm -- term with explicit type
394 | PApp FC PTerm [PArg]
395 | PCase FC PTerm [(PTerm, PTerm)]
401 | PPair FC PTerm PTerm
402 | PDPair FC PTerm PTerm PTerm
403 | PAlternative Bool [PTerm] -- True if only one may work
404 | PHidden PTerm -- irrelevant or hidden pattern
413 | PTactics [PTactic] -- as PProof, but no auto solving
414 | PElabError Err -- error to report on elaboration
415 | PImpossible -- special case for declaring when an LHS can't typecheck
418deriving instance Binary PTerm
421mapPT :: (PTerm -> PTerm) -> PTerm -> PTerm
422mapPT f t = f (mpt t) where
423 mpt (PLam n t s) = PLam n (mapPT f t) (mapPT f s)
424 mpt (PPi p n t s) = PPi p n (mapPT f t) (mapPT f s)
425 mpt (PLet n ty v s) = PLet n (mapPT f ty) (mapPT f v) (mapPT f s)
426 mpt (PApp fc t as) = PApp fc (mapPT f t) (map (fmap (mapPT f)) as)
427 mpt (PCase fc c os) = PCase fc (mapPT f c) (map (pmap (mapPT f)) os)
428 mpt (PEq fc l r) = PEq fc (mapPT f l) (mapPT f r)
429 mpt (PTyped l r) = PTyped (mapPT f l) (mapPT f r)
430 mpt (PPair fc l r) = PPair fc (mapPT f l) (mapPT f r)
431 mpt (PDPair fc l t r) = PDPair fc (mapPT f l) (mapPT f t) (mapPT f r)
432 mpt (PAlternative a as) = PAlternative a (map (mapPT f) as)
433 mpt (PHidden t) = PHidden (mapPT f t)
434 mpt (PDoBlock ds) = PDoBlock (map (fmap (mapPT f)) ds)
435 mpt (PProof ts) = PProof (map (fmap (mapPT f)) ts)
436 mpt (PTactics ts) = PTactics (map (fmap (mapPT f)) ts)
440data PTactic' t = Intro [Name] | Intros | Focus Name
441 | Refine Name [Bool] | Rewrite t | LetTac Name t
442 | Exact t | Compute | Trivial
445 | ProofState | ProofTerm | Undo
446 | Try (PTactic' t) (PTactic' t)
447 | TSeq (PTactic' t) (PTactic' t)
449 deriving (Show, Eq, Functor)
451deriving instance Binary PTactic'
454instance Sized a => Sized (PTactic' a) where
455 size (Intro nms) = 1 + size nms
457 size (Focus nm) = 1 + size nm
458 size (Refine nm bs) = 1 + size nm + length bs
459 size (Rewrite t) = 1 + size t
460 size (LetTac nm t) = 1 + size nm + size t
461 size (Exact t) = 1 + size t
469 size (Try l r) = 1 + size l + size r
470 size (TSeq l r) = 1 + size l + size r
474type PTactic = PTactic' PTerm
476data PDo' t = DoExp FC t
481 deriving (Eq, Functor)
483deriving instance Binary PDo'
486instance Sized a => Sized (PDo' a) where
487 size (DoExp fc t) = 1 + size fc + size t
488 size (DoBind fc nm t) = 1 + size fc + size nm + size t
489 size (DoBindP fc l r) = 1 + size fc + size l + size r
490 size (DoLet fc nm l r) = 1 + size fc + size nm + size l + size r
491 size (DoLetP fc l r) = 1 + size fc + size l + size r
495-- The priority gives a hint as to elaboration order. Best to elaborate
496-- things early which will help give a more concrete type to other
497-- variables, e.g. a before (interpTy a).
499data PArg' t = PImp { priority :: Int,
500 lazyarg :: Bool, pname :: Name, getTm :: t,
502 | PExp { priority :: Int,
503 lazyarg :: Bool, getTm :: t,
505 | PConstraint { priority :: Int,
506 lazyarg :: Bool, getTm :: t,
508 | PTacImplicit { priority :: Int,
509 lazyarg :: Bool, pname :: Name,
513 deriving (Show, Eq, Functor)
515instance Sized a => Sized (PArg' a) where
516 size (PImp p l nm trm _) = 1 + size nm + size trm
517 size (PExp p l trm _) = 1 + size trm
518 size (PConstraint p l trm _) = 1 + size trm
519 size (PTacImplicit p l nm scr trm _) = 1 + size nm + size scr + size trm
522deriving instance Binary PArg'
525pimp n t = PImp 0 True n t ""
526pexp t = PExp 0 False t ""
527pconst t = PConstraint 0 False t ""
528ptacimp n s t = PTacImplicit 0 True n s t ""
530type PArg = PArg' PTerm
534data ClassInfo = CI { instanceName :: Name,
535 class_methods :: [(Name, (FnOpts, PTerm))],
536 class_defaults :: [(Name, (Name, PDecl))], -- method name -> default impl
537 class_params :: [Name],
538 class_instances :: [Name] }
541deriving instance Binary ClassInfo
544data OptInfo = Optimise { collapsible :: Bool,
545 forceable :: [Int], -- argument positions
549deriving instance Binary OptInfo
553data TypeInfo = TI { con_names :: [Name], codata :: Bool }
556deriving instance Binary TypeInfo
559-- Syntactic sugar info
561data DSL' t = DSL { dsl_bind :: t,
566 index_first :: Maybe t,
567 index_next :: Maybe t,
568 dsl_lambda :: Maybe t,
571 deriving (Show, Functor)
573deriving instance Binary DSL'
578data SynContext = PatternSyntax | TermSyntax | AnySyntax
581deriving instance Binary SynContext
584data Syntax = Rule [SSymbol] PTerm SynContext
587deriving instance Binary Syntax
590data SSymbol = Keyword Name
597deriving instance Binary SSymbol
600initDSL = DSL (PRef f (UN ">>="))
601 (PRef f (UN "return"))
609 where f = FC "(builtin)" 0
611data SyntaxInfo = Syn { using :: [(Name, PTerm)],
612 syn_params :: [(Name, PTerm)],
613 syn_namespace :: [String],
615 decoration :: Name -> Name,
617 implicitAllowed :: Bool,
621deriving instance Binary SyntaxInfo
624defaultSyntax = Syn [] [] [] [] id False False initDSL
626expandNS :: SyntaxInfo -> Name -> Name
627expandNS syn n@(NS _ _) = n
628expandNS syn n = case syn_namespace syn of
633--- Pretty printing declarations and terms
635instance Show PTerm where
636 show tm = showImp False tm
638instance Pretty PTerm where
639 pretty = prettyImp False
641instance Show PDecl where
642 show d = showDeclImp False d
644instance Show PClause where
645 show c = showCImp True c
647instance Show PData where
648 show d = showDImp False d
650showDeclImp _ (PFix _ f ops) = show f ++ " " ++ showSep ", " ops
651showDeclImp t (PTy _ _ _ _ n ty) = show n ++ " : " ++ showImp t ty
652showDeclImp _ (PClauses _ _ n c) = showSep "\n" (map show c)
653showDeclImp _ (PData _ _ _ _ d) = show d
654showDeclImp _ (PParams f ns ps) = "parameters " ++ show ns ++ "\n" ++
655 showSep "\n" (map show ps)
658showCImp :: Bool -> PClause -> String
659showCImp impl (PClause _ n l ws r w)
660 = showImp impl l ++ showWs ws ++ " = " ++ showImp impl r
661 ++ " where " ++ show w
664 showWs (x : xs) = " | " ++ showImp impl x ++ showWs xs
665showCImp impl (PWith _ n l ws r w)
666 = showImp impl l ++ showWs ws ++ " with " ++ showImp impl r
667 ++ " { " ++ show w ++ " } "
670 showWs (x : xs) = " | " ++ showImp impl x ++ showWs xs
673showDImp :: Bool -> PData -> String
674showDImp impl (PDatadecl n ty cons)
675 = "data " ++ show n ++ " : " ++ showImp impl ty ++ " where\n\t"
677 (map (\ (_, n, t, _) -> show n ++ " : " ++ showImp impl t) cons)
679getImps :: [PArg] -> [(Name, PTerm)]
681getImps (PImp _ _ n tm _ : xs) = (n, tm) : getImps xs
682getImps (_ : xs) = getImps xs
684getExps :: [PArg] -> [PTerm]
686getExps (PExp _ _ tm _ : xs) = tm : getExps xs
687getExps (_ : xs) = getExps xs
689getConsts :: [PArg] -> [PTerm]
691getConsts (PConstraint _ _ tm _ : xs) = tm : getConsts xs
692getConsts (_ : xs) = getConsts xs
694getAll :: [PArg] -> [PTerm]
697prettyImp :: Bool -> PTerm -> Doc
698prettyImp impl = prettySe 10
700 prettySe p (PQuote r) =
701 if size r > breakingSize then
702 text "![" $$ pretty r <> text "]"
704 text "![" <> pretty r <> text "]"
705 prettySe p (PPatvar fc n) = pretty n
706 prettySe p (PRef fc n) =
712 prettyBasic n@(UN _) = pretty n
713 prettyBasic (MN _ s) = text s
714 prettyBasic (NS n s) = (foldr (<>) empty (intersperse (text ".") (map text $ reverse s))) <> prettyBasic n
715 prettySe p (PLam n ty sc) =
717 if size sc > breakingSize then
718 text "λ" <> pretty n <+> text "=>" $+$ pretty sc
720 text "λ" <> pretty n <+> text "=>" <+> pretty sc
721 prettySe p (PLet n ty v sc) =
723 if size sc > breakingSize then
724 text "let" <+> pretty n <+> text "=" <+> prettySe 10 v <+> text "in" $+$
725 nest nestingSize (prettySe 10 sc)
727 text "let" <+> pretty n <+> text "=" <+> prettySe 10 v <+> text "in" <+>
729 prettySe p (PPi (Exp l s _) n ty sc)
730 | n `elem` allNamesIn sc || impl =
731 let open = if l then text "|" <> lparen else lparen in
733 if size sc > breakingSize then
734 open <> pretty n <+> colon <+> prettySe 10 ty <> rparen <+>
735 st <+> text "->" $+$ prettySe 10 sc
737 open <> pretty n <+> colon <+> prettySe 10 ty <> rparen <+>
738 st <+> text "->" <+> prettySe 10 sc
741 if size sc > breakingSize then
742 prettySe 0 ty <+> st <+> text "->" $+$ prettySe 10 sc
744 prettySe 0 ty <+> st <+> text "->" <+> prettySe 10 sc
748 Static -> text "[static]"
750 prettySe p (PPi (Imp l s _) n ty sc)
752 let open = if l then text "|" <> lbrace else lbrace in
754 if size sc > breakingSize then
755 open <> pretty n <+> colon <+> prettySe 10 ty <> rbrace <+>
756 st <+> text "->" <+> prettySe 10 sc
758 open <> pretty n <+> colon <+> prettySe 10 ty <> rbrace <+>
759 st <+> text "->" <+> prettySe 10 sc
760 | otherwise = prettySe 10 sc
764 Static -> text $ "[static]"
766 prettySe p (PPi (Constraint _ _ _) n ty sc) =
768 if size sc > breakingSize then
769 prettySe 10 ty <+> text "=>" <+> prettySe 10 sc
771 prettySe 10 ty <+> text "=>" $+$ prettySe 10 sc
772 prettySe p (PPi (TacImp _ _ s _) n ty sc) =
774 if size sc > breakingSize then
775 lbrace <> text "tacimp" <+> pretty n <+> colon <+> prettySe 10 ty <>
776 rbrace <+> text "->" $+$ prettySe 10 sc
778 lbrace <> text "tacimp" <+> pretty n <+> colon <+> prettySe 10 ty <>
779 rbrace <+> text "->" <+> prettySe 10 sc
780 prettySe p (PApp _ (PRef _ f) [])
781 | not impl = pretty f
782 prettySe p (PApp _ (PRef _ op@(UN (f:_))) args)
783 | length (getExps args) == 2 && (not impl) && (not $ isAlpha f) =
784 let [l, r] = getExps args in
786 if size r > breakingSize then
787 prettySe 1 l <+> pretty op $+$ prettySe 0 r
789 prettySe 1 l <+> pretty op <+> prettySe 0 r
790 prettySe p (PApp _ f as) =
791 let args = getExps as in
796 -- foldr (<+>) empty $ map prettyArgS as
799 -- foldr (<+>) empty $ map prettyArgSe args
802 if size r > breakingSize then
803 l $+$ nest nestingSize (prettyArgS r)
808 if size r > breakingSize then
809 l $+$ nest nestingSize (prettyArgSe r)
812 prettySe p (PCase _ scr opts) =
813 text "case" <+> prettySe 10 scr <+> text "of" $+$ nest nestingSize prettyBody
815 prettyBody = foldr ($$) empty $ intersperse (text "|") $ map sc opts
817 sc (l, r) = prettySe 10 l <+> text "=>" <+> prettySe 10 r
818 prettySe p (PHidden tm) = text "." <> prettySe 0 tm
819 prettySe p (PRefl _ _) = text "refl"
820 prettySe p (PResolveTC _) = text "resolvetc"
821 prettySe p (PTrue _) = text "()"
822 prettySe p (PFalse _) = text "_|_"
823 prettySe p (PEq _ l r) =
825 if size r > breakingSize then
826 prettySe 10 l <+> text "=" $$ nest nestingSize (prettySe 10 r)
828 prettySe 10 l <+> text "=" <+> prettySe 10 r
829 prettySe p (PTyped l r) =
830 lparen <> prettySe 10 l <+> colon <+> prettySe 10 r <> rparen
831 prettySe p (PPair _ l r) =
832 if size r > breakingSize then
833 lparen <> prettySe 10 l <> text "," $+$
834 prettySe 10 r <> rparen
836 lparen <> prettySe 10 l <> text "," <+> prettySe 10 r <> rparen
837 prettySe p (PDPair _ l t r) =
838 if size r > breakingSize then
839 lparen <> prettySe 10 l <+> text "**" $+$
840 prettySe 10 r <> rparen
842 lparen <> prettySe 10 l <+> text "**" <+> prettySe 10 r <> rparen
843 prettySe p (PAlternative a as) =
844 lparen <> text "|" <> prettyAs <> text "|" <> rparen
847 foldr (\l -> \r -> l <+> text "," <+> r) empty $ map (prettySe 10) as
848 prettySe p PSet = text "Set"
849 prettySe p (PConstant c) = pretty c
850 -- XXX: add pretty for tactics
851 prettySe p (PProof ts) =
852 text "proof" <+> lbrace $+$ nest nestingSize (text . show $ ts) $+$ rbrace
853 prettySe p (PTactics ts) =
854 text "tactics" <+> lbrace $+$ nest nestingSize (text . show $ ts) $+$ rbrace
855 prettySe p (PMetavar n) = text "?" <> pretty n
856 prettySe p (PReturn f) = text "return"
857 prettySe p PImpossible = text "impossible"
858 prettySe p Placeholder = text "_"
859 prettySe p (PDoBlock _) = text "do block pretty not implemented"
860 prettySe p (PElabError s) = pretty s
862 prettySe p _ = text "test"
864 prettyArgS (PImp _ _ n tm _) = prettyArgSi (n, tm)
865 prettyArgS (PExp _ _ tm _) = prettyArgSe tm
866 prettyArgS (PConstraint _ _ tm _) = prettyArgSc tm
867 prettyArgS (PTacImplicit _ _ n _ tm _) = prettyArgSti (n, tm)
869 prettyArgSe arg = prettySe 0 arg
870 prettyArgSi (n, val) = lbrace <> pretty n <+> text "=" <+> prettySe 10 val <> rbrace
871 prettyArgSc val = lbrace <> lbrace <> prettySe 10 val <> rbrace <> rbrace
872 prettyArgSti (n, val) = lbrace <> text "auto" <+> pretty n <+> text "=" <+> prettySe 10 val <> rbrace
874 bracket outer inner doc
875 | inner > outer = lparen <> doc <> rparen
878showImp :: Bool -> PTerm -> String
879showImp impl tm = se 10 tm where
880 se p (PQuote r) = "![" ++ show r ++ "]"
881 se p (PPatvar fc n) = show n
882 se p (PRef fc n) = if impl then show n -- ++ "[" ++ show fc ++ "]"
884 where showbasic n@(UN _) = show n
885 showbasic (MN _ s) = s
886 showbasic (NS n s) = showSep "." (reverse s) ++ "." ++ showbasic n
887 se p (PLam n ty sc) = bracket p 2 $ "\\ " ++ show n ++
888 (if impl then " : " ++ se 10 ty else "") ++ " => "
890 se p (PLet n ty v sc) = bracket p 2 $ "let " ++ show n ++ " = " ++ se 10 v ++
892 se p (PPi (Exp l s _) n ty sc)
893 | n `elem` allNamesIn sc || impl
895 if l then "|(" else "(" ++
896 show n ++ " : " ++ se 10 ty ++
899 | otherwise = bracket p 2 $ se 0 ty ++ " " ++ st ++ "-> " ++ se 10 sc
901 Static -> "[static] "
903 se p (PPi (Imp l s _) n ty sc)
904 | impl = bracket p 2 $ if l then "|{" else "{" ++
905 show n ++ " : " ++ se 10 ty ++
906 "} " ++ st ++ "-> " ++ se 10 sc
907 | otherwise = se 10 sc
909 Static -> "[static] "
911 se p (PPi (Constraint _ _ _) n ty sc)
912 = bracket p 2 $ se 10 ty ++ " => " ++ se 10 sc
913 se p (PPi (TacImp _ _ s _) n ty sc)
914 = bracket p 2 $ "{tacimp " ++ show n ++ " : " ++ se 10 ty ++ "} -> " ++ se 10 sc
915 se p (PApp _ (PRef _ f) [])
917 se p (PApp _ (PRef _ op@(UN (f:_))) args)
918 | length (getExps args) == 2 && not impl && not (isAlpha f)
919 = let [l, r] = getExps args in
920 bracket p 1 $ se 1 l ++ " " ++ show op ++ " " ++ se 0 r
922 = let args = getExps as in
923 bracket p 1 $ se 1 f ++ if impl then concatMap sArg as
924 else concatMap seArg args
925 se p (PCase _ scr opts) = "case " ++ se 10 scr ++ " of " ++ showSep " | " (map sc opts)
926 where sc (l, r) = se 10 l ++ " => " ++ se 10 r
927 se p (PHidden tm) = "." ++ se 0 tm
930 | otherwise = "refl {" ++ se 10 t ++ "}"
931 se p (PResolveTC _) = "resolvetc"
932 se p (PTrue _) = "()"
933 se p (PFalse _) = "_|_"
934 se p (PEq _ l r) = bracket p 2 $ se 10 l ++ " = " ++ se 10 r
935 se p (PTyped l r) = "(" ++ se 10 l ++ " : " ++ se 10 r ++ ")"
936 se p (PPair _ l r) = "(" ++ se 10 l ++ ", " ++ se 10 r ++ ")"
937 se p (PDPair _ l t r) = "(" ++ se 10 l ++ " ** " ++ se 10 r ++ ")"
938 se p (PAlternative a as) = "(|" ++ showSep " , " (map (se 10) as) ++ "|)"
940 se p (PConstant c) = show c
941 se p (PProof ts) = "proof { " ++ show ts ++ "}"
942 se p (PTactics ts) = "tactics { " ++ show ts ++ "}"
943 se p (PMetavar n) = "?" ++ show n
944 se p (PReturn f) = "return"
945 se p PImpossible = "impossible"
946 se p Placeholder = "_"
947 se p (PDoBlock _) = "do block show not implemented"
948 se p (PElabError s) = show s
949-- se p x = "Not implemented"
951 sArg (PImp _ _ n tm _) = siArg (n, tm)
952 sArg (PExp _ _ tm _) = seArg tm
953 sArg (PConstraint _ _ tm _) = scArg tm
954 sArg (PTacImplicit _ _ n _ tm _) = stiArg (n, tm)
956 seArg arg = " " ++ se 0 arg
957 siArg (n, val) = " {" ++ show n ++ " = " ++ se 10 val ++ "}"
958 scArg val = " {{" ++ se 10 val ++ "}}"
959 stiArg (n, val) = " {auto " ++ show n ++ " = " ++ se 10 val ++ "}"
961 bracket outer inner str | inner > outer = "(" ++ str ++ ")"
965instance Sized PTerm where
966 size (PQuote rawTerm) = size rawTerm
967 size (PRef fc name) = size name
968 size (PLam name ty bdy) = 1 + size ty + size bdy
969 size (PPi plicity name ty bdy) = 1 + size ty + size bdy
970 size (PLet name ty def bdy) = 1 + size ty + size def + size bdy
971 size (PTyped trm ty) = 1 + size trm + size ty
972 size (PApp fc name args) = 1 + size args
973 size (PCase fc trm bdy) = 1 + size trm + size bdy
976 size (PRefl fc _) = 1
977 size (PResolveTC fc) = 1
978 size (PEq fc left right) = 1 + size left + size right
979 size (PPair fc left right) = 1 + size left + size right
980 size (PDPair fs left ty right) = 1 + size left + size ty + size right
981 size (PAlternative a alts) = 1 + size alts
982 size (PHidden hidden) = size hidden
984 size (PConstant const) = 1 + size const
986 size (PDoBlock dos) = 1 + size dos
987 size (PIdiom fc term) = 1 + size term
988 size (PReturn fc) = 1
989 size (PMetavar name) = 1
990 size (PProof tactics) = size tactics
991 size (PElabError err) = size err
994allNamesIn :: PTerm -> [Name]
995allNamesIn tm = nub $ ni [] tm
998 | not (n `elem` env) = [n]
999 ni env (PApp _ f as) = ni env f ++ concatMap (ni env) (map getTm as)
1000 ni env (PCase _ c os) = ni env c ++ concatMap (ni env) (map snd os)
1001 ni env (PLam n ty sc) = ni env ty ++ ni (n:env) sc
1002 ni env (PPi _ n ty sc) = ni env ty ++ ni (n:env) sc
1003 ni env (PHidden tm) = ni env tm
1004 ni env (PEq _ l r) = ni env l ++ ni env r
1005 ni env (PTyped l r) = ni env l ++ ni env r
1006 ni env (PPair _ l r) = ni env l ++ ni env r
1007 ni env (PDPair _ (PRef _ n) t r) = ni env t ++ ni (n:env) r
1008 ni env (PDPair _ l t r) = ni env l ++ ni env t ++ ni env r
1009 ni env (PAlternative a ls) = concatMap (ni env) ls
1012namesIn :: [(Name, PTerm)] -> IState -> PTerm -> [Name]
1013namesIn uvars ist tm = nub $ ni [] tm
1016 | not (n `elem` env)
1017 = case lookupTy Nothing n (tt_ctxt ist) of
1019 _ -> if n `elem` (map fst uvars) then [n] else []
1020 ni env (PApp _ f as) = ni env f ++ concatMap (ni env) (map getTm as)
1021 ni env (PCase _ c os) = ni env c ++ concatMap (ni env) (map snd os)
1022 ni env (PLam n ty sc) = ni env ty ++ ni (n:env) sc
1023 ni env (PPi _ n ty sc) = ni env ty ++ ni (n:env) sc
1024 ni env (PEq _ l r) = ni env l ++ ni env r
1025 ni env (PTyped l r) = ni env l ++ ni env r
1026 ni env (PPair _ l r) = ni env l ++ ni env r
1027 ni env (PDPair _ (PRef _ n) t r) = ni env t ++ ni (n:env) r
1028 ni env (PDPair _ l t r) = ni env l ++ ni env t ++ ni env r
1029 ni env (PAlternative a as) = concatMap (ni env) as
1030 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