1{-# LANGUAGE MultiParamTypeClasses, FlexibleInstances, DeriveFunctor,
2 TypeSynonymInstances, PatternGuards #-}
4module Idris.AbsSyntaxTree where
8import Core.Elaborate hiding (Tactic(..))
11import IRTS.CodegenCommon
16import System.Console.Haskeline
18import Control.Monad.Trans.State.Strict
26data IOption = IOption { opt_logLevel :: Int,
28 opt_typeintype :: Bool,
31 opt_errContext :: Bool,
35 opt_outputTy :: OutputType,
36 opt_ibcsubdir :: FilePath,
37 opt_importdirs :: [FilePath],
38 opt_cmdline :: [Opt] -- remember whole command line
42defaultOpts = IOption 0 False False True False False True True ViaC Executable "" [] []
44-- TODO: Add 'module data' to IState, which can be saved out and reloaded quickly (i.e
45-- without typechecking).
46-- This will include all the functions and data declarations, plus fixity declarations
51 idris_constraints :: [(UConstraint, FC)],
52 idris_infixes :: [FixDecl],
53 idris_implicits :: Ctxt [PArg],
54 idris_statics :: Ctxt [Bool],
55 idris_classes :: Ctxt ClassInfo,
56 idris_dsls :: Ctxt DSL,
57 idris_optimisation :: Ctxt OptInfo,
58 idris_datatypes :: Ctxt TypeInfo,
59 idris_patdefs :: Ctxt [([Name], Term, Term)], -- not exported
60 idris_flags :: Ctxt [FnOpt],
61 idris_callgraph :: Ctxt CGInfo, -- name, args used in each pos
62 idris_calledgraph :: Ctxt [Name],
63 idris_docstrings :: Ctxt String,
64 idris_totcheck :: [(FC, Name)],
66 idris_options :: IOption,
68 idris_metavars :: [Name],
69 syntax_rules :: [Syntax],
70 syntax_keywords :: [String],
71 imported :: [FilePath],
72 idris_scprims :: [(Name, (Int, PrimFn))],
73 idris_objs :: [FilePath],
74 idris_libs :: [String],
75 idris_hdrs :: [String],
76 proof_list :: [(Name, [String])],
78 lastParse :: Maybe Name,
79 indent_stack :: [Int],
80 brace_stack :: [Maybe Int],
81 hide_list :: [(Name, Maybe Accessibility)],
82 default_access :: Accessibility,
83 default_total :: Bool,
84 ibc_write :: [IBCWrite],
85 compiled_so :: Maybe String
88data SizeChange = Smaller | Same | Bigger | Unknown
91deriving instance Binary SizeChange
94type SCGEntry = (Name, [Maybe (Int, SizeChange)])
96data CGInfo = CGInfo { argsdef :: [Name],
97 calls :: [(Name, [[Name]])],
103deriving instance Binary CGInfo
106primDefs = [UN "unsafePerformIO", UN "mkLazyForeign", UN "mkForeign", UN "FalseElim"]
108-- information that needs writing for the current module's .ibc file
109data IBCWrite = IBCFix FixDecl
113 | IBCInstance Bool Name Name
123 | IBCAccess Name Accessibility
124 | IBCTotal Name Totality
125 | IBCFlags Name [FnOpt]
128 | IBCDef Name -- i.e. main context
131idrisInit = IState initContext [] [] emptyContext emptyContext emptyContext
132 emptyContext emptyContext emptyContext emptyContext
133 emptyContext emptyContext emptyContext emptyContext
134 [] "" defaultOpts 6 [] [] [] [] [] [] [] []
135 [] Nothing Nothing [] [] [] Hidden False [] Nothing
137-- The monad for the main REPL - reading and processing files and updating
138-- global state (hence the IO inner monad).
139type Idris = StateT IState (InputT IO)
141-- Commands in the REPL
143data Target = ViaC | ViaJava
156 | Compile Target String
162 | AddProof (Maybe Name)
181data Opt = Filename String
213 | OutputTy OutputType
216-- Parsed declarations
218data Fixity = Infixl { prec :: Int }
219 | Infixr { prec :: Int }
220 | InfixN { prec :: Int }
221 | PrefixN { prec :: Int }
224deriving instance Binary Fixity
227instance Show Fixity where
228 show (Infixl i) = "infixl " ++ show i
229 show (Infixr i) = "infixr " ++ show i
230 show (InfixN i) = "infix " ++ show i
231 show (PrefixN i) = "prefix " ++ show i
233data FixDecl = Fix Fixity String
236deriving instance Binary FixDecl
239instance Ord FixDecl where
240 compare (Fix x _) (Fix y _) = compare (prec x) (prec y)
243data Static = Static | Dynamic
246deriving instance Binary Static
249-- Mark bindings with their explicitness, and laziness
250data Plicity = Imp { plazy :: Bool,
253 | Exp { plazy :: Bool,
256 | Constraint { plazy :: Bool,
259 | TacImp { plazy :: Bool,
266deriving instance Binary Plicity
269impl = Imp False Dynamic ""
270expl = Exp False Dynamic ""
271constraint = Constraint False Dynamic ""
272tacimpl t = TacImp False Dynamic t ""
274data FnOpt = Inlinable | TotalFn | PartialFn
275 | Coinductive | AssertTotal | TCGen
276 | CExport String -- export, with a C name
277 | Specialise [Name] -- specialise it, freeze these names
280deriving instance Binary FnOpt
285inlinable :: FnOpts -> Bool
286inlinable = elem Inlinable
288data PDecl' t = PFix FC Fixity [String] -- fixity declaration
289 | PTy String SyntaxInfo FC FnOpts Name t -- type declaration
290 | PClauses FC FnOpts Name [PClause' t] -- pattern clause
291 | PCAF FC Name t -- top level constant
292 | PData String SyntaxInfo FC Bool -- codata
293 (PData' t) -- data declaration
294 | PParams FC [(Name, t)] [PDecl' t] -- params block
295 | PNamespace String [PDecl' t] -- new namespace
296 | PRecord String SyntaxInfo FC Name t String Name t -- record declaration
297 | PClass String SyntaxInfo FC
300 [(Name, t)] -- parameters
301 [PDecl' t] -- declarations
302 | PInstance SyntaxInfo FC [t] -- constraints
305 t -- full instance type
306 (Maybe Name) -- explicit name
310 | PMutual FC [PDecl' t]
311 | PDirective (Idris ())
314deriving instance Binary PDecl'
317data PClause' t = PClause FC Name t [t] t [PDecl' t]
318 | PWith FC Name t [t] t [PDecl' t]
319 | PClauseR FC [t] t [PDecl' t]
320 | PWithR FC [t] t [PDecl' t]
323deriving instance Binary PClause'
326data PData' t = PDatadecl { d_name :: Name,
328 d_cons :: [(String, Name, t, FC)] }
329 | PLaterdecl { d_name :: Name, d_tcon :: t }
332deriving instance Binary PData'
335-- Handy to get a free function for applying PTerm -> PTerm functions
336-- across a program, by deriving Functor
338type PDecl = PDecl' PTerm
339type PData = PData' PTerm
340type PClause = PClause' PTerm
342-- get all the names declared in a decl
344declared :: PDecl -> [Name]
345declared (PFix _ _ _) = []
346declared (PTy _ _ _ _ n t) = [n]
347declared (PClauses _ _ n _) = [] -- not a declaration
348declared (PRecord _ _ _ n _ _ c _) = [n, c]
349declared (PData _ _ _ _ (PDatadecl n _ ts)) = n : map fstt ts
350 where fstt (_, a, _, _) = a
351declared (PParams _ _ ds) = concatMap declared ds
352declared (PMutual _ ds) = concatMap declared ds
353declared (PNamespace _ ds) = concatMap declared ds
354-- declared (PImport _) = []
356defined :: PDecl -> [Name]
357defined (PFix _ _ _) = []
358defined (PTy _ _ _ _ n t) = []
359defined (PClauses _ _ n _) = [n] -- not a declaration
360defined (PRecord _ _ _ n _ _ c _) = [n, c]
361defined (PData _ _ _ _ (PDatadecl n _ ts)) = n : map fstt ts
362 where fstt (_, a, _, _) = a
363defined (PParams _ _ ds) = concatMap defined ds
364defined (PMutual _ ds) = concatMap defined ds
365defined (PNamespace _ ds) = concatMap defined ds
366-- declared (PImport _) = []
368updateN :: [(Name, Name)] -> Name -> Name
369updateN ns n | Just n' <- lookup n ns = n'
372updateNs :: [(Name, Name)] -> PTerm -> PTerm
374updateNs ns t = mapPT updateRef t
375 where updateRef (PRef fc f) = PRef fc (updateN ns f)
378-- updateDNs :: [(Name, Name)] -> PDecl -> PDecl
380-- updateDNs ns (PTy s f n t) | Just n' <- lookup n ns = PTy s f n' t
381-- updateDNs ns (PClauses f n c) | Just n' <- lookup n ns = PClauses f n' (map updateCNs c)
382-- where updateCNs ns (PClause n l ts r ds)
383-- = PClause (updateN ns n) (fmap (updateNs ns) l)
384-- (map (fmap (updateNs ns)) ts)
385-- (fmap (updateNs ns) r)
386-- (map (updateDNs ns) ds)
389-- High level language terms
391data PTerm = PQuote Raw
394 | PLam Name PTerm PTerm
395 | PPi Plicity Name PTerm PTerm
396 | PLet Name PTerm PTerm PTerm
397 | PTyped PTerm PTerm -- term with explicit type
398 | PApp FC PTerm [PArg]
399 | PCase FC PTerm [(PTerm, PTerm)]
405 | PPair FC PTerm PTerm
406 | PDPair FC PTerm PTerm PTerm
407 | PAlternative Bool [PTerm] -- True if only one may work
408 | PHidden PTerm -- irrelevant or hidden pattern
417 | PTactics [PTactic] -- as PProof, but no auto solving
418 | PElabError Err -- error to report on elaboration
419 | PImpossible -- special case for declaring when an LHS can't typecheck
422deriving instance Binary PTerm
425mapPT :: (PTerm -> PTerm) -> PTerm -> PTerm
426mapPT f t = f (mpt t) where
427 mpt (PLam n t s) = PLam n (mapPT f t) (mapPT f s)
428 mpt (PPi p n t s) = PPi p n (mapPT f t) (mapPT f s)
429 mpt (PLet n ty v s) = PLet n (mapPT f ty) (mapPT f v) (mapPT f s)
430 mpt (PApp fc t as) = PApp fc (mapPT f t) (map (fmap (mapPT f)) as)
431 mpt (PCase fc c os) = PCase fc (mapPT f c) (map (pmap (mapPT f)) os)
432 mpt (PEq fc l r) = PEq fc (mapPT f l) (mapPT f r)
433 mpt (PTyped l r) = PTyped (mapPT f l) (mapPT f r)
434 mpt (PPair fc l r) = PPair fc (mapPT f l) (mapPT f r)
435 mpt (PDPair fc l t r) = PDPair fc (mapPT f l) (mapPT f t) (mapPT f r)
436 mpt (PAlternative a as) = PAlternative a (map (mapPT f) as)
437 mpt (PHidden t) = PHidden (mapPT f t)
438 mpt (PDoBlock ds) = PDoBlock (map (fmap (mapPT f)) ds)
439 mpt (PProof ts) = PProof (map (fmap (mapPT f)) ts)
440 mpt (PTactics ts) = PTactics (map (fmap (mapPT f)) ts)
444data PTactic' t = Intro [Name] | Intros | Focus Name
445 | Refine Name [Bool] | Rewrite t | LetTac Name t
446 | Exact t | Compute | Trivial
449 | ProofState | ProofTerm | Undo
450 | Try (PTactic' t) (PTactic' t)
451 | TSeq (PTactic' t) (PTactic' t)
453 deriving (Show, Eq, Functor)
455deriving instance Binary PTactic'
458instance Sized a => Sized (PTactic' a) where
459 size (Intro nms) = 1 + size nms
461 size (Focus nm) = 1 + size nm
462 size (Refine nm bs) = 1 + size nm + length bs
463 size (Rewrite t) = 1 + size t
464 size (LetTac nm t) = 1 + size nm + size t
465 size (Exact t) = 1 + size t
473 size (Try l r) = 1 + size l + size r
474 size (TSeq l r) = 1 + size l + size r
478type PTactic = PTactic' PTerm
480data PDo' t = DoExp FC t
485 deriving (Eq, Functor)
487deriving instance Binary PDo'
490instance Sized a => Sized (PDo' a) where
491 size (DoExp fc t) = 1 + size fc + size t
492 size (DoBind fc nm t) = 1 + size fc + size nm + size t
493 size (DoBindP fc l r) = 1 + size fc + size l + size r
494 size (DoLet fc nm l r) = 1 + size fc + size nm + size l + size r
495 size (DoLetP fc l r) = 1 + size fc + size l + size r
499-- The priority gives a hint as to elaboration order. Best to elaborate
500-- things early which will help give a more concrete type to other
501-- variables, e.g. a before (interpTy a).
503data PArg' t = PImp { priority :: Int,
504 lazyarg :: Bool, pname :: Name, getTm :: t,
506 | PExp { priority :: Int,
507 lazyarg :: Bool, getTm :: t,
509 | PConstraint { priority :: Int,
510 lazyarg :: Bool, getTm :: t,
512 | PTacImplicit { priority :: Int,
513 lazyarg :: Bool, pname :: Name,
517 deriving (Show, Eq, Functor)
519instance Sized a => Sized (PArg' a) where
520 size (PImp p l nm trm _) = 1 + size nm + size trm
521 size (PExp p l trm _) = 1 + size trm
522 size (PConstraint p l trm _) = 1 + size trm
523 size (PTacImplicit p l nm scr trm _) = 1 + size nm + size scr + size trm
526deriving instance Binary PArg'
529pimp n t = PImp 0 True n t ""
530pexp t = PExp 0 False t ""
531pconst t = PConstraint 0 False t ""
532ptacimp n s t = PTacImplicit 0 True n s t ""
534type PArg = PArg' PTerm
538data ClassInfo = CI { instanceName :: Name,
539 class_methods :: [(Name, (FnOpts, PTerm))],
540 class_defaults :: [(Name, (Name, PDecl))], -- method name -> default impl
541 class_params :: [Name],
542 class_instances :: [Name] }
545deriving instance Binary ClassInfo
548data OptInfo = Optimise { collapsible :: Bool,
549 forceable :: [Int], -- argument positions
553deriving instance Binary OptInfo
557data TypeInfo = TI { con_names :: [Name], codata :: Bool }
560deriving instance Binary TypeInfo
563-- Syntactic sugar info
565data DSL' t = DSL { dsl_bind :: t,
570 index_first :: Maybe t,
571 index_next :: Maybe t,
572 dsl_lambda :: Maybe t,
575 deriving (Show, Functor)
577deriving instance Binary DSL'
582data SynContext = PatternSyntax | TermSyntax | AnySyntax
585deriving instance Binary SynContext
588data Syntax = Rule [SSymbol] PTerm SynContext
591deriving instance Binary Syntax
594data SSymbol = Keyword Name
601deriving instance Binary SSymbol
604initDSL = DSL (PRef f (UN ">>="))
605 (PRef f (UN "return"))
613 where f = FC "(builtin)" 0
615data SyntaxInfo = Syn { using :: [(Name, PTerm)],
616 syn_params :: [(Name, PTerm)],
617 syn_namespace :: [String],
619 decoration :: Name -> Name,
621 implicitAllowed :: Bool,
625deriving instance Binary SyntaxInfo
628defaultSyntax = Syn [] [] [] [] id False False initDSL
630expandNS :: SyntaxInfo -> Name -> Name
631expandNS syn n@(NS _ _) = n
632expandNS syn n = case syn_namespace syn of
637--- Pretty printing declarations and terms
639instance Show PTerm where
640 show tm = showImp False tm
642instance Pretty PTerm where
643 pretty = prettyImp False
645instance Show PDecl where
646 show d = showDeclImp False d
648instance Show PClause where
649 show c = showCImp True c
651instance Show PData where
652 show d = showDImp False d
654showDeclImp _ (PFix _ f ops) = show f ++ " " ++ showSep ", " ops
655showDeclImp t (PTy _ _ _ _ n ty) = show n ++ " : " ++ showImp t ty
656showDeclImp _ (PClauses _ _ n c) = showSep "\n" (map show c)
657showDeclImp _ (PData _ _ _ _ d) = show d
658showDeclImp _ (PParams f ns ps) = "parameters " ++ show ns ++ "\n" ++
659 showSep "\n" (map show ps)
662showCImp :: Bool -> PClause -> String
663showCImp impl (PClause _ n l ws r w)
664 = showImp impl l ++ showWs ws ++ " = " ++ showImp impl r
665 ++ " where " ++ show w
668 showWs (x : xs) = " | " ++ showImp impl x ++ showWs xs
669showCImp impl (PWith _ n l ws r w)
670 = showImp impl l ++ showWs ws ++ " with " ++ showImp impl r
671 ++ " { " ++ show w ++ " } "
674 showWs (x : xs) = " | " ++ showImp impl x ++ showWs xs
677showDImp :: Bool -> PData -> String
678showDImp impl (PDatadecl n ty cons)
679 = "data " ++ show n ++ " : " ++ showImp impl ty ++ " where\n\t"
681 (map (\ (_, n, t, _) -> show n ++ " : " ++ showImp impl t) cons)
683getImps :: [PArg] -> [(Name, PTerm)]
685getImps (PImp _ _ n tm _ : xs) = (n, tm) : getImps xs
686getImps (_ : xs) = getImps xs
688getExps :: [PArg] -> [PTerm]
690getExps (PExp _ _ tm _ : xs) = tm : getExps xs
691getExps (_ : xs) = getExps xs
693getConsts :: [PArg] -> [PTerm]
695getConsts (PConstraint _ _ tm _ : xs) = tm : getConsts xs
696getConsts (_ : xs) = getConsts xs
698getAll :: [PArg] -> [PTerm]
701prettyImp :: Bool -> PTerm -> Doc
702prettyImp impl = prettySe 10
704 prettySe p (PQuote r) =
705 if size r > breakingSize then
706 text "![" $$ pretty r <> text "]"
708 text "![" <> pretty r <> text "]"
709 prettySe p (PPatvar fc n) = pretty n
710 prettySe p (PRef fc n) =
716 prettyBasic n@(UN _) = pretty n
717 prettyBasic (MN _ s) = text s
718 prettyBasic (NS n s) = (foldr (<>) empty (intersperse (text ".") (map text $ reverse s))) <> prettyBasic n
719 prettySe p (PLam n ty sc) =
721 if size sc > breakingSize then
722 text "λ" <> pretty n <+> text "=>" $+$ pretty sc
724 text "λ" <> pretty n <+> text "=>" <+> pretty sc
725 prettySe p (PLet n ty v sc) =
727 if size sc > breakingSize then
728 text "let" <+> pretty n <+> text "=" <+> prettySe 10 v <+> text "in" $+$
729 nest nestingSize (prettySe 10 sc)
731 text "let" <+> pretty n <+> text "=" <+> prettySe 10 v <+> text "in" <+>
733 prettySe p (PPi (Exp l s _) n ty sc)
734 | n `elem` allNamesIn sc || impl =
735 let open = if l then text "|" <> lparen else lparen in
737 if size sc > breakingSize then
738 open <> pretty n <+> colon <+> prettySe 10 ty <> rparen <+>
739 st <+> text "->" $+$ prettySe 10 sc
741 open <> pretty n <+> colon <+> prettySe 10 ty <> rparen <+>
742 st <+> text "->" <+> prettySe 10 sc
745 if size sc > breakingSize then
746 prettySe 0 ty <+> st <+> text "->" $+$ prettySe 10 sc
748 prettySe 0 ty <+> st <+> text "->" <+> prettySe 10 sc
752 Static -> text "[static]"
754 prettySe p (PPi (Imp l s _) n ty sc)
756 let open = if l then text "|" <> lbrace else lbrace in
758 if size sc > breakingSize then
759 open <> pretty n <+> colon <+> prettySe 10 ty <> rbrace <+>
760 st <+> text "->" <+> prettySe 10 sc
762 open <> pretty n <+> colon <+> prettySe 10 ty <> rbrace <+>
763 st <+> text "->" <+> prettySe 10 sc
764 | otherwise = prettySe 10 sc
768 Static -> text $ "[static]"
770 prettySe p (PPi (Constraint _ _ _) n ty sc) =
772 if size sc > breakingSize then
773 prettySe 10 ty <+> text "=>" <+> prettySe 10 sc
775 prettySe 10 ty <+> text "=>" $+$ prettySe 10 sc
776 prettySe p (PPi (TacImp _ _ s _) n ty sc) =
778 if size sc > breakingSize then
779 lbrace <> text "tacimp" <+> pretty n <+> colon <+> prettySe 10 ty <>
780 rbrace <+> text "->" $+$ prettySe 10 sc
782 lbrace <> text "tacimp" <+> pretty n <+> colon <+> prettySe 10 ty <>
783 rbrace <+> text "->" <+> prettySe 10 sc
784 prettySe p (PApp _ (PRef _ f) [])
785 | not impl = pretty f
786 prettySe p (PApp _ (PRef _ op@(UN (f:_))) args)
787 | length (getExps args) == 2 && (not impl) && (not $ isAlpha f) =
788 let [l, r] = getExps args in
790 if size r > breakingSize then
791 prettySe 1 l <+> pretty op $+$ prettySe 0 r
793 prettySe 1 l <+> pretty op <+> prettySe 0 r
794 prettySe p (PApp _ f as) =
795 let args = getExps as in
800 -- foldr (<+>) empty $ map prettyArgS as
803 -- foldr (<+>) empty $ map prettyArgSe args
806 if size r > breakingSize then
807 l $+$ nest nestingSize (prettyArgS r)
812 if size r > breakingSize then
813 l $+$ nest nestingSize (prettyArgSe r)
816 prettySe p (PCase _ scr opts) =
817 text "case" <+> prettySe 10 scr <+> text "of" $+$ nest nestingSize prettyBody
819 prettyBody = foldr ($$) empty $ intersperse (text "|") $ map sc opts
821 sc (l, r) = prettySe 10 l <+> text "=>" <+> prettySe 10 r
822 prettySe p (PHidden tm) = text "." <> prettySe 0 tm
823 prettySe p (PRefl _ _) = text "refl"
824 prettySe p (PResolveTC _) = text "resolvetc"
825 prettySe p (PTrue _) = text "()"
826 prettySe p (PFalse _) = text "_|_"
827 prettySe p (PEq _ l r) =
829 if size r > breakingSize then
830 prettySe 10 l <+> text "=" $$ nest nestingSize (prettySe 10 r)
832 prettySe 10 l <+> text "=" <+> prettySe 10 r
833 prettySe p (PTyped l r) =
834 lparen <> prettySe 10 l <+> colon <+> prettySe 10 r <> rparen
835 prettySe p (PPair _ l r) =
836 if size r > breakingSize then
837 lparen <> prettySe 10 l <> text "," $+$
838 prettySe 10 r <> rparen
840 lparen <> prettySe 10 l <> text "," <+> prettySe 10 r <> rparen
841 prettySe p (PDPair _ l t r) =
842 if size r > breakingSize then
843 lparen <> prettySe 10 l <+> text "**" $+$
844 prettySe 10 r <> rparen
846 lparen <> prettySe 10 l <+> text "**" <+> prettySe 10 r <> rparen
847 prettySe p (PAlternative a as) =
848 lparen <> text "|" <> prettyAs <> text "|" <> rparen
851 foldr (\l -> \r -> l <+> text "," <+> r) empty $ map (prettySe 10) as
852 prettySe p PSet = text "Set"
853 prettySe p (PConstant c) = pretty c
854 -- XXX: add pretty for tactics
855 prettySe p (PProof ts) =
856 text "proof" <+> lbrace $+$ nest nestingSize (text . show $ ts) $+$ rbrace
857 prettySe p (PTactics ts) =
858 text "tactics" <+> lbrace $+$ nest nestingSize (text . show $ ts) $+$ rbrace
859 prettySe p (PMetavar n) = text "?" <> pretty n
860 prettySe p (PReturn f) = text "return"
861 prettySe p PImpossible = text "impossible"
862 prettySe p Placeholder = text "_"
863 prettySe p (PDoBlock _) = text "do block pretty not implemented"
864 prettySe p (PElabError s) = pretty s
866 prettySe p _ = text "test"
868 prettyArgS (PImp _ _ n tm _) = prettyArgSi (n, tm)
869 prettyArgS (PExp _ _ tm _) = prettyArgSe tm
870 prettyArgS (PConstraint _ _ tm _) = prettyArgSc tm
871 prettyArgS (PTacImplicit _ _ n _ tm _) = prettyArgSti (n, tm)
873 prettyArgSe arg = prettySe 0 arg
874 prettyArgSi (n, val) = lbrace <> pretty n <+> text "=" <+> prettySe 10 val <> rbrace
875 prettyArgSc val = lbrace <> lbrace <> prettySe 10 val <> rbrace <> rbrace
876 prettyArgSti (n, val) = lbrace <> text "auto" <+> pretty n <+> text "=" <+> prettySe 10 val <> rbrace
878 bracket outer inner doc
879 | inner > outer = lparen <> doc <> rparen
882showImp :: Bool -> PTerm -> String
883showImp impl tm = se 10 tm where
884 se p (PQuote r) = "![" ++ show r ++ "]"
885 se p (PPatvar fc n) = show n
886 se p (PRef fc n) = if impl then show n -- ++ "[" ++ show fc ++ "]"
888 where showbasic n@(UN _) = show n
889 showbasic (MN _ s) = s
890 showbasic (NS n s) = showSep "." (reverse s) ++ "." ++ showbasic n
891 se p (PLam n ty sc) = bracket p 2 $ "\\ " ++ show n ++
892 (if impl then " : " ++ se 10 ty else "") ++ " => "
894 se p (PLet n ty v sc) = bracket p 2 $ "let " ++ show n ++ " = " ++ se 10 v ++
896 se p (PPi (Exp l s _) n ty sc)
897 | n `elem` allNamesIn sc || impl
899 if l then "|(" else "(" ++
900 show n ++ " : " ++ se 10 ty ++
903 | otherwise = bracket p 2 $ se 0 ty ++ " " ++ st ++ "-> " ++ se 10 sc
905 Static -> "[static] "
907 se p (PPi (Imp l s _) n ty sc)
908 | impl = bracket p 2 $ if l then "|{" else "{" ++
909 show n ++ " : " ++ se 10 ty ++
910 "} " ++ st ++ "-> " ++ se 10 sc
911 | otherwise = se 10 sc
913 Static -> "[static] "
915 se p (PPi (Constraint _ _ _) n ty sc)
916 = bracket p 2 $ se 10 ty ++ " => " ++ se 10 sc
917 se p (PPi (TacImp _ _ s _) n ty sc)
918 = bracket p 2 $ "{tacimp " ++ show n ++ " : " ++ se 10 ty ++ "} -> " ++ se 10 sc
919 se p (PApp _ (PRef _ f) [])
921 se p (PApp _ (PRef _ op@(UN (f:_))) args)
922 | length (getExps args) == 2 && not impl && not (isAlpha f)
923 = let [l, r] = getExps args in
924 bracket p 1 $ se 1 l ++ " " ++ show op ++ " " ++ se 0 r
926 = let args = getExps as in
927 bracket p 1 $ se 1 f ++ if impl then concatMap sArg as
928 else concatMap seArg args
929 se p (PCase _ scr opts) = "case " ++ se 10 scr ++ " of " ++ showSep " | " (map sc opts)
930 where sc (l, r) = se 10 l ++ " => " ++ se 10 r
931 se p (PHidden tm) = "." ++ se 0 tm
934 | otherwise = "refl {" ++ se 10 t ++ "}"
935 se p (PResolveTC _) = "resolvetc"
936 se p (PTrue _) = "()"
937 se p (PFalse _) = "_|_"
938 se p (PEq _ l r) = bracket p 2 $ se 10 l ++ " = " ++ se 10 r
939 se p (PTyped l r) = "(" ++ se 10 l ++ " : " ++ se 10 r ++ ")"
940 se p (PPair _ l r) = "(" ++ se 10 l ++ ", " ++ se 10 r ++ ")"
941 se p (PDPair _ l t r) = "(" ++ se 10 l ++ " ** " ++ se 10 r ++ ")"
942 se p (PAlternative a as) = "(|" ++ showSep " , " (map (se 10) as) ++ "|)"
944 se p (PConstant c) = show c
945 se p (PProof ts) = "proof { " ++ show ts ++ "}"
946 se p (PTactics ts) = "tactics { " ++ show ts ++ "}"
947 se p (PMetavar n) = "?" ++ show n
948 se p (PReturn f) = "return"
949 se p PImpossible = "impossible"
950 se p Placeholder = "_"
951 se p (PDoBlock _) = "do block show not implemented"
952 se p (PElabError s) = show s
953-- se p x = "Not implemented"
955 sArg (PImp _ _ n tm _) = siArg (n, tm)
956 sArg (PExp _ _ tm _) = seArg tm
957 sArg (PConstraint _ _ tm _) = scArg tm
958 sArg (PTacImplicit _ _ n _ tm _) = stiArg (n, tm)
960 seArg arg = " " ++ se 0 arg
961 siArg (n, val) = " {" ++ show n ++ " = " ++ se 10 val ++ "}"
962 scArg val = " {{" ++ se 10 val ++ "}}"
963 stiArg (n, val) = " {auto " ++ show n ++ " = " ++ se 10 val ++ "}"
965 bracket outer inner str | inner > outer = "(" ++ str ++ ")"
969instance Sized PTerm where
970 size (PQuote rawTerm) = size rawTerm
971 size (PRef fc name) = size name
972 size (PLam name ty bdy) = 1 + size ty + size bdy
973 size (PPi plicity name ty bdy) = 1 + size ty + size bdy
974 size (PLet name ty def bdy) = 1 + size ty + size def + size bdy
975 size (PTyped trm ty) = 1 + size trm + size ty
976 size (PApp fc name args) = 1 + size args
977 size (PCase fc trm bdy) = 1 + size trm + size bdy
980 size (PRefl fc _) = 1
981 size (PResolveTC fc) = 1
982 size (PEq fc left right) = 1 + size left + size right
983 size (PPair fc left right) = 1 + size left + size right
984 size (PDPair fs left ty right) = 1 + size left + size ty + size right
985 size (PAlternative a alts) = 1 + size alts
986 size (PHidden hidden) = size hidden
988 size (PConstant const) = 1 + size const
990 size (PDoBlock dos) = 1 + size dos
991 size (PIdiom fc term) = 1 + size term
992 size (PReturn fc) = 1
993 size (PMetavar name) = 1
994 size (PProof tactics) = size tactics
995 size (PElabError err) = size err
998allNamesIn :: PTerm -> [Name]
999allNamesIn tm = nub $ ni [] tm
1002 | not (n `elem` env) = [n]
1003 ni env (PApp _ f as) = ni env f ++ concatMap (ni env) (map getTm as)
1004 ni env (PCase _ c os) = ni env c ++ concatMap (ni env) (map snd os)
1005 ni env (PLam n ty sc) = ni env ty ++ ni (n:env) sc
1006 ni env (PPi _ n ty sc) = ni env ty ++ ni (n:env) sc
1007 ni env (PHidden tm) = ni env tm
1008 ni env (PEq _ l r) = ni env l ++ ni env r
1009 ni env (PTyped l r) = ni env l ++ ni env r
1010 ni env (PPair _ l r) = ni env l ++ ni env r
1011 ni env (PDPair _ (PRef _ n) t r) = ni env t ++ ni (n:env) r
1012 ni env (PDPair _ l t r) = ni env l ++ ni env t ++ ni env r
1013 ni env (PAlternative a ls) = concatMap (ni env) ls
1016namesIn :: [(Name, PTerm)] -> IState -> PTerm -> [Name]
1017namesIn uvars ist tm = nub $ ni [] tm
1020 | not (n `elem` env)
1021 = case lookupTy Nothing n (tt_ctxt ist) of
1023 _ -> if n `elem` (map fst uvars) then [n] else []
1024 ni env (PApp _ f as) = ni env f ++ concatMap (ni env) (map getTm as)
1025 ni env (PCase _ c os) = ni env c ++ concatMap (ni env) (map snd os)
1026 ni env (PLam n ty sc) = ni env ty ++ ni (n:env) sc
1027 ni env (PPi _ n ty sc) = ni env ty ++ ni (n:env) sc
1028 ni env (PEq _ l r) = ni env l ++ ni env r
1029 ni env (PTyped l r) = ni env l ++ ni env r
1030 ni env (PPair _ l r) = ni env l ++ ni env r
1031 ni env (PDPair _ (PRef _ n) t r) = ni env t ++ ni (n:env) r
1032 ni env (PDPair _ l t r) = ni env l ++ ni env t ++ ni env r
1033 ni env (PAlternative a as) = concatMap (ni env) as
1034 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