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 | PData SyntaxInfo FC (PData' t) -- data declaration
249 | PParams FC [(Name, t)] [PDecl' t] -- params block
250 | PNamespace String [PDecl' t] -- new namespace
251 | PRecord SyntaxInfo FC Name t Name t -- record declaration
252 | PClass SyntaxInfo FC
255 [(Name, t)] -- parameters
256 [PDecl' t] -- declarations
257 | PInstance SyntaxInfo FC [t] -- constraints
260 t -- full instance type
261 (Maybe Name) -- explicit name
265 | PDirective (Idris ())
268deriving instance Binary PDecl'
271data PClause' t = PClause FC Name t [t] t [PDecl' t]
272 | PWith FC Name t [t] t [PDecl' t]
273 | PClauseR FC [t] t [PDecl' t]
274 | PWithR FC [t] t [PDecl' t]
277deriving instance Binary PClause'
280data PData' t = PDatadecl { d_name :: Name,
282 d_cons :: [(Name, t, FC)] }
285deriving instance Binary PData'
288-- Handy to get a free function for applying PTerm -> PTerm functions
289-- across a program, by deriving Functor
291type PDecl = PDecl' PTerm
292type PData = PData' PTerm
293type PClause = PClause' PTerm
295-- get all the names declared in a decl
297declared :: PDecl -> [Name]
298declared (PFix _ _ _) = []
299declared (PTy _ _ _ n t) = [n]
300declared (PClauses _ _ n _) = [] -- not a declaration
301declared (PData _ _ (PDatadecl n _ ts)) = n : map fstt ts
302 where fstt (a, _, _) = a
303declared (PParams _ _ ds) = concatMap declared ds
304declared (PNamespace _ ds) = concatMap declared ds
305-- declared (PImport _) = []
307defined :: PDecl -> [Name]
308defined (PFix _ _ _) = []
309defined (PTy _ _ _ n t) = []
310defined (PClauses _ _ n _) = [n] -- not a declaration
311defined (PData _ _ (PDatadecl n _ ts)) = n : map fstt ts
312 where fstt (a, _, _) = a
313defined (PParams _ _ ds) = concatMap defined ds
314defined (PNamespace _ ds) = concatMap defined ds
315-- declared (PImport _) = []
317updateN :: [(Name, Name)] -> Name -> Name
318updateN ns n | Just n' <- lookup n ns = n'
321updateNs :: [(Name, Name)] -> PTerm -> PTerm
323updateNs ns t = mapPT updateRef t
324 where updateRef (PRef fc f) = PRef fc (updateN ns f)
327-- updateDNs :: [(Name, Name)] -> PDecl -> PDecl
329-- updateDNs ns (PTy s f n t) | Just n' <- lookup n ns = PTy s f n' t
330-- updateDNs ns (PClauses f n c) | Just n' <- lookup n ns = PClauses f n' (map updateCNs c)
331-- where updateCNs ns (PClause n l ts r ds)
332-- = PClause (updateN ns n) (fmap (updateNs ns) l)
333-- (map (fmap (updateNs ns)) ts)
334-- (fmap (updateNs ns) r)
335-- (map (updateDNs ns) ds)
338-- High level language terms
340data PTerm = PQuote Raw
342 | PLam Name PTerm PTerm
343 | PPi Plicity Name PTerm PTerm
344 | PLet Name PTerm PTerm PTerm
345 | PTyped PTerm PTerm -- term with explicit type
346 | PApp FC PTerm [PArg]
347 | PCase FC PTerm [(PTerm, PTerm)]
353 | PPair FC PTerm PTerm
354 | PDPair FC PTerm PTerm PTerm
355 | PAlternative Bool [PTerm] -- True if only one may work
356 | PHidden PTerm -- irrelevant or hidden pattern
365 | PTactics [PTactic] -- as PProof, but no auto solving
366 | PElabError Err -- error to report on elaboration
367 | PImpossible -- special case for declaring when an LHS can't typecheck
370deriving instance Binary PTerm
373mapPT :: (PTerm -> PTerm) -> PTerm -> PTerm
374mapPT f t = f (mpt t) where
375 mpt (PLam n t s) = PLam n (mapPT f t) (mapPT f s)
376 mpt (PPi p n t s) = PPi p n (mapPT f t) (mapPT f s)
377 mpt (PLet n ty v s) = PLet n (mapPT f ty) (mapPT f v) (mapPT f s)
378 mpt (PApp fc t as) = PApp fc (mapPT f t) (map (fmap (mapPT f)) as)
379 mpt (PCase fc c os) = PCase fc (mapPT f c) (map (pmap (mapPT f)) os)
380 mpt (PEq fc l r) = PEq fc (mapPT f l) (mapPT f r)
381 mpt (PTyped l r) = PTyped (mapPT f l) (mapPT f r)
382 mpt (PPair fc l r) = PPair fc (mapPT f l) (mapPT f r)
383 mpt (PDPair fc l t r) = PDPair fc (mapPT f l) (mapPT f t) (mapPT f r)
384 mpt (PAlternative a as) = PAlternative a (map (mapPT f) as)
385 mpt (PHidden t) = PHidden (mapPT f t)
386 mpt (PDoBlock ds) = PDoBlock (map (fmap (mapPT f)) ds)
387 mpt (PProof ts) = PProof (map (fmap (mapPT f)) ts)
388 mpt (PTactics ts) = PTactics (map (fmap (mapPT f)) ts)
392data PTactic' t = Intro [Name] | Intros | Focus Name
393 | Refine Name [Bool] | Rewrite t | LetTac Name t
394 | Exact t | Compute | Trivial
397 | ProofState | ProofTerm | Undo
398 | Try (PTactic' t) (PTactic' t)
399 | TSeq (PTactic' t) (PTactic' t)
401 deriving (Show, Eq, Functor)
403deriving instance Binary PTactic'
406instance Sized a => Sized (PTactic' a) where
407 size (Intro nms) = 1 + size nms
409 size (Focus nm) = 1 + size nm
410 size (Refine nm bs) = 1 + size nm + length bs
411 size (Rewrite t) = 1 + size t
412 size (LetTac nm t) = 1 + size nm + size t
413 size (Exact t) = 1 + size t
421 size (Try l r) = 1 + size l + size r
422 size (TSeq l r) = 1 + size l + size r
426type PTactic = PTactic' PTerm
428data PDo' t = DoExp FC t
433 deriving (Eq, Functor)
435deriving instance Binary PDo'
438instance Sized a => Sized (PDo' a) where
439 size (DoExp fc t) = 1 + size fc + size t
440 size (DoBind fc nm t) = 1 + size fc + size nm + size t
441 size (DoBindP fc l r) = 1 + size fc + size l + size r
442 size (DoLet fc nm l r) = 1 + size fc + size nm + size l + size r
443 size (DoLetP fc l r) = 1 + size fc + size l + size r
447-- The priority gives a hint as to elaboration order. Best to elaborate
448-- things early which will help give a more concrete type to other
449-- variables, e.g. a before (interpTy a).
451data PArg' t = PImp { priority :: Int,
452 lazyarg :: Bool, pname :: Name, getTm :: t }
453 | PExp { priority :: Int,
454 lazyarg :: Bool, getTm :: t }
455 | PConstraint { priority :: Int,
456 lazyarg :: Bool, getTm :: t }
457 | PTacImplicit { priority :: Int,
458 lazyarg :: Bool, pname :: Name,
461 deriving (Show, Eq, Functor)
463instance Sized a => Sized (PArg' a) where
464 size (PImp p l nm trm) = 1 + size nm + size trm
465 size (PExp p l trm) = 1 + size trm
466 size (PConstraint p l trm) = 1 + size trm
467 size (PTacImplicit p l nm scr trm) = 1 + size nm + size scr + size trm
470deriving instance Binary PArg'
475pconst = PConstraint 0 False
476ptacimp = PTacImplicit 0 True
478type PArg = PArg' PTerm
482data ClassInfo = CI { instanceName :: Name,
483 class_methods :: [(Name, (FnOpts, PTerm))],
484 class_defaults :: [(Name, (Name, PDecl))], -- method name -> default impl
485 class_params :: [Name],
486 class_instances :: [Name] }
489deriving instance Binary ClassInfo
492data OptInfo = Optimise { collapsible :: Bool,
493 forceable :: [Int], -- argument positions
497deriving instance Binary OptInfo
501data TypeInfo = TI { con_names :: [Name] }
504deriving instance Binary TypeInfo
507-- Syntactic sugar info
509data DSL' t = DSL { dsl_bind :: t,
514 index_first :: Maybe t,
515 index_next :: Maybe t,
516 dsl_lambda :: Maybe t,
519 deriving (Show, Functor)
521deriving instance Binary DSL'
526data SynContext = PatternSyntax | TermSyntax | AnySyntax
529deriving instance Binary SynContext
532data Syntax = Rule [SSymbol] PTerm SynContext
535deriving instance Binary Syntax
538data SSymbol = Keyword Name
545deriving instance Binary SSymbol
548initDSL = DSL (PRef f (UN ">>="))
549 (PRef f (UN "return"))
557 where f = FC "(builtin)" 0
559data SyntaxInfo = Syn { using :: [(Name, PTerm)],
560 syn_params :: [(Name, PTerm)],
561 syn_namespace :: [String],
563 decoration :: Name -> Name,
565 implicitAllowed :: Bool,
569deriving instance Binary SyntaxInfo
572defaultSyntax = Syn [] [] [] [] id False False initDSL
574expandNS :: SyntaxInfo -> Name -> Name
575expandNS syn n@(NS _ _) = n
576expandNS syn n = case syn_namespace syn of
581--- Pretty printing declarations and terms
583instance Show PTerm where
584 show tm = showImp False tm
586instance Pretty PTerm where
587 pretty = prettyImp False
589instance Show PDecl where
590 show d = showDeclImp False d
592instance Show PClause where
593 show c = showCImp True c
595instance Show PData where
596 show d = showDImp False d
598showDeclImp _ (PFix _ f ops) = show f ++ " " ++ showSep ", " ops
599showDeclImp t (PTy _ _ _ n ty) = show n ++ " : " ++ showImp t ty
600showDeclImp _ (PClauses _ _ n c) = showSep "\n" (map show c)
601showDeclImp _ (PData _ _ d) = show d
603showCImp :: Bool -> PClause -> String
604showCImp impl (PClause _ n l ws r w)
605 = showImp impl l ++ showWs ws ++ " = " ++ showImp impl r
606 ++ " where " ++ show w
609 showWs (x : xs) = " | " ++ showImp impl x ++ showWs xs
610showCImp impl (PWith _ n l ws r w)
611 = showImp impl l ++ showWs ws ++ " with " ++ showImp impl r
612 ++ " { " ++ show w ++ " } "
615 showWs (x : xs) = " | " ++ showImp impl x ++ showWs xs
618showDImp :: Bool -> PData -> String
619showDImp impl (PDatadecl n ty cons)
620 = "data " ++ show n ++ " : " ++ showImp impl ty ++ " where\n\t"
622 (map (\ (n, t, _) -> show n ++ " : " ++ showImp impl t) cons)
624getImps :: [PArg] -> [(Name, PTerm)]
626getImps (PImp _ _ n tm : xs) = (n, tm) : getImps xs
627getImps (_ : xs) = getImps xs
629getExps :: [PArg] -> [PTerm]
631getExps (PExp _ _ tm : xs) = tm : getExps xs
632getExps (_ : xs) = getExps xs
634getConsts :: [PArg] -> [PTerm]
636getConsts (PConstraint _ _ tm : xs) = tm : getConsts xs
637getConsts (_ : xs) = getConsts xs
639getAll :: [PArg] -> [PTerm]
642prettyImp :: Bool -> PTerm -> Doc
643prettyImp impl = prettySe 10
645 prettySe p (PQuote r) =
646 if size r > breakingSize then
647 text "![" $$ pretty r <> text "]"
649 text "![" <> pretty r <> text "]"
650 prettySe p (PRef fc n) =
656 prettyBasic n@(UN _) = pretty n
657 prettyBasic (MN _ s) = text s
658 prettyBasic (NS n s) = (foldr (<>) empty (intersperse (text ".") (map text $ reverse s))) <> prettyBasic n
659 prettySe p (PLam n ty sc) =
661 if size sc > breakingSize then
662 text "λ" <> pretty n <+> text "=>" $+$ pretty sc
664 text "λ" <> pretty n <+> text "=>" <+> pretty sc
665 prettySe p (PLet n ty v sc) =
667 if size sc > breakingSize then
668 text "let" <+> pretty n <+> text "=" <+> prettySe 10 v <+> text "in" $+$
669 nest nestingSize (prettySe 10 sc)
671 text "let" <+> pretty n <+> text "=" <+> prettySe 10 v <+> text "in" <+>
673 prettySe p (PPi (Exp l s) n ty sc)
674 | n `elem` allNamesIn sc || impl =
675 let open = if l then text "|" <> lparen else lparen in
677 if size sc > breakingSize then
678 open <> pretty n <+> colon <+> prettySe 10 ty <> rparen <+>
679 st <+> text "->" $+$ prettySe 10 sc
681 open <> pretty n <+> colon <+> prettySe 10 ty <> rparen <+>
682 st <+> text "->" <+> prettySe 10 sc
685 if size sc > breakingSize then
686 prettySe 0 ty <+> st <+> text "->" $+$ prettySe 10 sc
688 prettySe 0 ty <+> st <+> text "->" <+> prettySe 10 sc
692 Static -> text "[static]"
694 prettySe p (PPi (Imp l s) n ty sc)
696 let open = if l then text "|" <> lbrace else lbrace in
698 if size sc > breakingSize then
699 open <> pretty n <+> colon <+> prettySe 10 ty <> rbrace <+>
700 st <+> text "->" <+> prettySe 10 sc
702 open <> pretty n <+> colon <+> prettySe 10 ty <> rbrace <+>
703 st <+> text "->" <+> prettySe 10 sc
704 | otherwise = prettySe 10 sc
708 Static -> text $ "[static]"
710 prettySe p (PPi (Constraint _ _) n ty sc) =
712 if size sc > breakingSize then
713 prettySe 10 ty <+> text "=>" <+> prettySe 10 sc
715 prettySe 10 ty <+> text "=>" $+$ prettySe 10 sc
716 prettySe p (PPi (TacImp _ _ s) n ty sc) =
718 if size sc > breakingSize then
719 lbrace <> text "tacimp" <+> pretty n <+> colon <+> prettySe 10 ty <>
720 rbrace <+> text "->" $+$ prettySe 10 sc
722 lbrace <> text "tacimp" <+> pretty n <+> colon <+> prettySe 10 ty <>
723 rbrace <+> text "->" <+> prettySe 10 sc
724 prettySe p (PApp _ (PRef _ f) [])
725 | not impl = pretty f
726 prettySe p (PApp _ (PRef _ op@(UN (f:_))) args)
727 | length (getExps args) == 2 && (not impl) && (not $ isAlpha f) =
728 let [l, r] = getExps args in
730 if size r > breakingSize then
731 prettySe 1 l <+> pretty op $+$ prettySe 0 r
733 prettySe 1 l <+> pretty op <+> prettySe 0 r
734 prettySe p (PApp _ f as) =
735 let args = getExps as in
740 -- foldr (<+>) empty $ map prettyArgS as
743 -- foldr (<+>) empty $ map prettyArgSe args
746 if size r > breakingSize then
747 l $+$ nest nestingSize (prettyArgS r)
752 if size r > breakingSize then
753 l $+$ nest nestingSize (prettyArgSe r)
756 prettySe p (PCase _ scr opts) =
757 text "case" <+> prettySe 10 scr <+> text "of" $+$ nest nestingSize prettyBody
759 prettyBody = foldr ($$) empty $ intersperse (text "|") $ map sc opts
761 sc (l, r) = prettySe 10 l <+> text "=>" <+> prettySe 10 r
762 prettySe p (PHidden tm) = text "." <> prettySe 0 tm
763 prettySe p (PRefl _) = text "refl"
764 prettySe p (PResolveTC _) = text "resolvetc"
765 prettySe p (PTrue _) = text "()"
766 prettySe p (PFalse _) = text "_|_"
767 prettySe p (PEq _ l r) =
769 if size r > breakingSize then
770 prettySe 10 l <+> text "=" $$ nest nestingSize (prettySe 10 r)
772 prettySe 10 l <+> text "=" <+> prettySe 10 r
773 prettySe p (PTyped l r) =
774 lparen <> prettySe 10 l <+> colon <+> prettySe 10 r <> rparen
775 prettySe p (PPair _ l r) =
776 if size r > breakingSize then
777 lparen <> prettySe 10 l <> text "," $+$
778 prettySe 10 r <> rparen
780 lparen <> prettySe 10 l <> text "," <+> prettySe 10 r <> rparen
781 prettySe p (PDPair _ l t r) =
782 if size r > breakingSize then
783 lparen <> prettySe 10 l <+> text "**" $+$
784 prettySe 10 r <> rparen
786 lparen <> prettySe 10 l <+> text "**" <+> prettySe 10 r <> rparen
787 prettySe p (PAlternative a as) =
788 lparen <> text "|" <> prettyAs <> text "|" <> rparen
791 foldr (\l -> \r -> l <+> text "," <+> r) empty $ map (prettySe 10) as
792 prettySe p PSet = text "Set"
793 prettySe p (PConstant c) = pretty c
794 -- XXX: add pretty for tactics
795 prettySe p (PProof ts) =
796 text "proof" <+> lbrace $+$ nest nestingSize (text . show $ ts) $+$ rbrace
797 prettySe p (PTactics ts) =
798 text "tactics" <+> lbrace $+$ nest nestingSize (text . show $ ts) $+$ rbrace
799 prettySe p (PMetavar n) = text "?" <> pretty n
800 prettySe p (PReturn f) = text "return"
801 prettySe p PImpossible = text "impossible"
802 prettySe p Placeholder = text "_"
803 prettySe p (PDoBlock _) = text "do block pretty not implemented"
804 prettySe p (PElabError s) = pretty s
806 prettySe p _ = text "test"
808 prettyArgS (PImp _ _ n tm) = prettyArgSi (n, tm)
809 prettyArgS (PExp _ _ tm) = prettyArgSe tm
810 prettyArgS (PConstraint _ _ tm) = prettyArgSc tm
811 prettyArgS (PTacImplicit _ _ n _ tm) = prettyArgSti (n, tm)
813 prettyArgSe arg = prettySe 0 arg
814 prettyArgSi (n, val) = lbrace <> pretty n <+> text "=" <+> prettySe 10 val <> rbrace
815 prettyArgSc val = lbrace <> lbrace <> prettySe 10 val <> rbrace <> rbrace
816 prettyArgSti (n, val) = lbrace <> text "auto" <+> pretty n <+> text "=" <+> prettySe 10 val <> rbrace
818 bracket outer inner doc
819 | inner > outer = lparen <> doc <> rparen
822showImp :: Bool -> PTerm -> String
823showImp impl tm = se 10 tm where
824 se p (PQuote r) = "![" ++ show r ++ "]"
825 se p (PRef fc n) = if impl then show n -- ++ "[" ++ show fc ++ "]"
827 where showbasic n@(UN _) = show n
828 showbasic (MN _ s) = s
829 showbasic (NS n s) = showSep "." (reverse s) ++ "." ++ showbasic n
830 se p (PLam n ty sc) = bracket p 2 $ "\\ " ++ show n ++
831 (if impl then " : " ++ se 10 ty else "") ++ " => "
833 se p (PLet n ty v sc) = bracket p 2 $ "let " ++ show n ++ " = " ++ se 10 v ++
835 se p (PPi (Exp l s) n ty sc)
836 | n `elem` allNamesIn sc || impl
838 if l then "|(" else "(" ++
839 show n ++ " : " ++ se 10 ty ++
842 | otherwise = bracket p 2 $ se 0 ty ++ " " ++ st ++ "-> " ++ se 10 sc
844 Static -> "[static] "
846 se p (PPi (Imp l s) n ty sc)
847 | impl = bracket p 2 $ if l then "|{" else "{" ++
848 show n ++ " : " ++ se 10 ty ++
849 "} " ++ st ++ "-> " ++ se 10 sc
850 | otherwise = se 10 sc
852 Static -> "[static] "
854 se p (PPi (Constraint _ _) n ty sc)
855 = bracket p 2 $ se 10 ty ++ " => " ++ se 10 sc
856 se p (PPi (TacImp _ _ s) n ty sc)
857 = bracket p 2 $ "{tacimp " ++ show n ++ " : " ++ se 10 ty ++ "} -> " ++ se 10 sc
858 se p (PApp _ (PRef _ f) [])
860 se p (PApp _ (PRef _ op@(UN (f:_))) args)
861 | length (getExps args) == 2 && not impl && not (isAlpha f)
862 = let [l, r] = getExps args in
863 bracket p 1 $ se 1 l ++ " " ++ show op ++ " " ++ se 0 r
865 = let args = getExps as in
866 bracket p 1 $ se 1 f ++ if impl then concatMap sArg as
867 else concatMap seArg args
868 se p (PCase _ scr opts) = "case " ++ se 10 scr ++ " of " ++ showSep " | " (map sc opts)
869 where sc (l, r) = se 10 l ++ " => " ++ se 10 r
870 se p (PHidden tm) = "." ++ se 0 tm
871 se p (PRefl _) = "refl"
872 se p (PResolveTC _) = "resolvetc"
873 se p (PTrue _) = "()"
874 se p (PFalse _) = "_|_"
875 se p (PEq _ l r) = bracket p 2 $ se 10 l ++ " = " ++ se 10 r
876 se p (PTyped l r) = "(" ++ se 10 l ++ " : " ++ se 10 r ++ ")"
877 se p (PPair _ l r) = "(" ++ se 10 l ++ ", " ++ se 10 r ++ ")"
878 se p (PDPair _ l t r) = "(" ++ se 10 l ++ " ** " ++ se 10 r ++ ")"
879 se p (PAlternative a as) = "(|" ++ showSep " , " (map (se 10) as) ++ "|)"
881 se p (PConstant c) = show c
882 se p (PProof ts) = "proof { " ++ show ts ++ "}"
883 se p (PTactics ts) = "tactics { " ++ show ts ++ "}"
884 se p (PMetavar n) = "?" ++ show n
885 se p (PReturn f) = "return"
886 se p PImpossible = "impossible"
887 se p Placeholder = "_"
888 se p (PDoBlock _) = "do block show not implemented"
889 se p (PElabError s) = show s
890-- se p x = "Not implemented"
892 sArg (PImp _ _ n tm) = siArg (n, tm)
893 sArg (PExp _ _ tm) = seArg tm
894 sArg (PConstraint _ _ tm) = scArg tm
895 sArg (PTacImplicit _ _ n _ tm) = stiArg (n, tm)
897 seArg arg = " " ++ se 0 arg
898 siArg (n, val) = " {" ++ show n ++ " = " ++ se 10 val ++ "}"
899 scArg val = " {{" ++ se 10 val ++ "}}"
900 stiArg (n, val) = " {auto " ++ show n ++ " = " ++ se 10 val ++ "}"
902 bracket outer inner str | inner > outer = "(" ++ str ++ ")"
908 | PLam Name PTerm PTerm
909 | PPi Plicity Name PTerm PTerm
910 | PLet Name PTerm PTerm PTerm
911 | PTyped PTerm PTerm -- term with explicit type
912 | PApp FC PTerm [PArg]
913 | PCase FC PTerm [(PTerm, PTerm)]
919 | PPair FC PTerm PTerm
920 | PDPair FC PTerm PTerm PTerm
921 | PAlternative [PTerm]
922 | PHidden PTerm -- irrelevant or hidden pattern
931 | PTactics [PTactic] -- as PProof, but no auto solving
932 | PElabError Err -- error to report on elaboration
933 | PImpossible -- special case for declaring when an LHS can't typecheck
936instance Sized PTerm where
937 size (PQuote rawTerm) = size rawTerm
938 size (PRef fc name) = size name
939 size (PLam name ty bdy) = 1 + size ty + size bdy
940 size (PPi plicity name ty bdy) = 1 + size ty + size bdy
941 size (PLet name ty def bdy) = 1 + size ty + size def + size bdy
942 size (PTyped trm ty) = 1 + size trm + size ty
943 size (PApp fc name args) = 1 + size args
944 size (PCase fc trm bdy) = 1 + size trm + size bdy
948 size (PResolveTC fc) = 1
949 size (PEq fc left right) = 1 + size left + size right
950 size (PPair fc left right) = 1 + size left + size right
951 size (PDPair fs left ty right) = 1 + size left + size ty + size right
952 size (PAlternative a alts) = 1 + size alts
953 size (PHidden hidden) = size hidden
955 size (PConstant const) = 1 + size const
957 size (PDoBlock dos) = 1 + size dos
958 size (PIdiom fc term) = 1 + size term
959 size (PReturn fc) = 1
960 size (PMetavar name) = 1
961 size (PProof tactics) = size tactics
962 size (PElabError err) = size err
965allNamesIn :: PTerm -> [Name]
966allNamesIn tm = nub $ ni [] tm
969 | not (n `elem` env) = [n]
970 ni env (PApp _ f as) = ni env f ++ concatMap (ni env) (map getTm as)
971 ni env (PCase _ c os) = ni env c ++ concatMap (ni env) (map snd os)
972 ni env (PLam n ty sc) = ni env ty ++ ni (n:env) sc
973 ni env (PPi _ n ty sc) = ni env ty ++ ni (n:env) sc
974 ni env (PHidden tm) = ni env tm
975 ni env (PEq _ l r) = ni env l ++ ni env r
976 ni env (PTyped l r) = ni env l ++ ni env r
977 ni env (PPair _ l r) = ni env l ++ ni env r
978 ni env (PDPair _ (PRef _ n) t r) = ni env t ++ ni (n:env) r
979 ni env (PDPair _ l t r) = ni env l ++ ni env t ++ ni env r
980 ni env (PAlternative a ls) = concatMap (ni env) ls
983namesIn :: [(Name, PTerm)] -> IState -> PTerm -> [Name]
984namesIn uvars ist tm = nub $ ni [] tm
988 = case lookupTy Nothing n (tt_ctxt ist) of
990 _ -> if n `elem` (map fst uvars) then [n] else []
991 ni env (PApp _ f as) = ni env f ++ concatMap (ni env) (map getTm as)
992 ni env (PCase _ c os) = ni env c ++ concatMap (ni env) (map snd os)
993 ni env (PLam n ty sc) = ni env ty ++ ni (n:env) sc
994 ni env (PPi _ n ty sc) = ni env ty ++ ni (n:env) sc
995 ni env (PEq _ l r) = ni env l ++ ni env r
996 ni env (PTyped l r) = ni env l ++ ni env r
997 ni env (PPair _ l r) = ni env l ++ ni env r
998 ni env (PDPair _ (PRef _ n) t r) = ni env t ++ ni (n:env) r
999 ni env (PDPair _ l t r) = ni env l ++ ni env t ++ ni env r
1000 ni env (PAlternative a as) = concatMap (ni env) as
1001 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