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_totcheck :: [(FC, Name)],
62 idris_options :: IOption,
64 idris_metavars :: [Name],
65 syntax_rules :: [Syntax],
66 syntax_keywords :: [String],
67 imported :: [FilePath],
68 idris_scprims :: [(Name, (Int, PrimFn))],
69 idris_objs :: [FilePath],
70 idris_libs :: [String],
71 idris_hdrs :: [String],
72 proof_list :: [(Name, [String])],
74 lastParse :: Maybe Name,
75 indent_stack :: [Int],
76 brace_stack :: [Maybe Int],
77 hide_list :: [(Name, Maybe Accessibility)],
78 default_access :: Accessibility,
79 default_total :: Bool,
80 ibc_write :: [IBCWrite],
81 compiled_so :: Maybe String
84data SizeChange = Smaller | Same | Bigger | Unknown
87deriving instance Binary SizeChange
90type SCGEntry = (Name, [Maybe (Int, SizeChange)])
92data CGInfo = CGInfo { argsdef :: [Name],
93 calls :: [(Name, [[Name]])],
99deriving instance Binary CGInfo
102primDefs = [UN "unsafePerformIO", UN "mkLazyForeign", UN "mkForeign", UN "FalseElim"]
104-- information that needs writing for the current module's .ibc file
105data IBCWrite = IBCFix FixDecl
109 | IBCInstance Bool Name Name
119 | IBCAccess Name Accessibility
120 | IBCTotal Name Totality
121 | IBCFlags Name [FnOpt]
123 | IBCDef Name -- i.e. main context
126idrisInit = IState initContext [] [] emptyContext emptyContext emptyContext
127 emptyContext emptyContext emptyContext emptyContext
128 emptyContext emptyContext emptyContext
129 [] "" defaultOpts 6 [] [] [] [] [] [] [] []
130 [] Nothing Nothing [] [] [] Hidden False [] Nothing
132-- The monad for the main REPL - reading and processing files and updating
133-- global state (hence the IO inner monad).
134type Idris = StateT IState (InputT IO)
136-- Commands in the REPL
138data Target = ViaC | ViaJava
149 | Compile Target String
155 | AddProof (Maybe Name)
174data Opt = Filename String
209-- Parsed declarations
211data Fixity = Infixl { prec :: Int }
212 | Infixr { prec :: Int }
213 | InfixN { prec :: Int }
214 | PrefixN { prec :: Int }
217deriving instance Binary Fixity
220instance Show Fixity where
221 show (Infixl i) = "infixl " ++ show i
222 show (Infixr i) = "infixr " ++ show i
223 show (InfixN i) = "infix " ++ show i
224 show (PrefixN i) = "prefix " ++ show i
226data FixDecl = Fix Fixity String
229deriving instance Binary FixDecl
232instance Ord FixDecl where
233 compare (Fix x _) (Fix y _) = compare (prec x) (prec y)
236data Static = Static | Dynamic
239deriving instance Binary Static
242-- Mark bindings with their explicitness, and laziness
243data Plicity = Imp { plazy :: Bool,
245 | Exp { plazy :: Bool,
247 | Constraint { plazy :: Bool,
249 | TacImp { plazy :: Bool,
255deriving instance Binary Plicity
258impl = Imp False Dynamic
259expl = Exp False Dynamic
260constraint = Constraint False Dynamic
261tacimpl = TacImp False Dynamic
263data FnOpt = Inlinable | TotalFn | PartialFn
264 | Coinductive | AssertTotal | TCGen
265 | CExport String -- export, with a C name
266 | Specialise [Name] -- specialise it, freeze these names
269deriving instance Binary FnOpt
274inlinable :: FnOpts -> Bool
275inlinable = elem Inlinable
277data PDecl' t = PFix FC Fixity [String] -- fixity declaration
278 | PTy SyntaxInfo FC FnOpts Name t -- type declaration
279 | PClauses FC FnOpts Name [PClause' t] -- pattern clause
280 | PCAF FC Name t -- top level constant
281 | PData SyntaxInfo FC Bool -- codata
282 (PData' t) -- data declaration
283 | PParams FC [(Name, t)] [PDecl' t] -- params block
284 | PNamespace String [PDecl' t] -- new namespace
285 | PRecord SyntaxInfo FC Name t Name t -- record declaration
286 | PClass SyntaxInfo FC
289 [(Name, t)] -- parameters
290 [PDecl' t] -- declarations
291 | PInstance SyntaxInfo FC [t] -- constraints
294 t -- full instance type
295 (Maybe Name) -- explicit name
299 | PDirective (Idris ())
302deriving instance Binary PDecl'
305data PClause' t = PClause FC Name t [t] t [PDecl' t]
306 | PWith FC Name t [t] t [PDecl' t]
307 | PClauseR FC [t] t [PDecl' t]
308 | PWithR FC [t] t [PDecl' t]
311deriving instance Binary PClause'
314data PData' t = PDatadecl { d_name :: Name,
316 d_cons :: [(Name, t, FC)] }
319deriving instance Binary PData'
322-- Handy to get a free function for applying PTerm -> PTerm functions
323-- across a program, by deriving Functor
325type PDecl = PDecl' PTerm
326type PData = PData' PTerm
327type PClause = PClause' PTerm
329-- get all the names declared in a decl
331declared :: PDecl -> [Name]
332declared (PFix _ _ _) = []
333declared (PTy _ _ _ n t) = [n]
334declared (PClauses _ _ n _) = [] -- not a declaration
335declared (PData _ _ _ (PDatadecl n _ ts)) = n : map fstt ts
336 where fstt (a, _, _) = a
337declared (PParams _ _ ds) = concatMap declared ds
338declared (PNamespace _ ds) = concatMap declared ds
339-- declared (PImport _) = []
341defined :: PDecl -> [Name]
342defined (PFix _ _ _) = []
343defined (PTy _ _ _ n t) = []
344defined (PClauses _ _ n _) = [n] -- not a declaration
345defined (PData _ _ _ (PDatadecl n _ ts)) = n : map fstt ts
346 where fstt (a, _, _) = a
347defined (PParams _ _ ds) = concatMap defined ds
348defined (PNamespace _ ds) = concatMap defined ds
349-- declared (PImport _) = []
351updateN :: [(Name, Name)] -> Name -> Name
352updateN ns n | Just n' <- lookup n ns = n'
355updateNs :: [(Name, Name)] -> PTerm -> PTerm
357updateNs ns t = mapPT updateRef t
358 where updateRef (PRef fc f) = PRef fc (updateN ns f)
361-- updateDNs :: [(Name, Name)] -> PDecl -> PDecl
363-- updateDNs ns (PTy s f n t) | Just n' <- lookup n ns = PTy s f n' t
364-- updateDNs ns (PClauses f n c) | Just n' <- lookup n ns = PClauses f n' (map updateCNs c)
365-- where updateCNs ns (PClause n l ts r ds)
366-- = PClause (updateN ns n) (fmap (updateNs ns) l)
367-- (map (fmap (updateNs ns)) ts)
368-- (fmap (updateNs ns) r)
369-- (map (updateDNs ns) ds)
372-- High level language terms
374data PTerm = PQuote Raw
377 | PLam Name PTerm PTerm
378 | PPi Plicity Name PTerm PTerm
379 | PLet Name PTerm PTerm PTerm
380 | PTyped PTerm PTerm -- term with explicit type
381 | PApp FC PTerm [PArg]
382 | PCase FC PTerm [(PTerm, PTerm)]
388 | PPair FC PTerm PTerm
389 | PDPair FC PTerm PTerm PTerm
390 | PAlternative Bool [PTerm] -- True if only one may work
391 | PHidden PTerm -- irrelevant or hidden pattern
400 | PTactics [PTactic] -- as PProof, but no auto solving
401 | PElabError Err -- error to report on elaboration
402 | PImpossible -- special case for declaring when an LHS can't typecheck
405deriving instance Binary PTerm
408mapPT :: (PTerm -> PTerm) -> PTerm -> PTerm
409mapPT f t = f (mpt t) where
410 mpt (PLam n t s) = PLam n (mapPT f t) (mapPT f s)
411 mpt (PPi p n t s) = PPi p n (mapPT f t) (mapPT f s)
412 mpt (PLet n ty v s) = PLet n (mapPT f ty) (mapPT f v) (mapPT f s)
413 mpt (PApp fc t as) = PApp fc (mapPT f t) (map (fmap (mapPT f)) as)
414 mpt (PCase fc c os) = PCase fc (mapPT f c) (map (pmap (mapPT f)) os)
415 mpt (PEq fc l r) = PEq fc (mapPT f l) (mapPT f r)
416 mpt (PTyped l r) = PTyped (mapPT f l) (mapPT f r)
417 mpt (PPair fc l r) = PPair fc (mapPT f l) (mapPT f r)
418 mpt (PDPair fc l t r) = PDPair fc (mapPT f l) (mapPT f t) (mapPT f r)
419 mpt (PAlternative a as) = PAlternative a (map (mapPT f) as)
420 mpt (PHidden t) = PHidden (mapPT f t)
421 mpt (PDoBlock ds) = PDoBlock (map (fmap (mapPT f)) ds)
422 mpt (PProof ts) = PProof (map (fmap (mapPT f)) ts)
423 mpt (PTactics ts) = PTactics (map (fmap (mapPT f)) ts)
427data PTactic' t = Intro [Name] | Intros | Focus Name
428 | Refine Name [Bool] | Rewrite t | LetTac Name t
429 | Exact t | Compute | Trivial
432 | ProofState | ProofTerm | Undo
433 | Try (PTactic' t) (PTactic' t)
434 | TSeq (PTactic' t) (PTactic' t)
436 deriving (Show, Eq, Functor)
438deriving instance Binary PTactic'
441instance Sized a => Sized (PTactic' a) where
442 size (Intro nms) = 1 + size nms
444 size (Focus nm) = 1 + size nm
445 size (Refine nm bs) = 1 + size nm + length bs
446 size (Rewrite t) = 1 + size t
447 size (LetTac nm t) = 1 + size nm + size t
448 size (Exact t) = 1 + size t
456 size (Try l r) = 1 + size l + size r
457 size (TSeq l r) = 1 + size l + size r
461type PTactic = PTactic' PTerm
463data PDo' t = DoExp FC t
468 deriving (Eq, Functor)
470deriving instance Binary PDo'
473instance Sized a => Sized (PDo' a) where
474 size (DoExp fc t) = 1 + size fc + size t
475 size (DoBind fc nm t) = 1 + size fc + size nm + size t
476 size (DoBindP fc l r) = 1 + size fc + size l + size r
477 size (DoLet fc nm l r) = 1 + size fc + size nm + size l + size r
478 size (DoLetP fc l r) = 1 + size fc + size l + size r
482-- The priority gives a hint as to elaboration order. Best to elaborate
483-- things early which will help give a more concrete type to other
484-- variables, e.g. a before (interpTy a).
486data PArg' t = PImp { priority :: Int,
487 lazyarg :: Bool, pname :: Name, getTm :: t }
488 | PExp { priority :: Int,
489 lazyarg :: Bool, getTm :: t }
490 | PConstraint { priority :: Int,
491 lazyarg :: Bool, getTm :: t }
492 | PTacImplicit { priority :: Int,
493 lazyarg :: Bool, pname :: Name,
496 deriving (Show, Eq, Functor)
498instance Sized a => Sized (PArg' a) where
499 size (PImp p l nm trm) = 1 + size nm + size trm
500 size (PExp p l trm) = 1 + size trm
501 size (PConstraint p l trm) = 1 + size trm
502 size (PTacImplicit p l nm scr trm) = 1 + size nm + size scr + size trm
505deriving instance Binary PArg'
510pconst = PConstraint 0 False
511ptacimp = PTacImplicit 0 True
513type PArg = PArg' PTerm
517data ClassInfo = CI { instanceName :: Name,
518 class_methods :: [(Name, (FnOpts, PTerm))],
519 class_defaults :: [(Name, (Name, PDecl))], -- method name -> default impl
520 class_params :: [Name],
521 class_instances :: [Name] }
524deriving instance Binary ClassInfo
527data OptInfo = Optimise { collapsible :: Bool,
528 forceable :: [Int], -- argument positions
532deriving instance Binary OptInfo
536data TypeInfo = TI { con_names :: [Name], codata :: Bool }
539deriving instance Binary TypeInfo
542-- Syntactic sugar info
544data DSL' t = DSL { dsl_bind :: t,
549 index_first :: Maybe t,
550 index_next :: Maybe t,
551 dsl_lambda :: Maybe t,
554 deriving (Show, Functor)
556deriving instance Binary DSL'
561data SynContext = PatternSyntax | TermSyntax | AnySyntax
564deriving instance Binary SynContext
567data Syntax = Rule [SSymbol] PTerm SynContext
570deriving instance Binary Syntax
573data SSymbol = Keyword Name
580deriving instance Binary SSymbol
583initDSL = DSL (PRef f (UN ">>="))
584 (PRef f (UN "return"))
592 where f = FC "(builtin)" 0
594data SyntaxInfo = Syn { using :: [(Name, PTerm)],
595 syn_params :: [(Name, PTerm)],
596 syn_namespace :: [String],
598 decoration :: Name -> Name,
600 implicitAllowed :: Bool,
604deriving instance Binary SyntaxInfo
607defaultSyntax = Syn [] [] [] [] id False False initDSL
609expandNS :: SyntaxInfo -> Name -> Name
610expandNS syn n@(NS _ _) = n
611expandNS syn n = case syn_namespace syn of
616--- Pretty printing declarations and terms
618instance Show PTerm where
619 show tm = showImp False tm
621instance Pretty PTerm where
622 pretty = prettyImp False
624instance Show PDecl where
625 show d = showDeclImp False d
627instance Show PClause where
628 show c = showCImp True c
630instance Show PData where
631 show d = showDImp False d
633showDeclImp _ (PFix _ f ops) = show f ++ " " ++ showSep ", " ops
634showDeclImp t (PTy _ _ _ n ty) = show n ++ " : " ++ showImp t ty
635showDeclImp _ (PClauses _ _ n c) = showSep "\n" (map show c)
636showDeclImp _ (PData _ _ _ d) = show d
637showDeclImp _ (PParams f ns ps) = "parameters " ++ show ns ++ "\n" ++
638 showSep "\n" (map show ps)
641showCImp :: Bool -> PClause -> String
642showCImp impl (PClause _ n l ws r w)
643 = showImp impl l ++ showWs ws ++ " = " ++ showImp impl r
644 ++ " where " ++ show w
647 showWs (x : xs) = " | " ++ showImp impl x ++ showWs xs
648showCImp impl (PWith _ n l ws r w)
649 = showImp impl l ++ showWs ws ++ " with " ++ showImp impl r
650 ++ " { " ++ show w ++ " } "
653 showWs (x : xs) = " | " ++ showImp impl x ++ showWs xs
656showDImp :: Bool -> PData -> String
657showDImp impl (PDatadecl n ty cons)
658 = "data " ++ show n ++ " : " ++ showImp impl ty ++ " where\n\t"
660 (map (\ (n, t, _) -> show n ++ " : " ++ showImp impl t) cons)
662getImps :: [PArg] -> [(Name, PTerm)]
664getImps (PImp _ _ n tm : xs) = (n, tm) : getImps xs
665getImps (_ : xs) = getImps xs
667getExps :: [PArg] -> [PTerm]
669getExps (PExp _ _ tm : xs) = tm : getExps xs
670getExps (_ : xs) = getExps xs
672getConsts :: [PArg] -> [PTerm]
674getConsts (PConstraint _ _ tm : xs) = tm : getConsts xs
675getConsts (_ : xs) = getConsts xs
677getAll :: [PArg] -> [PTerm]
680prettyImp :: Bool -> PTerm -> Doc
681prettyImp impl = prettySe 10
683 prettySe p (PQuote r) =
684 if size r > breakingSize then
685 text "![" $$ pretty r <> text "]"
687 text "![" <> pretty r <> text "]"
688 prettySe p (PPatvar fc n) = pretty n
689 prettySe p (PRef fc n) =
695 prettyBasic n@(UN _) = pretty n
696 prettyBasic (MN _ s) = text s
697 prettyBasic (NS n s) = (foldr (<>) empty (intersperse (text ".") (map text $ reverse s))) <> prettyBasic n
698 prettySe p (PLam n ty sc) =
700 if size sc > breakingSize then
701 text "λ" <> pretty n <+> text "=>" $+$ pretty sc
703 text "λ" <> pretty n <+> text "=>" <+> pretty sc
704 prettySe p (PLet n ty v sc) =
706 if size sc > breakingSize then
707 text "let" <+> pretty n <+> text "=" <+> prettySe 10 v <+> text "in" $+$
708 nest nestingSize (prettySe 10 sc)
710 text "let" <+> pretty n <+> text "=" <+> prettySe 10 v <+> text "in" <+>
712 prettySe p (PPi (Exp l s) n ty sc)
713 | n `elem` allNamesIn sc || impl =
714 let open = if l then text "|" <> lparen else lparen in
716 if size sc > breakingSize then
717 open <> pretty n <+> colon <+> prettySe 10 ty <> rparen <+>
718 st <+> text "->" $+$ prettySe 10 sc
720 open <> pretty n <+> colon <+> prettySe 10 ty <> rparen <+>
721 st <+> text "->" <+> prettySe 10 sc
724 if size sc > breakingSize then
725 prettySe 0 ty <+> st <+> text "->" $+$ prettySe 10 sc
727 prettySe 0 ty <+> st <+> text "->" <+> prettySe 10 sc
731 Static -> text "[static]"
733 prettySe p (PPi (Imp l s) n ty sc)
735 let open = if l then text "|" <> lbrace else lbrace in
737 if size sc > breakingSize then
738 open <> pretty n <+> colon <+> prettySe 10 ty <> rbrace <+>
739 st <+> text "->" <+> prettySe 10 sc
741 open <> pretty n <+> colon <+> prettySe 10 ty <> rbrace <+>
742 st <+> text "->" <+> prettySe 10 sc
743 | otherwise = prettySe 10 sc
747 Static -> text $ "[static]"
749 prettySe p (PPi (Constraint _ _) n ty sc) =
751 if size sc > breakingSize then
752 prettySe 10 ty <+> text "=>" <+> prettySe 10 sc
754 prettySe 10 ty <+> text "=>" $+$ prettySe 10 sc
755 prettySe p (PPi (TacImp _ _ s) n ty sc) =
757 if size sc > breakingSize then
758 lbrace <> text "tacimp" <+> pretty n <+> colon <+> prettySe 10 ty <>
759 rbrace <+> text "->" $+$ prettySe 10 sc
761 lbrace <> text "tacimp" <+> pretty n <+> colon <+> prettySe 10 ty <>
762 rbrace <+> text "->" <+> prettySe 10 sc
763 prettySe p (PApp _ (PRef _ f) [])
764 | not impl = pretty f
765 prettySe p (PApp _ (PRef _ op@(UN (f:_))) args)
766 | length (getExps args) == 2 && (not impl) && (not $ isAlpha f) =
767 let [l, r] = getExps args in
769 if size r > breakingSize then
770 prettySe 1 l <+> pretty op $+$ prettySe 0 r
772 prettySe 1 l <+> pretty op <+> prettySe 0 r
773 prettySe p (PApp _ f as) =
774 let args = getExps as in
779 -- foldr (<+>) empty $ map prettyArgS as
782 -- foldr (<+>) empty $ map prettyArgSe args
785 if size r > breakingSize then
786 l $+$ nest nestingSize (prettyArgS r)
791 if size r > breakingSize then
792 l $+$ nest nestingSize (prettyArgSe r)
795 prettySe p (PCase _ scr opts) =
796 text "case" <+> prettySe 10 scr <+> text "of" $+$ nest nestingSize prettyBody
798 prettyBody = foldr ($$) empty $ intersperse (text "|") $ map sc opts
800 sc (l, r) = prettySe 10 l <+> text "=>" <+> prettySe 10 r
801 prettySe p (PHidden tm) = text "." <> prettySe 0 tm
802 prettySe p (PRefl _ _) = text "refl"
803 prettySe p (PResolveTC _) = text "resolvetc"
804 prettySe p (PTrue _) = text "()"
805 prettySe p (PFalse _) = text "_|_"
806 prettySe p (PEq _ l r) =
808 if size r > breakingSize then
809 prettySe 10 l <+> text "=" $$ nest nestingSize (prettySe 10 r)
811 prettySe 10 l <+> text "=" <+> prettySe 10 r
812 prettySe p (PTyped l r) =
813 lparen <> prettySe 10 l <+> colon <+> prettySe 10 r <> rparen
814 prettySe p (PPair _ l r) =
815 if size r > breakingSize then
816 lparen <> prettySe 10 l <> text "," $+$
817 prettySe 10 r <> rparen
819 lparen <> prettySe 10 l <> text "," <+> prettySe 10 r <> rparen
820 prettySe p (PDPair _ l t r) =
821 if size r > breakingSize then
822 lparen <> prettySe 10 l <+> text "**" $+$
823 prettySe 10 r <> rparen
825 lparen <> prettySe 10 l <+> text "**" <+> prettySe 10 r <> rparen
826 prettySe p (PAlternative a as) =
827 lparen <> text "|" <> prettyAs <> text "|" <> rparen
830 foldr (\l -> \r -> l <+> text "," <+> r) empty $ map (prettySe 10) as
831 prettySe p PSet = text "Set"
832 prettySe p (PConstant c) = pretty c
833 -- XXX: add pretty for tactics
834 prettySe p (PProof ts) =
835 text "proof" <+> lbrace $+$ nest nestingSize (text . show $ ts) $+$ rbrace
836 prettySe p (PTactics ts) =
837 text "tactics" <+> lbrace $+$ nest nestingSize (text . show $ ts) $+$ rbrace
838 prettySe p (PMetavar n) = text "?" <> pretty n
839 prettySe p (PReturn f) = text "return"
840 prettySe p PImpossible = text "impossible"
841 prettySe p Placeholder = text "_"
842 prettySe p (PDoBlock _) = text "do block pretty not implemented"
843 prettySe p (PElabError s) = pretty s
845 prettySe p _ = text "test"
847 prettyArgS (PImp _ _ n tm) = prettyArgSi (n, tm)
848 prettyArgS (PExp _ _ tm) = prettyArgSe tm
849 prettyArgS (PConstraint _ _ tm) = prettyArgSc tm
850 prettyArgS (PTacImplicit _ _ n _ tm) = prettyArgSti (n, tm)
852 prettyArgSe arg = prettySe 0 arg
853 prettyArgSi (n, val) = lbrace <> pretty n <+> text "=" <+> prettySe 10 val <> rbrace
854 prettyArgSc val = lbrace <> lbrace <> prettySe 10 val <> rbrace <> rbrace
855 prettyArgSti (n, val) = lbrace <> text "auto" <+> pretty n <+> text "=" <+> prettySe 10 val <> rbrace
857 bracket outer inner doc
858 | inner > outer = lparen <> doc <> rparen
861showImp :: Bool -> PTerm -> String
862showImp impl tm = se 10 tm where
863 se p (PQuote r) = "![" ++ show r ++ "]"
864 se p (PPatvar fc n) = show n
865 se p (PRef fc n) = if impl then show n -- ++ "[" ++ show fc ++ "]"
867 where showbasic n@(UN _) = show n
868 showbasic (MN _ s) = s
869 showbasic (NS n s) = showSep "." (reverse s) ++ "." ++ showbasic n
870 se p (PLam n ty sc) = bracket p 2 $ "\\ " ++ show n ++
871 (if impl then " : " ++ se 10 ty else "") ++ " => "
873 se p (PLet n ty v sc) = bracket p 2 $ "let " ++ show n ++ " = " ++ se 10 v ++
875 se p (PPi (Exp l s) n ty sc)
876 | n `elem` allNamesIn sc || impl
878 if l then "|(" else "(" ++
879 show n ++ " : " ++ se 10 ty ++
882 | otherwise = bracket p 2 $ se 0 ty ++ " " ++ st ++ "-> " ++ se 10 sc
884 Static -> "[static] "
886 se p (PPi (Imp l s) n ty sc)
887 | impl = bracket p 2 $ if l then "|{" else "{" ++
888 show n ++ " : " ++ se 10 ty ++
889 "} " ++ st ++ "-> " ++ se 10 sc
890 | otherwise = se 10 sc
892 Static -> "[static] "
894 se p (PPi (Constraint _ _) n ty sc)
895 = bracket p 2 $ se 10 ty ++ " => " ++ se 10 sc
896 se p (PPi (TacImp _ _ s) n ty sc)
897 = bracket p 2 $ "{tacimp " ++ show n ++ " : " ++ se 10 ty ++ "} -> " ++ se 10 sc
898 se p (PApp _ (PRef _ f) [])
900 se p (PApp _ (PRef _ op@(UN (f:_))) args)
901 | length (getExps args) == 2 && not impl && not (isAlpha f)
902 = let [l, r] = getExps args in
903 bracket p 1 $ se 1 l ++ " " ++ show op ++ " " ++ se 0 r
905 = let args = getExps as in
906 bracket p 1 $ se 1 f ++ if impl then concatMap sArg as
907 else concatMap seArg args
908 se p (PCase _ scr opts) = "case " ++ se 10 scr ++ " of " ++ showSep " | " (map sc opts)
909 where sc (l, r) = se 10 l ++ " => " ++ se 10 r
910 se p (PHidden tm) = "." ++ se 0 tm
913 | otherwise = "refl {" ++ se 10 t ++ "}"
914 se p (PResolveTC _) = "resolvetc"
915 se p (PTrue _) = "()"
916 se p (PFalse _) = "_|_"
917 se p (PEq _ l r) = bracket p 2 $ se 10 l ++ " = " ++ se 10 r
918 se p (PTyped l r) = "(" ++ se 10 l ++ " : " ++ se 10 r ++ ")"
919 se p (PPair _ l r) = "(" ++ se 10 l ++ ", " ++ se 10 r ++ ")"
920 se p (PDPair _ l t r) = "(" ++ se 10 l ++ " ** " ++ se 10 r ++ ")"
921 se p (PAlternative a as) = "(|" ++ showSep " , " (map (se 10) as) ++ "|)"
923 se p (PConstant c) = show c
924 se p (PProof ts) = "proof { " ++ show ts ++ "}"
925 se p (PTactics ts) = "tactics { " ++ show ts ++ "}"
926 se p (PMetavar n) = "?" ++ show n
927 se p (PReturn f) = "return"
928 se p PImpossible = "impossible"
929 se p Placeholder = "_"
930 se p (PDoBlock _) = "do block show not implemented"
931 se p (PElabError s) = show s
932-- se p x = "Not implemented"
934 sArg (PImp _ _ n tm) = siArg (n, tm)
935 sArg (PExp _ _ tm) = seArg tm
936 sArg (PConstraint _ _ tm) = scArg tm
937 sArg (PTacImplicit _ _ n _ tm) = stiArg (n, tm)
939 seArg arg = " " ++ se 0 arg
940 siArg (n, val) = " {" ++ show n ++ " = " ++ se 10 val ++ "}"
941 scArg val = " {{" ++ se 10 val ++ "}}"
942 stiArg (n, val) = " {auto " ++ show n ++ " = " ++ se 10 val ++ "}"
944 bracket outer inner str | inner > outer = "(" ++ str ++ ")"
948instance Sized PTerm where
949 size (PQuote rawTerm) = size rawTerm
950 size (PRef fc name) = size name
951 size (PLam name ty bdy) = 1 + size ty + size bdy
952 size (PPi plicity name ty bdy) = 1 + size ty + size bdy
953 size (PLet name ty def bdy) = 1 + size ty + size def + size bdy
954 size (PTyped trm ty) = 1 + size trm + size ty
955 size (PApp fc name args) = 1 + size args
956 size (PCase fc trm bdy) = 1 + size trm + size bdy
959 size (PRefl fc _) = 1
960 size (PResolveTC fc) = 1
961 size (PEq fc left right) = 1 + size left + size right
962 size (PPair fc left right) = 1 + size left + size right
963 size (PDPair fs left ty right) = 1 + size left + size ty + size right
964 size (PAlternative a alts) = 1 + size alts
965 size (PHidden hidden) = size hidden
967 size (PConstant const) = 1 + size const
969 size (PDoBlock dos) = 1 + size dos
970 size (PIdiom fc term) = 1 + size term
971 size (PReturn fc) = 1
972 size (PMetavar name) = 1
973 size (PProof tactics) = size tactics
974 size (PElabError err) = size err
977allNamesIn :: PTerm -> [Name]
978allNamesIn tm = nub $ ni [] tm
981 | not (n `elem` env) = [n]
982 ni env (PApp _ f as) = ni env f ++ concatMap (ni env) (map getTm as)
983 ni env (PCase _ c os) = ni env c ++ concatMap (ni env) (map snd os)
984 ni env (PLam n ty sc) = ni env ty ++ ni (n:env) sc
985 ni env (PPi _ n ty sc) = ni env ty ++ ni (n:env) sc
986 ni env (PHidden tm) = ni env tm
987 ni env (PEq _ l r) = ni env l ++ ni env r
988 ni env (PTyped l r) = ni env l ++ ni env r
989 ni env (PPair _ l r) = ni env l ++ ni env r
990 ni env (PDPair _ (PRef _ n) t r) = ni env t ++ ni (n:env) r
991 ni env (PDPair _ l t r) = ni env l ++ ni env t ++ ni env r
992 ni env (PAlternative a ls) = concatMap (ni env) ls
995namesIn :: [(Name, PTerm)] -> IState -> PTerm -> [Name]
996namesIn uvars ist tm = nub $ ni [] tm
1000 = case lookupTy Nothing n (tt_ctxt ist) of
1002 _ -> if n `elem` (map fst uvars) then [n] else []
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 (PEq _ l r) = ni env l ++ ni env r
1008 ni env (PTyped l r) = ni env l ++ ni env r
1009 ni env (PPair _ l r) = ni env l ++ ni env r
1010 ni env (PDPair _ (PRef _ n) t r) = ni env t ++ ni (n:env) r
1011 ni env (PDPair _ l t r) = ni env l ++ ni env t ++ ni env r
1012 ni env (PAlternative a as) = concatMap (ni env) as
1013 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