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
25import qualified Epic.Epic as E
27data IOption = IOption { opt_logLevel :: Int,
29 opt_typeintype :: Bool,
32 opt_errContext :: Bool,
35 opt_ibcsubdir :: FilePath,
36 opt_importdirs :: [FilePath]
40defaultOpts = IOption 0 False False True False False True True "" []
42-- TODO: Add 'module data' to IState, which can be saved out and reloaded quickly (i.e
43-- without typechecking).
44-- This will include all the functions and data declarations, plus fixity declarations
47data IState = IState { tt_ctxt :: Context,
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 [Name],
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_prims :: [(Name, ([E.Name], E.Term))],
69 idris_scprims :: Prims,
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 ibc_write :: [IBCWrite],
81 compiled_so :: Maybe String
84primDefs = [UN "unsafePerformIO", UN "mkLazyForeign", UN "mkForeign", UN "FalseElim"]
86-- information that needs writing for the current module's .ibc file
87data IBCWrite = IBCFix FixDecl
91 | IBCInstance Bool Name Name
101 | IBCAccess Name Accessibility
102 | IBCTotal Name Totality
103 | IBCFlags Name [FnOpt]
105 | IBCDef Name -- i.e. main context
108idrisInit = IState initContext [] [] emptyContext emptyContext emptyContext
109 emptyContext emptyContext emptyContext emptyContext
110 emptyContext emptyContext emptyContext
111 [] "" defaultOpts 6 [] [] [] [] [] [] [] [] []
112 [] Nothing Nothing [] [] [] Hidden [] Nothing
114-- The monad for the main REPL - reading and processing files and updating
115-- global state (hence the IO inner monad).
116type Idris = StateT IState (InputT IO)
118-- Commands in the REPL
120data Command = Quit | Help | Eval PTerm | Check PTerm | TotCheck Name
122 | Compile String | Execute | ExecVal PTerm
124 | Metavars | Prove Name | AddProof | RmProof | Proofs | Universes
126 | LogLvl Int | Spec PTerm | HNF PTerm | Defn Name
127 | Info Name | DebugInfo Name
129 | SetOpt Opt | UnsetOpt Opt
132data Opt = Filename String
155-- Parsed declarations
157data Fixity = Infixl { prec :: Int }
158 | Infixr { prec :: Int }
159 | InfixN { prec :: Int }
160 | PrefixN { prec :: Int }
163deriving instance Binary Fixity
166instance Show Fixity where
167 show (Infixl i) = "infixl " ++ show i
168 show (Infixr i) = "infixr " ++ show i
169 show (InfixN i) = "infix " ++ show i
170 show (PrefixN i) = "prefix " ++ show i
172data FixDecl = Fix Fixity String
175deriving instance Binary FixDecl
178instance Ord FixDecl where
179 compare (Fix x _) (Fix y _) = compare (prec x) (prec y)
182data Static = Static | Dynamic
185deriving instance Binary Static
188-- Mark bindings with their explicitness, and laziness
189data Plicity = Imp { plazy :: Bool,
191 | Exp { plazy :: Bool,
193 | Constraint { plazy :: Bool,
195 | TacImp { plazy :: Bool,
201deriving instance Binary Plicity
204impl = Imp False Dynamic
205expl = Exp False Dynamic
206constraint = Constraint False Dynamic
207tacimpl = TacImp False Dynamic
209data FnOpt = Inlinable | TotalFn | AssertTotal | TCGen
210 | CExport String -- export, with a C name
211 | Specialise [Name] -- specialise it, freeze these names
214deriving instance Binary FnOpt
219inlinable :: FnOpts -> Bool
220inlinable = elem Inlinable
222data PDecl' t = PFix FC Fixity [String] -- fixity declaration
223 | PTy SyntaxInfo FC FnOpts Name t -- type declaration
224 | PClauses FC FnOpts Name [PClause' t] -- pattern clause
225 | PData SyntaxInfo FC (PData' t) -- data declaration
226 | PParams FC [(Name, t)] [PDecl' t] -- params block
227 | PNamespace String [PDecl' t] -- new namespace
228 | PRecord SyntaxInfo FC Name t Name t -- record declaration
229 | PClass SyntaxInfo FC
232 [(Name, t)] -- parameters
233 [PDecl' t] -- declarations
234 | PInstance SyntaxInfo FC [t] -- constraints
237 t -- full instance type
238 (Maybe Name) -- explicit name
242 | PDirective (Idris ())
245deriving instance Binary PDecl'
248data PClause' t = PClause FC Name t [t] t [PDecl' t]
249 | PWith FC Name t [t] t [PDecl' t]
250 | PClauseR FC [t] t [PDecl' t]
251 | PWithR FC [t] t [PDecl' t]
254deriving instance Binary PClause'
257data PData' t = PDatadecl { d_name :: Name,
259 d_cons :: [(Name, t, FC)] }
262deriving instance Binary PData'
265-- Handy to get a free function for applying PTerm -> PTerm functions
266-- across a program, by deriving Functor
268type PDecl = PDecl' PTerm
269type PData = PData' PTerm
270type PClause = PClause' PTerm
272-- get all the names declared in a decl
274declared :: PDecl -> [Name]
275declared (PFix _ _ _) = []
276declared (PTy _ _ _ n t) = [n]
277declared (PClauses _ _ n _) = [] -- not a declaration
278declared (PData _ _ (PDatadecl n _ ts)) = n : map fstt ts
279 where fstt (a, _, _) = a
280declared (PParams _ _ ds) = concatMap declared ds
281declared (PNamespace _ ds) = concatMap declared ds
282-- declared (PImport _) = []
284defined :: PDecl -> [Name]
285defined (PFix _ _ _) = []
286defined (PTy _ _ _ n t) = []
287defined (PClauses _ _ n _) = [n] -- not a declaration
288defined (PData _ _ (PDatadecl n _ ts)) = n : map fstt ts
289 where fstt (a, _, _) = a
290defined (PParams _ _ ds) = concatMap defined ds
291defined (PNamespace _ ds) = concatMap defined ds
292-- declared (PImport _) = []
294updateN :: [(Name, Name)] -> Name -> Name
295updateN ns n | Just n' <- lookup n ns = n'
298updateNs :: [(Name, Name)] -> PTerm -> PTerm
300updateNs ns t = mapPT updateRef t
301 where updateRef (PRef fc f) = PRef fc (updateN ns f)
304-- updateDNs :: [(Name, Name)] -> PDecl -> PDecl
306-- updateDNs ns (PTy s f n t) | Just n' <- lookup n ns = PTy s f n' t
307-- updateDNs ns (PClauses f n c) | Just n' <- lookup n ns = PClauses f n' (map updateCNs c)
308-- where updateCNs ns (PClause n l ts r ds)
309-- = PClause (updateN ns n) (fmap (updateNs ns) l)
310-- (map (fmap (updateNs ns)) ts)
311-- (fmap (updateNs ns) r)
312-- (map (updateDNs ns) ds)
315-- High level language terms
317data PTerm = PQuote Raw
319 | PLam Name PTerm PTerm
320 | PPi Plicity Name PTerm PTerm
321 | PLet Name PTerm PTerm PTerm
322 | PTyped PTerm PTerm -- term with explicit type
323 | PApp FC PTerm [PArg]
324 | PCase FC PTerm [(PTerm, PTerm)]
330 | PPair FC PTerm PTerm
331 | PDPair FC PTerm PTerm PTerm
332 | PAlternative Bool [PTerm] -- True if only one may work
333 | PHidden PTerm -- irrelevant or hidden pattern
342 | PTactics [PTactic] -- as PProof, but no auto solving
343 | PElabError Err -- error to report on elaboration
344 | PImpossible -- special case for declaring when an LHS can't typecheck
347deriving instance Binary PTerm
350mapPT :: (PTerm -> PTerm) -> PTerm -> PTerm
351mapPT f t = f (mpt t) where
352 mpt (PLam n t s) = PLam n (mapPT f t) (mapPT f s)
353 mpt (PPi p n t s) = PPi p n (mapPT f t) (mapPT f s)
354 mpt (PLet n ty v s) = PLet n (mapPT f ty) (mapPT f v) (mapPT f s)
355 mpt (PApp fc t as) = PApp fc (mapPT f t) (map (fmap (mapPT f)) as)
356 mpt (PCase fc c os) = PCase fc (mapPT f c) (map (pmap (mapPT f)) os)
357 mpt (PEq fc l r) = PEq fc (mapPT f l) (mapPT f r)
358 mpt (PTyped l r) = PTyped (mapPT f l) (mapPT f r)
359 mpt (PPair fc l r) = PPair fc (mapPT f l) (mapPT f r)
360 mpt (PDPair fc l t r) = PDPair fc (mapPT f l) (mapPT f t) (mapPT f r)
361 mpt (PAlternative a as) = PAlternative a (map (mapPT f) as)
362 mpt (PHidden t) = PHidden (mapPT f t)
363 mpt (PDoBlock ds) = PDoBlock (map (fmap (mapPT f)) ds)
364 mpt (PProof ts) = PProof (map (fmap (mapPT f)) ts)
365 mpt (PTactics ts) = PTactics (map (fmap (mapPT f)) ts)
369data PTactic' t = Intro [Name] | Intros | Focus Name
370 | Refine Name [Bool] | Rewrite t | LetTac Name t
371 | Exact t | Compute | Trivial
374 | ProofState | ProofTerm | Undo
375 | Try (PTactic' t) (PTactic' t)
376 | TSeq (PTactic' t) (PTactic' t)
378 deriving (Show, Eq, Functor)
380deriving instance Binary PTactic'
383instance Sized a => Sized (PTactic' a) where
384 size (Intro nms) = 1 + size nms
386 size (Focus nm) = 1 + size nm
387 size (Refine nm bs) = 1 + size nm + length bs
388 size (Rewrite t) = 1 + size t
389 size (LetTac nm t) = 1 + size nm + size t
390 size (Exact t) = 1 + size t
398 size (Try l r) = 1 + size l + size r
399 size (TSeq l r) = 1 + size l + size r
403type PTactic = PTactic' PTerm
405data PDo' t = DoExp FC t
410 deriving (Eq, Functor)
412deriving instance Binary PDo'
415instance Sized a => Sized (PDo' a) where
416 size (DoExp fc t) = 1 + size fc + size t
417 size (DoBind fc nm t) = 1 + size fc + size nm + size t
418 size (DoBindP fc l r) = 1 + size fc + size l + size r
419 size (DoLet fc nm l r) = 1 + size fc + size nm + size l + size r
420 size (DoLetP fc l r) = 1 + size fc + size l + size r
424-- The priority gives a hint as to elaboration order. Best to elaborate
425-- things early which will help give a more concrete type to other
426-- variables, e.g. a before (interpTy a).
428data PArg' t = PImp { priority :: Int,
429 lazyarg :: Bool, pname :: Name, getTm :: t }
430 | PExp { priority :: Int,
431 lazyarg :: Bool, getTm :: t }
432 | PConstraint { priority :: Int,
433 lazyarg :: Bool, getTm :: t }
434 | PTacImplicit { priority :: Int,
435 lazyarg :: Bool, pname :: Name,
438 deriving (Show, Eq, Functor)
440instance Sized a => Sized (PArg' a) where
441 size (PImp p l nm trm) = 1 + size nm + size trm
442 size (PExp p l trm) = 1 + size trm
443 size (PConstraint p l trm) = 1 + size trm
444 size (PTacImplicit p l nm scr trm) = 1 + size nm + size scr + size trm
447deriving instance Binary PArg'
452pconst = PConstraint 0 False
453ptacimp = PTacImplicit 0 True
455type PArg = PArg' PTerm
459data ClassInfo = CI { instanceName :: Name,
460 class_methods :: [(Name, (FnOpts, PTerm))],
461 class_defaults :: [(Name, (Name, PDecl))], -- method name -> default impl
462 class_params :: [Name],
463 class_instances :: [Name] }
466deriving instance Binary ClassInfo
469data OptInfo = Optimise { collapsible :: Bool,
470 forceable :: [Int], -- argument positions
474deriving instance Binary OptInfo
478data TypeInfo = TI { con_names :: [Name] }
481deriving instance Binary TypeInfo
484-- Syntactic sugar info
486data DSL' t = DSL { dsl_bind :: t,
491 index_first :: Maybe t,
492 index_next :: Maybe t,
493 dsl_lambda :: Maybe t,
496 deriving (Show, Functor)
498deriving instance Binary DSL'
503data SynContext = PatternSyntax | TermSyntax | AnySyntax
506deriving instance Binary SynContext
509data Syntax = Rule [SSymbol] PTerm SynContext
512deriving instance Binary Syntax
515data SSymbol = Keyword Name
522deriving instance Binary SSymbol
525initDSL = DSL (PRef f (UN ">>="))
526 (PRef f (UN "return"))
534 where f = FC "(builtin)" 0
536data SyntaxInfo = Syn { using :: [(Name, PTerm)],
537 syn_params :: [(Name, PTerm)],
538 syn_namespace :: [String],
540 decoration :: Name -> Name,
542 implicitAllowed :: Bool,
546deriving instance Binary SyntaxInfo
549defaultSyntax = Syn [] [] [] [] id False False initDSL
551expandNS :: SyntaxInfo -> Name -> Name
552expandNS syn n@(NS _ _) = n
553expandNS syn n = case syn_namespace syn of
558--- Pretty printing declarations and terms
560instance Show PTerm where
561 show tm = showImp False tm
563instance Pretty PTerm where
564 pretty = prettyImp False
566instance Show PDecl where
567 show d = showDeclImp False d
569instance Show PClause where
570 show c = showCImp True c
572instance Show PData where
573 show d = showDImp False d
575showDeclImp _ (PFix _ f ops) = show f ++ " " ++ showSep ", " ops
576showDeclImp t (PTy _ _ _ n ty) = show n ++ " : " ++ showImp t ty
577showDeclImp _ (PClauses _ _ n c) = showSep "\n" (map show c)
578showDeclImp _ (PData _ _ d) = show d
580showCImp :: Bool -> PClause -> String
581showCImp impl (PClause _ n l ws r w)
582 = showImp impl l ++ showWs ws ++ " = " ++ showImp impl r
583 ++ " where " ++ show w
586 showWs (x : xs) = " | " ++ showImp impl x ++ showWs xs
587showCImp impl (PWith _ n l ws r w)
588 = showImp impl l ++ showWs ws ++ " with " ++ showImp impl r
589 ++ " { " ++ show w ++ " } "
592 showWs (x : xs) = " | " ++ showImp impl x ++ showWs xs
595showDImp :: Bool -> PData -> String
596showDImp impl (PDatadecl n ty cons)
597 = "data " ++ show n ++ " : " ++ showImp impl ty ++ " where\n\t"
599 (map (\ (n, t, _) -> show n ++ " : " ++ showImp impl t) cons)
601getImps :: [PArg] -> [(Name, PTerm)]
603getImps (PImp _ _ n tm : xs) = (n, tm) : getImps xs
604getImps (_ : xs) = getImps xs
606getExps :: [PArg] -> [PTerm]
608getExps (PExp _ _ tm : xs) = tm : getExps xs
609getExps (_ : xs) = getExps xs
611getConsts :: [PArg] -> [PTerm]
613getConsts (PConstraint _ _ tm : xs) = tm : getConsts xs
614getConsts (_ : xs) = getConsts xs
616getAll :: [PArg] -> [PTerm]
619prettyImp :: Bool -> PTerm -> Doc
620prettyImp impl = prettySe 10
622 prettySe p (PQuote r) =
623 if size r > breakingSize then
624 text "![" $$ pretty r <> text "]"
626 text "![" <> pretty r <> text "]"
627 prettySe p (PRef fc n) =
633 prettyBasic n@(UN _) = pretty n
634 prettyBasic (MN _ s) = text s
635 prettyBasic (NS n s) = (foldr (<>) empty (intersperse (text ".") (map text $ reverse s))) <> prettyBasic n
636 prettySe p (PLam n ty sc) =
638 if size sc > breakingSize then
639 text "λ" <> pretty n <+> text "=>" $+$ pretty sc
641 text "λ" <> pretty n <+> text "=>" <+> pretty sc
642 prettySe p (PLet n ty v sc) =
644 if size sc > breakingSize then
645 text "let" <+> pretty n <+> text "=" <+> prettySe 10 v <+> text "in" $+$
646 nest nestingSize (prettySe 10 sc)
648 text "let" <+> pretty n <+> text "=" <+> prettySe 10 v <+> text "in" <+>
650 prettySe p (PPi (Exp l s) n ty sc)
651 | n `elem` allNamesIn sc || impl =
652 let open = if l then text "|" <> lparen else lparen in
654 if size sc > breakingSize then
655 open <> pretty n <+> colon <+> prettySe 10 ty <> rparen <+>
656 st <+> text "->" $+$ prettySe 10 sc
658 open <> pretty n <+> colon <+> prettySe 10 ty <> rparen <+>
659 st <+> text "->" <+> prettySe 10 sc
662 if size sc > breakingSize then
663 prettySe 0 ty <+> st <+> text "->" $+$ prettySe 10 sc
665 prettySe 0 ty <+> st <+> text "->" <+> prettySe 10 sc
669 Static -> text "[static]"
671 prettySe p (PPi (Imp l s) n ty sc)
673 let open = if l then text "|" <> lbrace else lbrace in
675 if size sc > breakingSize then
676 open <> pretty n <+> colon <+> prettySe 10 ty <> rbrace <+>
677 st <+> text "->" <+> prettySe 10 sc
679 open <> pretty n <+> colon <+> prettySe 10 ty <> rbrace <+>
680 st <+> text "->" <+> prettySe 10 sc
681 | otherwise = prettySe 10 sc
685 Static -> text $ "[static]"
687 prettySe p (PPi (Constraint _ _) n ty sc) =
689 if size sc > breakingSize then
690 prettySe 10 ty <+> text "=>" <+> prettySe 10 sc
692 prettySe 10 ty <+> text "=>" $+$ prettySe 10 sc
693 prettySe p (PPi (TacImp _ _ s) n ty sc) =
695 if size sc > breakingSize then
696 lbrace <> text "tacimp" <+> pretty n <+> colon <+> prettySe 10 ty <>
697 rbrace <+> text "->" $+$ prettySe 10 sc
699 lbrace <> text "tacimp" <+> pretty n <+> colon <+> prettySe 10 ty <>
700 rbrace <+> text "->" <+> prettySe 10 sc
701 prettySe p (PApp _ (PRef _ f) [])
702 | not impl = pretty f
703 prettySe p (PApp _ (PRef _ op@(UN (f:_))) args)
704 | length (getExps args) == 2 && (not impl) && (not $ isAlpha f) =
705 let [l, r] = getExps args in
707 if size r > breakingSize then
708 prettySe 1 l <+> pretty op $+$ prettySe 0 r
710 prettySe 1 l <+> pretty op <+> prettySe 0 r
711 prettySe p (PApp _ f as) =
712 let args = getExps as in
717 -- foldr (<+>) empty $ map prettyArgS as
720 -- foldr (<+>) empty $ map prettyArgSe args
723 if size r > breakingSize then
724 l $+$ nest nestingSize (prettyArgS r)
729 if size r > breakingSize then
730 l $+$ nest nestingSize (prettyArgSe r)
733 prettySe p (PCase _ scr opts) =
734 text "case" <+> prettySe 10 scr <+> text "of" $+$ nest nestingSize prettyBody
736 prettyBody = foldr ($$) empty $ intersperse (text "|") $ map sc opts
738 sc (l, r) = prettySe 10 l <+> text "=>" <+> prettySe 10 r
739 prettySe p (PHidden tm) = text "." <> prettySe 0 tm
740 prettySe p (PRefl _) = text "refl"
741 prettySe p (PResolveTC _) = text "resolvetc"
742 prettySe p (PTrue _) = text "()"
743 prettySe p (PFalse _) = text "_|_"
744 prettySe p (PEq _ l r) =
746 if size r > breakingSize then
747 prettySe 10 l <+> text "=" $$ nest nestingSize (prettySe 10 r)
749 prettySe 10 l <+> text "=" <+> prettySe 10 r
750 prettySe p (PTyped l r) =
751 lparen <> prettySe 10 l <+> colon <+> prettySe 10 r <> rparen
752 prettySe p (PPair _ l r) =
753 if size r > breakingSize then
754 lparen <> prettySe 10 l <> text "," $+$
755 prettySe 10 r <> rparen
757 lparen <> prettySe 10 l <> text "," <+> prettySe 10 r <> rparen
758 prettySe p (PDPair _ l t r) =
759 if size r > breakingSize then
760 lparen <> prettySe 10 l <+> text "**" $+$
761 prettySe 10 r <> rparen
763 lparen <> prettySe 10 l <+> text "**" <+> prettySe 10 r <> rparen
764 prettySe p (PAlternative a as) =
765 lparen <> text "|" <> prettyAs <> text "|" <> rparen
768 foldr (\l -> \r -> l <+> text "," <+> r) empty $ map (prettySe 10) as
769 prettySe p PSet = text "Set"
770 prettySe p (PConstant c) = pretty c
771 -- XXX: add pretty for tactics
772 prettySe p (PProof ts) =
773 text "proof" <+> lbrace $+$ nest nestingSize (text . show $ ts) $+$ rbrace
774 prettySe p (PTactics ts) =
775 text "tactics" <+> lbrace $+$ nest nestingSize (text . show $ ts) $+$ rbrace
776 prettySe p (PMetavar n) = text "?" <> pretty n
777 prettySe p (PReturn f) = text "return"
778 prettySe p PImpossible = text "impossible"
779 prettySe p Placeholder = text "_"
780 prettySe p (PDoBlock _) = text "do block pretty not implemented"
781 prettySe p (PElabError s) = pretty s
783 prettySe p _ = text "test"
785 prettyArgS (PImp _ _ n tm) = prettyArgSi (n, tm)
786 prettyArgS (PExp _ _ tm) = prettyArgSe tm
787 prettyArgS (PConstraint _ _ tm) = prettyArgSc tm
788 prettyArgS (PTacImplicit _ _ n _ tm) = prettyArgSti (n, tm)
790 prettyArgSe arg = prettySe 0 arg
791 prettyArgSi (n, val) = lbrace <> pretty n <+> text "=" <+> prettySe 10 val <> rbrace
792 prettyArgSc val = lbrace <> lbrace <> prettySe 10 val <> rbrace <> rbrace
793 prettyArgSti (n, val) = lbrace <> text "auto" <+> pretty n <+> text "=" <+> prettySe 10 val <> rbrace
795 bracket outer inner doc
796 | inner > outer = lparen <> doc <> rparen
799showImp :: Bool -> PTerm -> String
800showImp impl tm = se 10 tm where
801 se p (PQuote r) = "![" ++ show r ++ "]"
802 se p (PRef fc n) = if impl then show n -- ++ "[" ++ show fc ++ "]"
804 where showbasic n@(UN _) = show n
805 showbasic (MN _ s) = s
806 showbasic (NS n s) = showSep "." (reverse s) ++ "." ++ showbasic n
807 se p (PLam n ty sc) = bracket p 2 $ "\\ " ++ show n ++
808 (if impl then " : " ++ se 10 ty else "") ++ " => "
810 se p (PLet n ty v sc) = bracket p 2 $ "let " ++ show n ++ " = " ++ se 10 v ++
812 se p (PPi (Exp l s) n ty sc)
813 | n `elem` allNamesIn sc || impl
815 if l then "|(" else "(" ++
816 show n ++ " : " ++ se 10 ty ++
819 | otherwise = bracket p 2 $ se 0 ty ++ " " ++ st ++ "-> " ++ se 10 sc
821 Static -> "[static] "
823 se p (PPi (Imp l s) n ty sc)
824 | impl = bracket p 2 $ if l then "|{" else "{" ++
825 show n ++ " : " ++ se 10 ty ++
826 "} " ++ st ++ "-> " ++ se 10 sc
827 | otherwise = se 10 sc
829 Static -> "[static] "
831 se p (PPi (Constraint _ _) n ty sc)
832 = bracket p 2 $ se 10 ty ++ " => " ++ se 10 sc
833 se p (PPi (TacImp _ _ s) n ty sc)
834 = bracket p 2 $ "{tacimp " ++ show n ++ " : " ++ se 10 ty ++ "} -> " ++ se 10 sc
835 se p (PApp _ (PRef _ f) [])
837 se p (PApp _ (PRef _ op@(UN (f:_))) args)
838 | length (getExps args) == 2 && not impl && not (isAlpha f)
839 = let [l, r] = getExps args in
840 bracket p 1 $ se 1 l ++ " " ++ show op ++ " " ++ se 0 r
842 = let args = getExps as in
843 bracket p 1 $ se 1 f ++ if impl then concatMap sArg as
844 else concatMap seArg args
845 se p (PCase _ scr opts) = "case " ++ se 10 scr ++ " of " ++ showSep " | " (map sc opts)
846 where sc (l, r) = se 10 l ++ " => " ++ se 10 r
847 se p (PHidden tm) = "." ++ se 0 tm
848 se p (PRefl _) = "refl"
849 se p (PResolveTC _) = "resolvetc"
850 se p (PTrue _) = "()"
851 se p (PFalse _) = "_|_"
852 se p (PEq _ l r) = bracket p 2 $ se 10 l ++ " = " ++ se 10 r
853 se p (PTyped l r) = "(" ++ se 10 l ++ " : " ++ se 10 r ++ ")"
854 se p (PPair _ l r) = "(" ++ se 10 l ++ ", " ++ se 10 r ++ ")"
855 se p (PDPair _ l t r) = "(" ++ se 10 l ++ " ** " ++ se 10 r ++ ")"
856 se p (PAlternative a as) = "(|" ++ showSep " , " (map (se 10) as) ++ "|)"
858 se p (PConstant c) = show c
859 se p (PProof ts) = "proof { " ++ show ts ++ "}"
860 se p (PTactics ts) = "tactics { " ++ show ts ++ "}"
861 se p (PMetavar n) = "?" ++ show n
862 se p (PReturn f) = "return"
863 se p PImpossible = "impossible"
864 se p Placeholder = "_"
865 se p (PDoBlock _) = "do block show not implemented"
866 se p (PElabError s) = show s
867-- se p x = "Not implemented"
869 sArg (PImp _ _ n tm) = siArg (n, tm)
870 sArg (PExp _ _ tm) = seArg tm
871 sArg (PConstraint _ _ tm) = scArg tm
872 sArg (PTacImplicit _ _ n _ tm) = stiArg (n, tm)
874 seArg arg = " " ++ se 0 arg
875 siArg (n, val) = " {" ++ show n ++ " = " ++ se 10 val ++ "}"
876 scArg val = " {{" ++ se 10 val ++ "}}"
877 stiArg (n, val) = " {auto " ++ show n ++ " = " ++ se 10 val ++ "}"
879 bracket outer inner str | inner > outer = "(" ++ str ++ ")"
885 | PLam Name PTerm PTerm
886 | PPi Plicity Name PTerm PTerm
887 | PLet Name PTerm PTerm PTerm
888 | PTyped PTerm PTerm -- term with explicit type
889 | PApp FC PTerm [PArg]
890 | PCase FC PTerm [(PTerm, PTerm)]
896 | PPair FC PTerm PTerm
897 | PDPair FC PTerm PTerm PTerm
898 | PAlternative [PTerm]
899 | PHidden PTerm -- irrelevant or hidden pattern
908 | PTactics [PTactic] -- as PProof, but no auto solving
909 | PElabError Err -- error to report on elaboration
910 | PImpossible -- special case for declaring when an LHS can't typecheck
913instance Sized PTerm where
914 size (PQuote rawTerm) = size rawTerm
915 size (PRef fc name) = size name
916 size (PLam name ty bdy) = 1 + size ty + size bdy
917 size (PPi plicity name ty bdy) = 1 + size ty + size bdy
918 size (PLet name ty def bdy) = 1 + size ty + size def + size bdy
919 size (PTyped trm ty) = 1 + size trm + size ty
920 size (PApp fc name args) = 1 + size args
921 size (PCase fc trm bdy) = 1 + size trm + size bdy
925 size (PResolveTC fc) = 1
926 size (PEq fc left right) = 1 + size left + size right
927 size (PPair fc left right) = 1 + size left + size right
928 size (PDPair fs left ty right) = 1 + size left + size ty + size right
929 size (PAlternative a alts) = 1 + size alts
930 size (PHidden hidden) = size hidden
932 size (PConstant const) = 1 + size const
934 size (PDoBlock dos) = 1 + size dos
935 size (PIdiom fc term) = 1 + size term
936 size (PReturn fc) = 1
937 size (PMetavar name) = 1
938 size (PProof tactics) = size tactics
939 size (PElabError err) = size err
942allNamesIn :: PTerm -> [Name]
943allNamesIn tm = nub $ ni [] tm
946 | not (n `elem` env) = [n]
947 ni env (PApp _ f as) = ni env f ++ concatMap (ni env) (map getTm as)
948 ni env (PCase _ c os) = ni env c ++ concatMap (ni env) (map snd os)
949 ni env (PLam n ty sc) = ni env ty ++ ni (n:env) sc
950 ni env (PPi _ n ty sc) = ni env ty ++ ni (n:env) sc
951 ni env (PHidden tm) = ni env tm
952 ni env (PEq _ l r) = ni env l ++ ni env r
953 ni env (PTyped l r) = ni env l ++ ni env r
954 ni env (PPair _ l r) = ni env l ++ ni env r
955 ni env (PDPair _ (PRef _ n) t r) = ni env t ++ ni (n:env) r
956 ni env (PDPair _ l t r) = ni env l ++ ni env t ++ ni env r
957 ni env (PAlternative a ls) = concatMap (ni env) ls
960namesIn :: [(Name, PTerm)] -> IState -> PTerm -> [Name]
961namesIn uvars ist tm = nub $ ni [] tm
965 = case lookupTy Nothing n (tt_ctxt ist) of
967 _ -> if n `elem` (map fst uvars) then [n] else []
968 ni env (PApp _ f as) = ni env f ++ concatMap (ni env) (map getTm as)
969 ni env (PCase _ c os) = ni env c ++ concatMap (ni env) (map snd os)
970 ni env (PLam n ty sc) = ni env ty ++ ni (n:env) sc
971 ni env (PPi _ n ty sc) = ni env ty ++ ni (n:env) sc
972 ni env (PEq _ l r) = ni env l ++ ni env r
973 ni env (PTyped l r) = ni env l ++ ni env r
974 ni env (PPair _ l r) = ni env l ++ ni env r
975 ni env (PDPair _ (PRef _ n) t r) = ni env t ++ ni (n:env) r
976 ni env (PDPair _ l t r) = ni env l ++ ni env t ++ ni env r
977 ni env (PAlternative a as) = concatMap (ni env) as
978 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